From fe4d4f04c7379843e603687e0e39432f21bb27ae Mon Sep 17 00:00:00 2001 From: Jake Smith Date: Fri, 12 Jul 2024 11:33:54 +0100 Subject: [PATCH] minor review changes Signed-off-by: Jake Smith --- system/jlib/jsocket.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/system/jlib/jsocket.cpp b/system/jlib/jsocket.cpp index 816f69d725e..14fa5aed316 100644 --- a/system/jlib/jsocket.cpp +++ b/system/jlib/jsocket.cpp @@ -666,6 +666,7 @@ static win_socket_library ws32_lib; #define JSE_NOTSOCK WSAENOTSOCK #define JSE_TIMEDOUT WSAETIMEDOUT #define JSE_CONNREFUSED WSAECONNREFUSED +#define JSE_EAGAIN WSAEWOULDBLOCK #define JSE_BADF WSAEBADF #define JSE_INTR WSAEINTR @@ -785,6 +786,7 @@ int inet_aton (const char *name, struct in_addr *addr) #define JSE_NOTSOCK ENOTSOCK #define JSE_TIMEDOUT ETIMEDOUT #define JSE_CONNREFUSED ECONNREFUSED +#define JSE_EAGAIN EAGAIN #define JSE_BADF EBADF @@ -1982,7 +1984,7 @@ void CSocket::readtms(void* buf, size32_t min_size, size32_t max_size, size32_t } else { - if (err == JSE_WOULDBLOCK || err == EAGAIN) // if EGAIN or EWOULDBLOCK - no more data to read + if (err == JSE_WOULDBLOCK || err == JSE_EAGAIN) // if EAGAIN or EWOULDBLOCK - no more data to read { //NB: in UDP can only reach here if have not read anything so far. @@ -2138,7 +2140,7 @@ size32_t CSocket::writetms(void const* buf, size32_t minSize, size32_t size, uns errclose(); err = JSOCKERR_broken_pipe; } - if (err == JSE_WOULDBLOCK) + if (err == JSE_WOULDBLOCK || err == JSE_EAGAIN) { if (sizeWritten >= minSize) break; @@ -7242,6 +7244,12 @@ extern jlib_decl void shutdownAndCloseNoThrow(ISocket * optSocket) //// void ScopedNonBlockingMode::init(ISocket *_socket) { + // NB: for the time being, don't switch to non-blocking mode for UDP connections (may want to revisit). + // It probably does make sense, e.g. to allow readtms/writetms to be called with min_size 0 and return if blocked, + // but we don't depend on it at the moment, and to reduce the impact of these semantic changes, leave UDP as blocking for now. + // It would likely be necessary if UDP+SSL were ever in play. + if (socket->connectionless()) + return; socket = _socket; if (socket->set_nonblock(true)) // was already nonblocking socket = nullptr; // nothing to reset in dtor