<p>Max has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.osmocom.org/12845">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">Deprecate osmo_stream_cli_open2()<br><br>This supposed to be variant of osmo_stream_cli_open() with explicit<br>control over reconnection logic but it's plain broken: doxygen docs<br>contradict the code, actual reconnection logic is affected by timeout<br>parameter directly which is set in different function.<br><br>It seems like we haven't been affected by this so far because we always<br>use it in auto-reconnection mode which is triggered by due to positive<br>reconnection timeout value (5 sec) used in the absense of explicitly set<br>timeout.<br><br>Looking at commit history, this function already been source of<br>confusion in the past. Instead of trying to fix this mess, let's just<br>deprecate it entirely and properly document use of<br>osmo_stream_cli_set_reconnect_timeout() to control reconnection logic.<br><br>Change-Id: Id988ed0274b363db049f59cbf6a193727c8c3c8a<br>---<br>M include/osmocom/netif/stream.h<br>M tests/stream/stream_test.c<br>2 files changed, 77 insertions(+), 1 deletion(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.osmocom.org:29418/libosmo-netif refs/changes/45/12845/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/include/osmocom/netif/stream.h b/include/osmocom/netif/stream.h</span><br><span>index 3044511..f64daf9 100644</span><br><span>--- a/include/osmocom/netif/stream.h</span><br><span>+++ b/include/osmocom/netif/stream.h</span><br><span>@@ -71,7 +71,7 @@</span><br><span> void osmo_stream_cli_destroy(struct osmo_stream_cli *cli);</span><br><span> </span><br><span> int osmo_stream_cli_open(struct osmo_stream_cli *cli);</span><br><span style="color: hsl(0, 100%, 40%);">-int osmo_stream_cli_open2(struct osmo_stream_cli *cli, int reconnect);</span><br><span style="color: hsl(120, 100%, 40%);">+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");</span><br><span> void osmo_stream_cli_close(struct osmo_stream_cli *cli);</span><br><span> </span><br><span> void osmo_stream_cli_send(struct osmo_stream_cli *cli, struct msgb *msg);</span><br><span>diff --git a/tests/stream/stream_test.c b/tests/stream/stream_test.c</span><br><span>index 7a24e21..35d18b5 100644</span><br><span>--- a/tests/stream/stream_test.c</span><br><span>+++ b/tests/stream/stream_test.c</span><br><span>@@ -127,6 +127,76 @@</span><br><span>      return cli;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+/* Without explicit timeout set with osmo_stream_cli_set_reconnect_timeout() default value is used.</span><br><span style="color: hsl(120, 100%, 40%);">+static struct osmo_stream_cli *init_client_reconnection_broken1(struct osmo_stream_cli *cli, bool autoreconnect)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+        if (osmo_stream_cli_open2(cli, autoreconnect) < 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+               LOGCLI(cli, "unable to open client\n");</span><br><span style="color: hsl(120, 100%, 40%);">+             return NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+  }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+   return cli;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+That's why those those functions result in exact the same output despite inverse use of autoreconnect parameter.</span><br><span style="color: hsl(120, 100%, 40%);">+static struct osmo_stream_cli *init_client_reconnection_broken2(struct osmo_stream_cli *cli, bool autoreconnect)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+     if (osmo_stream_cli_open2(cli, !autoreconnect) < 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+              LOGCLI(cli, "unable to open client\n");</span><br><span style="color: hsl(120, 100%, 40%);">+             return NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+  }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+   return cli;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+Variant below are also equivalent to each other.</span><br><span style="color: hsl(120, 100%, 40%);">+static struct osmo_stream_cli *init_client_reconnection_broken1(struct osmo_stream_cli *cli, bool autoreconnect)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+       osmo_stream_cli_set_reconnect_timeout(cli, (!autoreconnect) ? 2 : -1);</span><br><span style="color: hsl(120, 100%, 40%);">+        if (osmo_stream_cli_open2(cli, autoreconnect) < 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+               LOGCLI(cli, "unable to open client\n");</span><br><span style="color: hsl(120, 100%, 40%);">+             return NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+  }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+   return cli;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+static struct osmo_stream_cli *init_client_reconnection_broken2(struct osmo_stream_cli *cli, bool autoreconnect)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ osmo_stream_cli_set_reconnect_timeout(cli, (!autoreconnect) ? 2 : -1);</span><br><span style="color: hsl(120, 100%, 40%);">+        if (osmo_stream_cli_open2(cli, !autoreconnect) < 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+              LOGCLI(cli, "unable to open client\n");</span><br><span style="color: hsl(120, 100%, 40%);">+             return NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+  }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+   return cli;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+Note: the result differs from normal init_client_reconnection()</span><br><span style="color: hsl(120, 100%, 40%);">+*/</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/* Setting reconnection value explicitly as follows is equivalent to normal init_client_reconnection()</span><br><span style="color: hsl(120, 100%, 40%);">+static struct osmo_stream_cli *init_client_reconnection_broken1(struct osmo_stream_cli *cli, bool autoreconnect)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+    osmo_stream_cli_set_reconnect_timeout(cli, autoreconnect ? 2 : -1);</span><br><span style="color: hsl(120, 100%, 40%);">+   if (osmo_stream_cli_open2(cli, autoreconnect) < 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+               LOGCLI(cli, "unable to open client\n");</span><br><span style="color: hsl(120, 100%, 40%);">+             return NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+  }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+   return cli;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+static struct osmo_stream_cli *init_client_reconnection_broken2(struct osmo_stream_cli *cli, bool autoreconnect)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ osmo_stream_cli_set_reconnect_timeout(cli, autoreconnect ? 2 : -1);</span><br><span style="color: hsl(120, 100%, 40%);">+   if (osmo_stream_cli_open2(cli, !autoreconnect) < 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+              LOGCLI(cli, "unable to open client\n");</span><br><span style="color: hsl(120, 100%, 40%);">+             return NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+  }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+   return cli;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+*/</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> static struct osmo_stream_cli *make_client(void *ctx, const char *host, unsigned port, bool autoreconnect)</span><br><span> {</span><br><span>      struct osmo_stream_cli *cli = osmo_stream_cli_create(ctx);</span><br><span>@@ -142,6 +212,12 @@</span><br><span>    osmo_stream_cli_set_connect_cb(cli, connect_cb_cli);</span><br><span>         osmo_stream_cli_set_read_cb(cli, read_cb_cli);</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+    /* using</span><br><span style="color: hsl(120, 100%, 40%);">+         return init_client_reconnection_broken1(cli, autoreconnect);</span><br><span style="color: hsl(120, 100%, 40%);">+          or</span><br><span style="color: hsl(120, 100%, 40%);">+    return init_client_reconnection_broken2(cli, autoreconnect);</span><br><span style="color: hsl(120, 100%, 40%);">+          will result in exactly the same output which might or might not be the same as with</span><br><span style="color: hsl(120, 100%, 40%);">+           init_client_reconnection() - see preceeding notes */</span><br><span>      return init_client_reconnection(cli, autoreconnect);</span><br><span> }</span><br><span> </span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/12845">change 12845</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.osmocom.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.osmocom.org/12845"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: libosmo-netif </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: Id988ed0274b363db049f59cbf6a193727c8c3c8a </div>
<div style="display:none"> Gerrit-Change-Number: 12845 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Max <msuraev@sysmocom.de> </div>