aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Willmann <dwillmann@sysmocom.de>2023-09-07 16:26:25 +0200
committerdaniel <dwillmann@sysmocom.de>2023-09-29 15:26:46 +0000
commit59a785b62840305b8df59992b6dbb4cb530fbdd9 (patch)
tree21a64196779fda41719398abfe7662d73ac785cb
parent0c4c47ddfb2d90d88045e85702885fef92d8634c (diff)
stream_srv: Fix connection error handling
If read returned an error or the stream got closed then simply destroy the connection. If the user code called osmo_stream_srv_set_flush_and_destroy() then ignore any incoming messages and destroy the connection once the tx queue is empty. Change-Id: I84eea2717f3762830f3f5b115e6fc8545eaa4fd5
-rw-r--r--src/stream_srv.c28
1 files changed, 16 insertions, 12 deletions
diff --git a/src/stream_srv.c b/src/stream_srv.c
index ca22e1b..e789584 100644
--- a/src/stream_srv.c
+++ b/src/stream_srv.c
@@ -532,18 +532,22 @@ static void stream_srv_iofd_read_cb(struct osmo_io_fd *iofd, int res, struct msg
struct osmo_stream_srv *conn = osmo_iofd_get_data(iofd);
LOGSSRV(conn, LOGL_DEBUG, "message received (res=%d)\n", res);
- 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);
- return;
- }
+ if (OSMO_UNLIKELY(res <= 0)) {
+ /* This connection is dead, destroy it. */
+ 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 (res <= 0) {
- osmo_stream_srv_set_flush_and_destroy(conn);
- if (osmo_iofd_txqueue_len(iofd) == 0)
- osmo_stream_srv_destroy(conn);
- } else if (conn->iofd_read_cb) {
- conn->iofd_read_cb(conn, msg);
+ if (conn->iofd_read_cb)
+ conn->iofd_read_cb(conn, msg);
+ else
+ msgb_free(msg);
}
}
@@ -552,7 +556,7 @@ static void stream_srv_iofd_write_cb(struct osmo_io_fd *iofd, int res, struct ms
struct osmo_stream_srv *conn = osmo_iofd_get_data(iofd);
LOGSSRV(conn, LOGL_DEBUG, "connected write\n");
- if (res == -1)
+ if (res < 0)
LOGSSRV(conn, LOGL_ERROR, "error to send: %s\n", strerror(errno));
if (osmo_iofd_txqueue_len(iofd) == 0)