aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Eversberg <jolly@eversberg.eu>2024-03-15 14:14:46 +0100
committerOliver Smith <osmith@sysmocom.de>2024-03-18 11:02:56 +0100
commit0245cf5e07855abea72693272c55b50b5a93aff4 (patch)
treeeea5f9db86b1c4f9a86d952c17606a4f93c9feb5
parent34a657d1e1fd29241a1b910fb3ec8d1d8a0b03ff (diff)
stream_cli.c: Handle read / recvfrom error and close connectionosmith/wip
If read or recvfrom fails or returns 0, the connection must be closed. This is also done when a write / send fails. In both cases the disconnect callback is called, to notify the user's client. Related: OS#6405 Change-Id: I55426de6b49cb4cb0797e50dfeae11f2efc29b15
-rw-r--r--src/stream_cli.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/stream_cli.c b/src/stream_cli.c
index fa43a22..fdd0c3d 100644
--- a/src/stream_cli.c
+++ b/src/stream_cli.c
@@ -449,9 +449,13 @@ 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)
+ if (res <= 0) {
+ LOGSCLI(cli, LOGL_ERROR, "received result %d in response to read\n", res);
osmo_stream_cli_reconnect(cli);
- else if (cli->iofd_read_cb)
+ msgb_free(msg);
+ break;
+ }
+ if (cli->iofd_read_cb)
cli->iofd_read_cb(cli, msg);
else
msgb_free(msg);
@@ -500,8 +504,12 @@ 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)
+ if (res <= 0) {
+ LOGSCLI(cli, LOGL_ERROR, "received result %d in response to recvmsg\n", res);
osmo_stream_cli_reconnect(cli);
+ msgb_free(msg);
+ break;
+ }
/* Forward message to read callback, also if the connection failed. */
if (cli->iofd_read_cb)
cli->iofd_read_cb(cli, msg);