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 <info@metux.net>
This commit is contained in:
Enrico Weigelt, metux IT consult
2025-11-07 15:33:54 +01:00
committed by Enrico Weigelt
parent 037a2e5675
commit b0b9a624d8
6 changed files with 21 additions and 22 deletions

View File

@@ -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));
}

View File

@@ -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));
}
/**

View File

@@ -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. */

View File

@@ -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;

View File

@@ -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
}

View File

@@ -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_ */