From 5a6c8e588b8a0dbb98d4b5ad36e9fed0183173b6 Mon Sep 17 00:00:00 2001 From: icex2 Date: Sat, 23 Jan 2021 23:05:52 +0100 Subject: [PATCH] util/sock-tcp: Fix non blocking receiving, detect broken connection --- src/main/util/sock-tcp.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/util/sock-tcp.c b/src/main/util/sock-tcp.c index 4e11475..a823fea 100644 --- a/src/main/util/sock-tcp.c +++ b/src/main/util/sock-tcp.c @@ -260,9 +260,12 @@ ssize_t util_sock_tcp_recv(int handle, void* buffer, size_t size, uint32_t timeo } return -1; + } else if (length == 0) { + // connection lost + return -1; + } else { + return length; } - - return length; } void util_sock_tcp_close(int handle)