Skip to content

Commit 78e09b7

Browse files
committed
[PR #1364] os: replace ETEST macro by ossock_wouldblock()
PR: #1364
1 parent 8e835a0 commit 78e09b7

File tree

6 files changed

+21
-22
lines changed

6 files changed

+21
-22
lines changed

os/WaitFor.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ SOFTWARE.
6666
#include "dix/screensaver_priv.h"
6767
#include "os/busfault.h"
6868
#include "os/client_priv.h"
69+
#include "os/ossock.h"
6970
#include "os/screensaver.h"
7071

7172
#include "misc.h"
@@ -210,7 +211,7 @@ WaitForSomething(Bool are_ready)
210211
if (dispatchException)
211212
return FALSE;
212213
if (i < 0) {
213-
if (pollerr != EINTR && !ETEST(pollerr)) {
214+
if (pollerr != EINTR && ossock_wouldblock(pollerr)) {
214215
ErrorF("WaitForSomething(): poll: %s\n",
215216
strerror(pollerr));
216217
}

os/inputthread.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "dix/input_priv.h"
3737
#include "os/ddx_priv.h"
3838
#include "os/log_priv.h"
39+
#include "os/ossock.h"
3940

4041
#include "inputstr.h"
4142
#include "opaque.h"
@@ -148,7 +149,7 @@ InputThreadFillPipe(int writeHead)
148149

149150
do {
150151
ret = write(writeHead, &byte, 1);
151-
} while (ret < 0 && ETEST(errno));
152+
} while (ret < 0 && ossock_wouldblock(errno));
152153
}
153154

154155
/**

os/io.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ SOFTWARE.
7676
#include "os/bug_priv.h"
7777
#include "os/client_priv.h"
7878
#include "os/osdep.h"
79+
#include "os/ossock.h"
7980

8081
#include "os.h"
8182
#include "opaque.h"
@@ -360,7 +361,7 @@ ReadRequestFromClient(ClientPtr client)
360361
result = _XSERVTransRead(oc->trans_conn, oci->buffer + oci->bufcnt,
361362
oci->size - oci->bufcnt);
362363
if (result <= 0) {
363-
if ((result < 0) && ETEST(errno)) {
364+
if ((result < 0) && ossock_wouldblock(errno)) {
364365
mark_client_not_ready(client);
365366
YieldControlNoInput(client);
366367
return 0;
@@ -937,11 +938,7 @@ FlushClient(ClientPtr who, OsCommPtr oc)
937938
notWritten -= len;
938939
todo = notWritten;
939940
}
940-
else if (ETEST(errno)
941-
#ifdef EMSGSIZE /* check for another brain-damaged OS bug */
942-
|| ((errno == EMSGSIZE) && (todo == 1))
943-
#endif
944-
) {
941+
else if (ossock_wouldblock(errno) || ((errno == EMSGSIZE) && (todo == 1))) {
945942
/* If we've arrived here, then the client is stuffed to the gills
946943
and not ready to accept more. Make a note of it and buffer
947944
the rest. */

os/osdep.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -61,20 +61,6 @@ SOFTWARE.
6161
# define __has_builtin(x) 0 /* Compatibility with older compilers */
6262
#endif
6363

64-
/* If EAGAIN and EWOULDBLOCK are distinct errno values, then we check errno
65-
* for both EAGAIN and EWOULDBLOCK, because some supposedly POSIX
66-
* systems are broken and return EWOULDBLOCK when they should return EAGAIN
67-
*/
68-
#ifndef WIN32
69-
# if (EAGAIN != EWOULDBLOCK)
70-
# define ETEST(err) (err == EAGAIN || err == EWOULDBLOCK)
71-
# else
72-
# define ETEST(err) (err == EAGAIN)
73-
# endif
74-
#else /* WIN32 The socket errorcodes differ from the normal errors */
75-
#define ETEST(err) (err == EAGAIN || err == WSAEWOULDBLOCK)
76-
#endif
77-
7864
typedef struct _connectionInput *ConnectionInputPtr;
7965
typedef struct _connectionOutput *ConnectionOutputPtr;
8066

os/ossock.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,12 @@ int ossock_close(int fd)
4646
return close(fd);
4747
#endif
4848
}
49+
50+
int ossock_wouldblock(int err)
51+
{
52+
#ifdef WIN32
53+
return ((err == EAGAIN) || (err == WSAEWOULDBLOCK));
54+
#else
55+
return ((err == EAGAIN) || (err == EWOULDBLOCK));
56+
#endif
57+
}

os/ossock.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,9 @@ int ossock_ioctl(int fd, unsigned long request, void *arg);
2222
*/
2323
int ossock_close(int fd);
2424

25+
/*
26+
* os specific check for errno indicating operation would block
27+
*/
28+
int ossock_wouldblock(int err);
29+
2530
#endif /* _XSERVER_OS_OSSOCK_H_ */

0 commit comments

Comments
 (0)