Change in libosmo-netif[master]: Deprecate osmo_stream_cli_open2()

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
Wed Feb 6 16:35:01 UTC 2019


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


Change subject: Deprecate osmo_stream_cli_open2()
......................................................................

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 due to positive
reconnection timeout value (5 sec) 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.

Change-Id: Id988ed0274b363db049f59cbf6a193727c8c3c8a
---
M include/osmocom/netif/stream.h
M tests/stream/stream_test.c
2 files changed, 77 insertions(+), 1 deletion(-)



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

diff --git a/include/osmocom/netif/stream.h b/include/osmocom/netif/stream.h
index 3044511..f64daf9 100644
--- a/include/osmocom/netif/stream.h
+++ b/include/osmocom/netif/stream.h
@@ -71,7 +71,7 @@
 void osmo_stream_cli_destroy(struct osmo_stream_cli *cli);
 
 int osmo_stream_cli_open(struct osmo_stream_cli *cli);
-int osmo_stream_cli_open2(struct osmo_stream_cli *cli, int reconnect);
+int osmo_stream_cli_open2(struct osmo_stream_cli *cli, int reconnect) OSMO_DEPRECATED("Use osmo_stream_cli_set_reconnect_timeout() or osmo_stream_cli_reconnect() instead");
 void osmo_stream_cli_close(struct osmo_stream_cli *cli);
 
 void osmo_stream_cli_send(struct osmo_stream_cli *cli, struct msgb *msg);
diff --git a/tests/stream/stream_test.c b/tests/stream/stream_test.c
index 7a24e21..35d18b5 100644
--- a/tests/stream/stream_test.c
+++ b/tests/stream/stream_test.c
@@ -127,6 +127,76 @@
 	return cli;
 }
 
+/* Without explicit timeout set with osmo_stream_cli_set_reconnect_timeout() default value is used.
+static struct osmo_stream_cli *init_client_reconnection_broken1(struct osmo_stream_cli *cli, bool autoreconnect)
+{
+	if (osmo_stream_cli_open2(cli, autoreconnect) < 0) {
+		LOGCLI(cli, "unable to open client\n");
+		return NULL;
+	}
+
+	return cli;
+}
+That's why those those functions result in exact the same output despite inverse use of autoreconnect parameter.
+static struct osmo_stream_cli *init_client_reconnection_broken2(struct osmo_stream_cli *cli, bool autoreconnect)
+{
+	if (osmo_stream_cli_open2(cli, !autoreconnect) < 0) {
+		LOGCLI(cli, "unable to open client\n");
+		return NULL;
+	}
+
+	return cli;
+}
+
+Variant below are also equivalent to each other.
+static struct osmo_stream_cli *init_client_reconnection_broken1(struct osmo_stream_cli *cli, bool autoreconnect)
+{
+	osmo_stream_cli_set_reconnect_timeout(cli, (!autoreconnect) ? 2 : -1);
+	if (osmo_stream_cli_open2(cli, autoreconnect) < 0) {
+		LOGCLI(cli, "unable to open client\n");
+		return NULL;
+	}
+
+	return cli;
+}
+
+static struct osmo_stream_cli *init_client_reconnection_broken2(struct osmo_stream_cli *cli, bool autoreconnect)
+{
+	osmo_stream_cli_set_reconnect_timeout(cli, (!autoreconnect) ? 2 : -1);
+	if (osmo_stream_cli_open2(cli, !autoreconnect) < 0) {
+		LOGCLI(cli, "unable to open client\n");
+		return NULL;
+	}
+
+	return cli;
+}
+Note: the result differs from normal init_client_reconnection()
+*/
+
+/* Setting reconnection value explicitly as follows is equivalent to normal init_client_reconnection()
+static struct osmo_stream_cli *init_client_reconnection_broken1(struct osmo_stream_cli *cli, bool autoreconnect)
+{
+	osmo_stream_cli_set_reconnect_timeout(cli, autoreconnect ? 2 : -1);
+	if (osmo_stream_cli_open2(cli, autoreconnect) < 0) {
+		LOGCLI(cli, "unable to open client\n");
+		return NULL;
+	}
+
+	return cli;
+}
+
+static struct osmo_stream_cli *init_client_reconnection_broken2(struct osmo_stream_cli *cli, bool autoreconnect)
+{
+	osmo_stream_cli_set_reconnect_timeout(cli, autoreconnect ? 2 : -1);
+	if (osmo_stream_cli_open2(cli, !autoreconnect) < 0) {
+		LOGCLI(cli, "unable to open client\n");
+		return NULL;
+	}
+
+	return cli;
+}
+*/
+
 static struct osmo_stream_cli *make_client(void *ctx, const char *host, unsigned port, bool autoreconnect)
 {
 	struct osmo_stream_cli *cli = osmo_stream_cli_create(ctx);
@@ -142,6 +212,12 @@
 	osmo_stream_cli_set_connect_cb(cli, connect_cb_cli);
 	osmo_stream_cli_set_read_cb(cli, read_cb_cli);
 
+	/* using
+	   return init_client_reconnection_broken1(cli, autoreconnect);
+	   or
+	   return init_client_reconnection_broken2(cli, autoreconnect);
+	   will result in exactly the same output which might or might not be the same as with
+	   init_client_reconnection() - see preceeding notes */
 	return init_client_reconnection(cli, autoreconnect);
 }
 

-- 
To view, visit https://gerrit.osmocom.org/12845
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: Id988ed0274b363db049f59cbf6a193727c8c3c8a
Gerrit-Change-Number: 12845
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/20190206/b4c005fc/attachment.htm>


More information about the gerrit-log mailing list