diff options
author | Harald Welte <laforge@gnumonks.org> | 2015-12-22 23:54:21 +0100 |
---|---|---|
committer | Harald Welte <laforge@gnumonks.org> | 2015-12-22 23:54:21 +0100 |
commit | cc4ce39fc6e3b844605eb3fbc1c413b3282ed292 (patch) | |
tree | 95ffe7f7c674175f5cfaf146bb794a42feb00fc4 /src/stream.c | |
parent | b60edf05a6cde75dee8a7974c761f4f3929c47e3 (diff) |
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.
Diffstat (limited to 'src/stream.c')
-rw-r--r-- | src/stream.c | 20 |
1 files changed, 16 insertions, 4 deletions
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; |