[S] Change in libosmo-netif[master]: stream_cli: Allow setting nodelay sockopt after opening sock
pespin has submitted this change. ( https://gerrit.osmocom.org/c/libosmo-netif/+/38826?usp=email ) Change subject: stream_cli: Allow setting nodelay sockopt after opening sock ...................................................................... stream_cli: Allow setting nodelay sockopt after opening sock This allows users who wish to first open the socket and set the nodelay option at a later point. This has also a use case according to man 7 tcp: """ setting this option forces an explicit flush of pending output, even if TCP_CORK is currently set. """ Change-Id: Ic178d924da03968de1f140bfc8805c972b849e7b --- M src/stream_cli.c 1 file changed, 24 insertions(+), 1 deletion(-) Approvals: laforge: Looks good to me, but someone else must approve fixeria: Looks good to me, approved Jenkins Builder: Verified diff --git a/src/stream_cli.c b/src/stream_cli.c index d4067d6..5d8a2c2 100644 --- a/src/stream_cli.c +++ b/src/stream_cli.c @@ -148,6 +148,17 @@ return cli->state == STREAM_CLI_STATE_CONNECTED; } +/*! Check if Osmocom Stream Client is opened (has an FD available) according to + * its current state. + * \param[in] cli Osmocom Stream Client + * \return true if fd is available (osmo_stream_cli_get_fd()), false otherwise + */ +static bool stream_cli_is_opened(const struct osmo_stream_cli *cli) +{ + return cli->state == STREAM_CLI_STATE_CONNECTING || + cli->state == STREAM_CLI_STATE_CONNECTED; +} + static void osmo_stream_cli_close_iofd(struct osmo_stream_cli *cli) { if (!cli->iofd) @@ -911,17 +922,29 @@ /*! Set the NODELAY socket option to avoid Nagle-like behavior. * Setting this to nodelay=true will automatically set the NODELAY * socket option on any socket established via \ref osmo_stream_cli_open - * or any re-connect. You have to set this _before_ opening the + * or any re-connect. This can be set either before or after opening the * socket. * \param[in] cli Stream client whose sockets are to be configured * \param[in] nodelay whether to set (true) NODELAY before connect() */ void osmo_stream_cli_set_nodelay(struct osmo_stream_cli *cli, bool nodelay) { + int fd; if (nodelay) cli->flags |= OSMO_STREAM_CLI_F_NODELAY; else cli->flags &= ~OSMO_STREAM_CLI_F_NODELAY; + + if (!stream_cli_is_opened(cli)) + return; /* Config will be applied upon open() time */ + + if ((fd = osmo_stream_cli_get_fd(cli)) < 0) { + LOGSCLI(cli, LOGL_ERROR, "set_nodelay(%u): failed obtaining socket\n", nodelay); + return; + } + if (stream_setsockopt_nodelay(fd, cli->proto, nodelay ? 1 : 0) < 0) + LOGSCLI(cli, LOGL_ERROR, "set_nodelay(%u): failed setsockopt err=%d\n", + nodelay, errno); } /*! Open connection of an Osmocom stream client. -- To view, visit https://gerrit.osmocom.org/c/libosmo-netif/+/38826?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email Gerrit-MessageType: merged Gerrit-Project: libosmo-netif Gerrit-Branch: master Gerrit-Change-Id: Ic178d924da03968de1f140bfc8805c972b849e7b Gerrit-Change-Number: 38826 Gerrit-PatchSet: 2 Gerrit-Owner: pespin <pespin@sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: fixeria <vyanitskiy@sysmocom.de> Gerrit-Reviewer: laforge <laforge@osmocom.org> Gerrit-Reviewer: pespin <pespin@sysmocom.de>
participants (1)
-
pespin