diff options
author | Max <msuraev@sysmocom.de> | 2019-02-06 17:27:18 +0100 |
---|---|---|
committer | Harald Welte <laforge@gnumonks.org> | 2019-03-19 13:40:55 +0000 |
commit | b3e34435b3bde227805c8dcac39c28e57144e500 (patch) | |
tree | 66553c23c3392dd1cb6733ad9693048d8d97136f /tests | |
parent | 1ab218d28f684a431cd9de972499b987b63a507a (diff) |
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 default due to
positive reconnection timeout value (5 sec) automatically 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.
The only known user is libosmo-sccp which won't use it as of
0a93a683f3cb8e5977eb4a666ab207db6e7d7af9 commit.
Change-Id: Id988ed0274b363db049f59cbf6a193727c8c3c8a
Diffstat (limited to 'tests')
-rw-r--r-- | tests/stream/stream_test.c | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/tests/stream/stream_test.c b/tests/stream/stream_test.c index 1a0c555..439ea1a 100644 --- a/tests/stream/stream_test.c +++ b/tests/stream/stream_test.c @@ -126,6 +126,76 @@ static struct osmo_stream_cli *init_client_reconnection(struct osmo_stream_cli * 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); @@ -141,6 +211,12 @@ static struct osmo_stream_cli *make_client(void *ctx, const char *host, unsigned 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); } |