aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPau Espin Pedrol <pespin@sysmocom.de>2024-04-16 19:11:58 +0200
committerPau Espin Pedrol <pespin@sysmocom.de>2024-04-18 10:55:13 +0200
commit05ff552f25cde5d84f428421bd4d2d64fae0bc9d (patch)
tree2106b0a857960293a5231e049eeb88b4f61c78cb /src
parent01f33ec93fa355f9cd1016610d7fe92cde5aaa2d (diff)
stream_{cli,srv}: Add 'res' param to read_cb2HEADpespin/streammaster
Notify user about read errors, similar to what is supported in the earlier ofd cb backend of osmo_stream_cli/srv: https://osmocom.org/issues/6405#note-15 Related: OS#6405 Fixes: 5fec34a9f20c3b8769373d1b28ae2062e5e2bdd6 Fixes: 0245cf5e07855abea72693272c55b50b5a93aff4 Change-Id: I395c75ff1e9904757ce1d767a9ac2f779593c4c8
Diffstat (limited to 'src')
-rw-r--r--src/stream_cli.c34
-rw-r--r--src/stream_srv.c80
2 files changed, 70 insertions, 44 deletions
diff --git a/src/stream_cli.c b/src/stream_cli.c
index 62ea03e..d4067d6 100644
--- a/src/stream_cli.c
+++ b/src/stream_cli.c
@@ -448,14 +448,23 @@ static void stream_cli_iofd_read_cb(struct osmo_io_fd *iofd, int res, struct msg
stream_cli_handle_connecting(cli, res);
break;
case STREAM_CLI_STATE_CONNECTED:
- if (res <= 0) {
- LOGSCLI(cli, LOGL_NOTICE, "received result %d in response to read\n", res);
+ switch (res) {
+ case -EPIPE:
+ case -ECONNRESET:
+ LOGSCLI(cli, LOGL_ERROR, "lost connection with srv (%d)\n", res);
osmo_stream_cli_reconnect(cli);
- msgb_free(msg);
+ break;
+ case 0:
+ LOGSCLI(cli, LOGL_NOTICE, "connection closed with srv\n");
+ osmo_stream_cli_reconnect(cli);
+ break;
+ default:
+ LOGSCLI(cli, LOGL_DEBUG, "received %d bytes from srv\n", res);
break;
}
+ /* Notify user of new data or error: */
if (cli->iofd_read_cb)
- cli->iofd_read_cb(cli, msg);
+ cli->iofd_read_cb(cli, res, msg);
else
msgb_free(msg);
break;
@@ -503,15 +512,22 @@ static void stream_cli_iofd_recvmsg_cb(struct osmo_io_fd *iofd, int res, struct
stream_cli_handle_connecting(cli, res);
break;
case STREAM_CLI_STATE_CONNECTED:
- if (res <= 0) {
- LOGSCLI(cli, LOGL_NOTICE, "received result %d in response to recvmsg\n", res);
+ switch (res) {
+ case -EPIPE:
+ case -ECONNRESET:
+ LOGSCLI(cli, LOGL_ERROR, "lost connection with srv (%d)\n", res);
osmo_stream_cli_reconnect(cli);
- msgb_free(msg);
+ break;
+ case 0:
+ LOGSCLI(cli, LOGL_NOTICE, "connection closed with srv\n");
+ osmo_stream_cli_reconnect(cli);
+ break;
+ default:
break;
}
- /* Forward message to read callback, also if the connection failed. */
+ /* Notify user of new data or error: */
if (cli->iofd_read_cb)
- cli->iofd_read_cb(cli, msg);
+ cli->iofd_read_cb(cli, res, msg);
else
msgb_free(msg);
break;
diff --git a/src/stream_srv.c b/src/stream_srv.c
index 74193a4..dad6b7a 100644
--- a/src/stream_srv.c
+++ b/src/stream_srv.c
@@ -611,26 +611,31 @@ struct osmo_stream_srv {
static void stream_srv_iofd_read_cb(struct osmo_io_fd *iofd, int res, struct msgb *msg)
{
struct osmo_stream_srv *conn = osmo_iofd_get_data(iofd);
- LOGSSRV(conn, LOGL_DEBUG, "message received (res=%d)\n", res);
- if (OSMO_UNLIKELY(res <= 0)) {
- /* This connection is dead, destroy it. */
+ switch (res) {
+ case -EPIPE:
+ case -ECONNRESET:
+ LOGSSRV(conn, LOGL_ERROR, "lost connection with client (%d)\n", res);
+ break;
+ case 0:
+ LOGSSRV(conn, LOGL_NOTICE, "connection closed with client\n");
+ break;
+ default:
+ LOGSSRV(conn, LOGL_DEBUG, "received %d bytes from client\n", res);
+ break;
+ }
+ if (OSMO_UNLIKELY(conn->flags & OSMO_STREAM_SRV_F_FLUSH_DESTROY)) {
+ LOGSSRV(conn, LOGL_INFO, "Connection is being flushed and closed; ignoring received message\n");
msgb_free(msg);
- osmo_stream_srv_destroy(conn);
- } else {
- if (conn->flags & OSMO_STREAM_SRV_F_FLUSH_DESTROY) {
- LOGSSRV(conn, LOGL_INFO, "Connection is being flushed and closed; ignoring received message\n");
- msgb_free(msg);
- if (osmo_iofd_txqueue_len(iofd) == 0)
- osmo_stream_srv_destroy(conn);
- return;
- }
-
- if (conn->iofd_read_cb)
- conn->iofd_read_cb(conn, msg);
- else
- msgb_free(msg);
+ if (osmo_iofd_txqueue_len(iofd) == 0)
+ osmo_stream_srv_destroy(conn);
+ return;
}
+
+ if (conn->iofd_read_cb)
+ conn->iofd_read_cb(conn, res, msg);
+ else
+ msgb_free(msg);
}
static void stream_srv_iofd_write_cb(struct osmo_io_fd *iofd, int res, struct msgb *msg)
@@ -658,27 +663,32 @@ static void stream_srv_iofd_recvmsg_cb(struct osmo_io_fd *iofd, int res, struct
LOGSSRV(conn, LOGL_DEBUG, "message received (res=%d)\n", res);
res = stream_iofd_sctp_recvmsg_trailer(iofd, msg, res, msgh);
- if (res == -EAGAIN)
- return;
- if (OSMO_UNLIKELY(res <= 0)) {
- /* This connection is dead, destroy it. */
+ switch (res) {
+ case -EPIPE:
+ case -ECONNRESET:
+ LOGSSRV(conn, LOGL_ERROR, "lost connection with client (%d)\n", res);
+ break;
+ case 0:
+ LOGSSRV(conn, LOGL_NOTICE, "connection closed with client\n");
+ break;
+ default:
+ if (OSMO_LIKELY(res > 0))
+ LOGSSRV(conn, LOGL_DEBUG, "received %u bytes from client\n", res);
+ break;
+ }
+ if (OSMO_UNLIKELY(conn->flags & OSMO_STREAM_SRV_F_FLUSH_DESTROY)) {
+ LOGSSRV(conn, LOGL_INFO, "Connection is being flushed and closed; ignoring received message\n");
msgb_free(msg);
- osmo_stream_srv_destroy(conn);
- } else {
- if (conn->flags & OSMO_STREAM_SRV_F_FLUSH_DESTROY) {
- LOGSSRV(conn, LOGL_INFO, "Connection is being flushed and closed; ignoring received message\n");
- msgb_free(msg);
- if (osmo_iofd_txqueue_len(iofd) == 0)
- osmo_stream_srv_destroy(conn);
- return;
- }
-
- if (conn->iofd_read_cb)
- conn->iofd_read_cb(conn, msg);
- else
- msgb_free(msg);
+ if (osmo_iofd_txqueue_len(iofd) == 0)
+ osmo_stream_srv_destroy(conn);
+ return;
}
+
+ if (conn->iofd_read_cb)
+ conn->iofd_read_cb(conn, res, msg);
+ else
+ msgb_free(msg);
}
static const struct osmo_io_ops srv_ioops_sctp = {