From 0ce3a760d3c43f97bd9fca913696126738ad45b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Duval?= Date: Mon, 1 Feb 2021 18:48:12 +0100 Subject: [PATCH] libnetwork: handle EINTR on select() and poll() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I4e3562bd2564dd0c61142d0b467c81abd393373a Reviewed-on: https://review.haiku-os.org/c/haiku/+/3726 Reviewed-by: waddlesplash Reviewed-by: Axel Dörfler --- src/kits/network/libnetapi/AbstractSocket.cpp | 5 ++++- src/kits/network/libnetapi/NetEndpoint.cpp | 8 +++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/kits/network/libnetapi/AbstractSocket.cpp b/src/kits/network/libnetapi/AbstractSocket.cpp index 8caf62c659..93a0e66787 100644 --- a/src/kits/network/libnetapi/AbstractSocket.cpp +++ b/src/kits/network/libnetapi/AbstractSocket.cpp @@ -309,7 +309,10 @@ BAbstractSocket::_WaitFor(int flags, bigtime_t timeout) const entry.fd = Socket(); entry.events = flags; - int result = poll(&entry, 1, millis); + int result; + do { + result = poll(&entry, 1, millis); + } while (result == -1 && errno == EINTR); if (result < 0) return errno; if (result == 0) diff --git a/src/kits/network/libnetapi/NetEndpoint.cpp b/src/kits/network/libnetapi/NetEndpoint.cpp index 694d62744a..fa8a529b4a 100644 --- a/src/kits/network/libnetapi/NetEndpoint.cpp +++ b/src/kits/network/libnetapi/NetEndpoint.cpp @@ -490,7 +490,13 @@ BNetEndpoint::IsDataPending(bigtime_t timeout) tv.tv_usec = (timeout % 1000000); } - if (select(fSocket + 1, &fds, NULL, NULL, timeout >= 0 ? &tv : NULL) < 0) { + int status; + do { + status = select(fSocket + 1, &fds, NULL, NULL, + timeout >= 0 ? &tv : NULL); + } while (status == -1 && errno == EINTR); + + if (status < 0) { fStatus = errno; return false; }