From 8f039cc2055a96d9660a0856f1448bf016d5ecb2 Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Fri, 7 Nov 2025 15:33:54 +0100 Subject: [PATCH] os: replace ETEST macro by ossock_wouldblock() Move this to a little function (which also has a better name now) inside the already platform specific ossock.c Also removing the EMSGSIZE check: we're using TCP or local unix socket, so EMSGSIZE is never returned. Signed-off-by: Enrico Weigelt, metux IT consult --- os/WaitFor.c | 3 ++- os/inputthread.c | 3 ++- os/io.c | 9 +++------ os/osdep.h | 14 -------------- os/ossock.c | 9 +++++++++ os/ossock.h | 5 +++++ 6 files changed, 21 insertions(+), 22 deletions(-) diff --git a/os/WaitFor.c b/os/WaitFor.c index ed86839dad..992962df4b 100644 --- a/os/WaitFor.c +++ b/os/WaitFor.c @@ -66,6 +66,7 @@ SOFTWARE. #include "dix/screensaver_priv.h" #include "os/busfault.h" #include "os/client_priv.h" +#include "os/ossock.h" #include "os/screensaver.h" #include "misc.h" @@ -210,7 +211,7 @@ WaitForSomething(Bool are_ready) if (dispatchException) return FALSE; if (i < 0) { - if (pollerr != EINTR && !ETEST(pollerr)) { + if (pollerr != EINTR && ossock_wouldblock(pollerr)) { ErrorF("WaitForSomething(): poll: %s\n", strerror(pollerr)); } diff --git a/os/inputthread.c b/os/inputthread.c index ea43bf1c30..07399a113e 100644 --- a/os/inputthread.c +++ b/os/inputthread.c @@ -36,6 +36,7 @@ #include "dix/input_priv.h" #include "os/ddx_priv.h" #include "os/log_priv.h" +#include "os/ossock.h" #include "inputstr.h" #include "opaque.h" @@ -148,7 +149,7 @@ InputThreadFillPipe(int writeHead) do { ret = write(writeHead, &byte, 1); - } while (ret < 0 && ETEST(errno)); + } while (ret < 0 && ossock_wouldblock(errno)); } /** diff --git a/os/io.c b/os/io.c index 8c5d60e29b..d6be03f1e3 100644 --- a/os/io.c +++ b/os/io.c @@ -76,6 +76,7 @@ SOFTWARE. #include "os/bug_priv.h" #include "os/client_priv.h" #include "os/osdep.h" +#include "os/ossock.h" #include "os.h" #include "opaque.h" @@ -360,7 +361,7 @@ ReadRequestFromClient(ClientPtr client) result = _XSERVTransRead(oc->trans_conn, oci->buffer + oci->bufcnt, oci->size - oci->bufcnt); if (result <= 0) { - if ((result < 0) && ETEST(errno)) { + if ((result < 0) && ossock_wouldblock(errno)) { mark_client_not_ready(client); YieldControlNoInput(client); return 0; @@ -937,11 +938,7 @@ FlushClient(ClientPtr who, OsCommPtr oc) notWritten -= len; todo = notWritten; } - else if (ETEST(errno) -#ifdef EMSGSIZE /* check for another brain-damaged OS bug */ - || ((errno == EMSGSIZE) && (todo == 1)) -#endif - ) { + else if (ossock_wouldblock(errno)) { /* If we've arrived here, then the client is stuffed to the gills and not ready to accept more. Make a note of it and buffer the rest. */ diff --git a/os/osdep.h b/os/osdep.h index 5ea06c547a..f63b93c1ee 100644 --- a/os/osdep.h +++ b/os/osdep.h @@ -61,20 +61,6 @@ SOFTWARE. # define __has_builtin(x) 0 /* Compatibility with older compilers */ #endif -/* If EAGAIN and EWOULDBLOCK are distinct errno values, then we check errno - * for both EAGAIN and EWOULDBLOCK, because some supposedly POSIX - * systems are broken and return EWOULDBLOCK when they should return EAGAIN - */ -#ifndef WIN32 -# if (EAGAIN != EWOULDBLOCK) -# define ETEST(err) (err == EAGAIN || err == EWOULDBLOCK) -# else -# define ETEST(err) (err == EAGAIN) -# endif -#else /* WIN32 The socket errorcodes differ from the normal errors */ -#define ETEST(err) (err == EAGAIN || err == WSAEWOULDBLOCK) -#endif - typedef struct _connectionInput *ConnectionInputPtr; typedef struct _connectionOutput *ConnectionOutputPtr; diff --git a/os/ossock.c b/os/ossock.c index f9cac0151d..68e1cdb29e 100644 --- a/os/ossock.c +++ b/os/ossock.c @@ -46,3 +46,12 @@ int ossock_close(int fd) return close(fd); #endif } + +int ossock_wouldblock(int err) +{ +#ifdef WIN32 + return ((err == EAGAIN) || (err == WSAEWOULDBLOCK)); +#else + return ((err == EAGAIN) || (err == EWOULDBLOCK)); +#endif +} diff --git a/os/ossock.h b/os/ossock.h index 254ed5d083..b2475285b8 100644 --- a/os/ossock.h +++ b/os/ossock.h @@ -22,4 +22,9 @@ int ossock_ioctl(int fd, unsigned long request, void *arg); */ int ossock_close(int fd); +/* + * os specific check for errno indicating operation would block + */ +int ossock_wouldblock(int err); + #endif /* _XSERVER_OS_OSSOCK_H_ */