daniel has uploaded this change for review. ( 
https://gerrit.osmocom.org/c/libosmo-netif/+/34338?usp=email )


Change subject: stream_srv: Fix connection error handling
......................................................................

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
---
M src/stream_srv.c
1 file changed, 25 insertions(+), 10 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmo-netif refs/changes/38/34338/1

diff --git a/src/stream_srv.c b/src/stream_srv.c
index f46175b..1f78707 100644
--- a/src/stream_srv.c
+++ b/src/stream_srv.c
@@ -486,17 +486,17 @@
        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 (res <= 0) {
-               osmo_stream_srv_set_flush_and_destroy(conn);
-               if (osmo_iofd_txqueue_len(iofd) == 0)
-                       osmo_stream_srv_destroy(conn);
+               /* This connection is dead, destroy it. */
+               osmo_stream_srv_destroy(conn);
        } else if (conn->iofd_read_cb) {
+               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;
+               }
                conn->iofd_read_cb(conn, msg);
        }
 }
@@ -506,7 +506,7 @@
        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)

--
To view, visit https://gerrit.osmocom.org/c/libosmo-netif/+/34338?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: libosmo-netif
Gerrit-Branch: master
Gerrit-Change-Id: I84eea2717f3762830f3f5b115e6fc8545eaa4fd5
Gerrit-Change-Number: 34338
Gerrit-PatchSet: 1
Gerrit-Owner: daniel <dwillm...@sysmocom.de>
Gerrit-MessageType: newchange

Reply via email to