Change in libosmo-netif[master]: Stream client: fix disconnection logic

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Max gerrit-no-reply at lists.osmocom.org
Thu Jan 31 12:56:57 UTC 2019


Max has uploaded this change for review. ( https://gerrit.osmocom.org/12760


Change subject: Stream client: fix disconnection logic
......................................................................

Stream client: fix disconnection logic

Previously closing the client did not alter it's state so might end-up
with a client without any file descriptors but in
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.

Change-Id: If41ed60bd625488c283d1e8a2b078e640f04c78e
---
M src/stream.c
1 file changed, 5 insertions(+), 2 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmo-netif refs/changes/60/12760/1

diff --git a/src/stream.c b/src/stream.c
index 902e688..af457dd 100644
--- a/src/stream.c
+++ b/src/stream.c
@@ -159,12 +159,14 @@
  *  connection (if any) and schedule a re-connect timer */
 void osmo_stream_cli_reconnect(struct osmo_stream_cli *cli)
 {
+	LOGP(DLINP, LOGL_DEBUG, "connection closed\n");
+	osmo_stream_cli_close(cli);
+
 	if (cli->reconnect_timeout < 0) {
 		LOGP(DLINP, LOGL_DEBUG, "not reconnecting, disabled.\n");
 		return;
 	}
-	LOGP(DLINP, LOGL_DEBUG, "connection closed\n");
-	osmo_stream_cli_close(cli);
+
 	LOGP(DLINP, LOGL_DEBUG, "retrying in %d seconds...\n",
 		cli->reconnect_timeout);
 	osmo_timer_schedule(&cli->timer, cli->reconnect_timeout, 0);
@@ -182,6 +184,7 @@
 	osmo_fd_unregister(&cli->ofd);
 	close(cli->ofd.fd);
 	cli->ofd.fd = -1;
+	cli->state = STREAM_CLI_STATE_NONE;
 }
 
 static void osmo_stream_cli_read(struct osmo_stream_cli *cli)

-- 
To view, visit https://gerrit.osmocom.org/12760
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: libosmo-netif
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: If41ed60bd625488c283d1e8a2b078e640f04c78e
Gerrit-Change-Number: 12760
Gerrit-PatchSet: 1
Gerrit-Owner: Max <msuraev at sysmocom.de>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20190131/012e87da/attachment.htm>


More information about the gerrit-log mailing list