aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMax <msuraev@sysmocom.de>2019-02-06 17:27:18 +0100
committerHarald Welte <laforge@gnumonks.org>2019-03-19 13:40:55 +0000
commitb3e34435b3bde227805c8dcac39c28e57144e500 (patch)
tree66553c23c3392dd1cb6733ad9693048d8d97136f /src
parent1ab218d28f684a431cd9de972499b987b63a507a (diff)
Deprecate osmo_stream_cli_open2()
This supposed to be variant of osmo_stream_cli_open() with explicit control over reconnection logic but it's plain broken: doxygen docs contradict the code, actual reconnection logic is affected by timeout parameter directly which is set in different function. It seems like we haven't been affected by this so far because we always use it in auto-reconnection mode which is triggered by default due to positive reconnection timeout value (5 sec) automatically used in the absense of explicitly set timeout. Looking at commit history, this function already been source of confusion in the past. Instead of trying to fix this mess, let's just deprecate it entirely and properly document use of osmo_stream_cli_set_reconnect_timeout() to control reconnection logic. The only known user is libosmo-sccp which won't use it as of 0a93a683f3cb8e5977eb4a666ab207db6e7d7af9 commit. Change-Id: Id988ed0274b363db049f59cbf6a193727c8c3c8a
Diffstat (limited to 'src')
-rw-r--r--src/stream.c48
1 files changed, 42 insertions, 6 deletions
diff --git a/src/stream.c b/src/stream.c
index c4db3d7..3d0b665 100644
--- a/src/stream.c
+++ b/src/stream.c
@@ -166,8 +166,9 @@ struct osmo_stream_cli {
void osmo_stream_cli_close(struct osmo_stream_cli *cli);
/*! \brief Re-connect an Osmocom Stream Client
- * If re-connection is enabled for this client, we close any existing
- * connection (if any) and schedule a re-connect timer */
+ * If re-connection is enabled for this client
+ * (which is the case unless negative timeout was explicitly set via osmo_stream_cli_set_reconnect_timeout() call),
+ * we close any existing connection (if any) and schedule a re-connect timer */
void osmo_stream_cli_reconnect(struct osmo_stream_cli *cli)
{
osmo_stream_cli_close(cli);
@@ -391,7 +392,7 @@ osmo_stream_cli_set_proto(struct osmo_stream_cli *cli, uint16_t proto)
/*! \brief Set the reconnect time of the stream client socket
* \param[in] cli Stream Client to modify
- * \param[in] timeout Re-connect timeout in seconds */
+ * \param[in] timeout Re-connect timeout in seconds or negative value to disable auto-reconnection */
void
osmo_stream_cli_set_reconnect_timeout(struct osmo_stream_cli *cli, int timeout)
{
@@ -475,7 +476,8 @@ void osmo_stream_cli_destroy(struct osmo_stream_cli *cli)
talloc_free(cli);
}
-/*! \brief Open connection of an Osmocom stream client
+/*! \brief DEPRECATED: use osmo_stream_cli_set_reconnect_timeout() or osmo_stream_cli_reconnect() instead!
+ * Open connection of an Osmocom stream client
* \param[in] cli Stream Client to connect
* \param[in] reconect 1 if we should not automatically reconnect
*/
@@ -534,10 +536,44 @@ void osmo_stream_cli_set_nodelay(struct osmo_stream_cli *cli, bool nodelay)
}
/*! \brief Open connection of an Osmocom stream client
+ * By default the client will automatically reconnect after default timeout.
+ * To disable this, use osmo_stream_cli_set_reconnect_timeout() before calling this function.
* \param[in] cli Stream Client to connect */
int osmo_stream_cli_open(struct osmo_stream_cli *cli)
{
- return osmo_stream_cli_open2(cli, 0);
+ int ret;
+
+ /* we are reconfiguring this socket, close existing first. */
+ if ((cli->flags & OSMO_STREAM_CLI_F_RECONF) && cli->ofd.fd >= 0)
+ osmo_stream_cli_close(cli);
+
+ cli->flags &= ~OSMO_STREAM_CLI_F_RECONF;
+
+ ret = osmo_sock_init2(AF_INET, SOCK_STREAM, cli->proto,
+ cli->local_addr, cli->local_port,
+ cli->addr, cli->port,
+ OSMO_SOCK_F_CONNECT|OSMO_SOCK_F_BIND|OSMO_SOCK_F_NONBLOCK);
+ if (ret < 0) {
+ osmo_stream_cli_reconnect(cli);
+ return ret;
+ }
+ cli->ofd.fd = ret;
+
+ if (cli->flags & OSMO_STREAM_CLI_F_NODELAY) {
+ ret = setsockopt_nodelay(cli->ofd.fd, cli->proto, 1);
+ if (ret < 0)
+ goto error_close_socket;
+ }
+
+ if (osmo_fd_register(&cli->ofd) < 0)
+ goto error_close_socket;
+
+ return 0;
+
+error_close_socket:
+ close(ret);
+ cli->ofd.fd = -1;
+ return -EIO;
}
static void cli_timer_cb(void *data)
@@ -549,7 +585,7 @@ static void cli_timer_cb(void *data)
switch(cli->state) {
case STREAM_CLI_STATE_CONNECTING:
cli->ofd.when |= BSC_FD_READ | BSC_FD_WRITE;
- osmo_stream_cli_open2(cli, 1);
+ osmo_stream_cli_open(cli);
break;
default:
break;