From 9fb31c13df0d2bffc602b6cc7f67b76033471874 Mon Sep 17 00:00:00 2001 From: Pau Espin Pedrol Date: Tue, 16 Apr 2024 19:37:27 +0200 Subject: cbsp_link.c: Update somo_stream read_cb2 functions to accommodate for new API param libosmo-netif (not yet released) stream_{cli,srv} osmo_io read_cb API was updated to provide read result status. Hence, now API users can account for lower layer errors and act properly, like it used to do with the previous ofd backend. This commit partially reverts some error code paths removed in 85687bf176e4b9663f2396a27c28b49221c72fa3 when converting code to use osmo_io osmo_stream backend. Change-Id: I4cce5cb6ca98bc28a67dd6e927e9cdfd2312851a Depends: libosmo-netif.git Change-Id I395c75ff1e9904757ce1d767a9ac2f779593c4c8 --- src/osmo-bsc/cbsp_link.c | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/src/osmo-bsc/cbsp_link.c b/src/osmo-bsc/cbsp_link.c index 98f25d358..9e17ef373 100644 --- a/src/osmo-bsc/cbsp_link.c +++ b/src/osmo-bsc/cbsp_link.c @@ -62,11 +62,28 @@ static int cbsp_srv_closed_cb(struct osmo_stream_srv *conn) return 0; } -static int cbsp_srv_read_cb(struct osmo_stream_srv *conn, struct msgb *msg) +static int cbsp_srv_read_cb(struct osmo_stream_srv *conn, int res, struct msgb *msg) { struct bsc_cbc_link *cbc = osmo_stream_srv_get_data(conn); struct osmo_cbsp_decoded *decoded; + if (res <= 0) { + if (res == -EAGAIN || res == -EINTR) { + msgb_free(msg); + return 0; + } + /* + if (rc == -EPIPE || rc == -ECONNRESET) { + // lost connection + } else if (rc == 0) { + // connection closed + } */ + msgb_free(msg); + osmo_stream_srv_destroy(conn); + cbc->server.srv = NULL; + return -EBADF; + } + OSMO_ASSERT(msg); decoded = osmo_cbsp_decode(conn, msg); if (decoded) { @@ -148,11 +165,27 @@ static int cbsp_client_disconnect_cb(struct osmo_stream_cli *cli) return 0; } -static int cbsp_client_read_cb(struct osmo_stream_cli *cli, struct msgb *msg) +static int cbsp_client_read_cb(struct osmo_stream_cli *cli, int res, struct msgb *msg) { struct bsc_cbc_link *cbc = osmo_stream_cli_get_data(cli); struct osmo_cbsp_decoded *decoded; + if (res <= 0) { + if (res == -EAGAIN || res == -EINTR) { + msgb_free(msg); + return 0; + } + /* + if (rc == -EPIPE || rc == -ECONNRESET) { + // lost connection + } else if (rc == 0) { + // connection closed + } */ + msgb_free(msg); + osmo_stream_cli_reconnect(cli); + return -EBADF; + } + OSMO_ASSERT(msg); decoded = osmo_cbsp_decode(cli, msg); if (decoded) { -- cgit v1.2.3