diff --git a/lib/sockopt.c b/lib/sockopt.c index 0c4adb0b7c22..41fcc41202ef 100644 --- a/lib/sockopt.c +++ b/lib/sockopt.c @@ -24,9 +24,12 @@ void setsockopt_so_recvbuf(int sock, int size) { int orig_req = size; - while (setsockopt(sock, SOL_SOCKET, SO_RCVBUF, &size, sizeof(size)) - == -1) + while (setsockopt(sock, SOL_SOCKET, SO_RCVBUF, &size, sizeof(size)) == + -1) { + if (size == 0) + break; size /= 2; + } if (size != orig_req) flog_err(EC_LIB_SOCKET, @@ -38,9 +41,12 @@ void setsockopt_so_sendbuf(const int sock, int size) { int orig_req = size; - while (setsockopt(sock, SOL_SOCKET, SO_SNDBUF, &size, sizeof(size)) - == -1) + while (setsockopt(sock, SOL_SOCKET, SO_SNDBUF, &size, sizeof(size)) == + -1) { + if (size == 0) + break; size /= 2; + } if (size != orig_req) flog_err(EC_LIB_SOCKET,