aboutsummaryrefslogtreecommitdiffstats
path: root/src/stream.c
diff options
context:
space:
mode:
authorMax <msuraev@sysmocom.de>2019-02-05 12:25:25 +0100
committerMax <msuraev@sysmocom.de>2019-02-05 16:26:49 +0000
commit827d693b5031c4495793a9d85d5a89fd8b97b7ba (patch)
treeb82c912f4c260dbca8678c13d5b51e61fce2e703 /src/stream.c
parent732652b5b7f4fe02ecfff5f33b67db6392b02617 (diff)
Stream client: fix disconnection logic
Previously closing the client did not alter its state, so we might end-up with a client without any file descriptors, but being in state STREAM_CLI_STATE_CONNECTED. Fix this inconsistency by setting appropriate state. Related issue is that reconnect function, which is always (at least in the library and examples) called when some problem with the connection is detected, closed the connection only after checking whether reconnection is enabled. This might result in another inconsistency fixed in this patch by moving the check below connection cleanup. While at it, also move connection close logging to appropriate place: it's confusing to see logs about connection being closed while in reality it wasn't even established. Change-Id: If41ed60bd625488c283d1e8a2b078e640f04c78e
Diffstat (limited to 'src/stream.c')
-rw-r--r--src/stream.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/stream.c b/src/stream.c
index 7cc77c9..7b97d2a 100644
--- a/src/stream.c
+++ b/src/stream.c
@@ -169,12 +169,13 @@ void osmo_stream_cli_close(struct osmo_stream_cli *cli);
* connection (if any) and schedule a re-connect timer */
void osmo_stream_cli_reconnect(struct osmo_stream_cli *cli)
{
+ osmo_stream_cli_close(cli);
+
if (cli->reconnect_timeout < 0) {
LOGSCLI(cli, LOGL_DEBUG, "not reconnecting, disabled.\n");
return;
}
- LOGSCLI(cli, LOGL_DEBUG, "connection closed\n");
- osmo_stream_cli_close(cli);
+
LOGSCLI(cli, LOGL_DEBUG, "retrying in %d seconds...\n",
cli->reconnect_timeout);
osmo_timer_schedule(&cli->timer, cli->reconnect_timeout, 0);
@@ -192,6 +193,11 @@ void osmo_stream_cli_close(struct osmo_stream_cli *cli)
osmo_fd_unregister(&cli->ofd);
close(cli->ofd.fd);
cli->ofd.fd = -1;
+
+ if (cli->state == STREAM_CLI_STATE_CONNECTED)
+ LOGSCLI(cli, LOGL_DEBUG, "connection closed\n");
+
+ cli->state = STREAM_CLI_STATE_NONE;
}
static void osmo_stream_cli_read(struct osmo_stream_cli *cli)