From cc4ce39fc6e3b844605eb3fbc1c413b3282ed292 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Tue, 22 Dec 2015 23:54:21 +0100 Subject: fix/complete stream client re-connect logic So far, when the first connection attempt failed in osmo_stream_cli_open(), we returned a terminal errro without any re-connection attempts. While this may be useful in some cases, our general idea of the stream client logic is to handle the reconnection attempts insid the library. We introduce a new osmo_stream_cli_open2() function while keping the old behavior for backwards compatibility. --- src/stream.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/stream.c b/src/stream.c index 6bd1a37..d56224b 100644 --- a/src/stream.c +++ b/src/stream.c @@ -275,7 +275,7 @@ void osmo_stream_cli_destroy(struct osmo_stream_cli *cli) talloc_free(cli); } -int osmo_stream_cli_open(struct osmo_stream_cli *cli) +int osmo_stream_cli_open2(struct osmo_stream_cli *cli, int reconnect) { int ret; @@ -289,8 +289,14 @@ int osmo_stream_cli_open(struct osmo_stream_cli *cli) cli->addr, cli->port, OSMO_SOCK_F_CONNECT); if (ret < 0) { - if (errno != EINPROGRESS) - return ret; + if (errno != EINPROGRESS) { + if (reconnect) { + osmo_timer_schedule(&cli->timer, cli->reconnect_timeout, 0); + cli->state = STREAM_CLI_STATE_CONNECTING; + return 0; + } else + return ret; + } } cli->ofd.fd = ret; if (osmo_fd_register(&cli->ofd) < 0) { @@ -300,6 +306,12 @@ int osmo_stream_cli_open(struct osmo_stream_cli *cli) return 0; } + +int osmo_stream_cli_open(struct osmo_stream_cli *cli) +{ + return osmo_stream_cli_open2(cli, 0); +} + static void cli_timer_cb(void *data) { struct osmo_stream_cli *cli = data; @@ -308,7 +320,7 @@ static void cli_timer_cb(void *data) switch(cli->state) { case STREAM_CLI_STATE_CONNECTING: - osmo_stream_cli_open(cli); + osmo_stream_cli_open2(cli, 1); break; default: break; -- cgit v1.2.3