From 4ce53ff10755ccb19914a7017dad2905d0339125 Mon Sep 17 00:00:00 2001 From: Max Date: Tue, 29 Jan 2019 18:17:57 +0100 Subject: Stream examples: fix server's endless loop Stream server example had an error which resulted in infinite loop on client disconnect. Fix this by properly handling client closing connection to allow it to reconnect multiple times. Change-Id: Icfc2cf7f971b9e3a4abc34cc18d8a44c811c5617 --- examples/stream-server.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'examples/stream-server.c') diff --git a/examples/stream-server.c b/examples/stream-server.c index cd6dc57..31487a0 100644 --- a/examples/stream-server.c +++ b/examples/stream-server.c @@ -56,9 +56,12 @@ int read_cb(struct osmo_stream_srv *conn) bytes = osmo_stream_srv_recv(conn, msg); - if (bytes < 0) { - LOGPC(DSTREAMTEST, LOGL_ERROR, "cannot receive message: %s\n", strerror(-bytes)); - return 0; + if (bytes <= 0) { + if (bytes < 0) + LOGPC(DSTREAMTEST, LOGL_ERROR, "cannot receive message: %s\n", strerror(-bytes)); + else + LOGPC(DSTREAMTEST, LOGL_ERROR, "client closed connection\n"); + osmo_stream_srv_destroy(conn); } else LOGPC(DSTREAMTEST, LOGL_NOTICE, "got %d (%d) bytes: %s\n", bytes, msg->len, msgb_hexdump(msg)); -- cgit v1.2.3