Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion os/WaitFor.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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));
}
Expand Down
3 changes: 2 additions & 1 deletion os/inputthread.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -148,7 +149,7 @@ InputThreadFillPipe(int writeHead)

do {
ret = write(writeHead, &byte, 1);
} while (ret < 0 && ETEST(errno));
} while (ret < 0 && ossock_wouldblock(errno));
}

/**
Expand Down
9 changes: 3 additions & 6 deletions os/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you keep this and the comment, if we're keeping the EMSGSIZE test?

Also, what os fails with EMSGSIZE on tcp/unix socket reads?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed that entirely. couldn't find any OS (supported by us) that's returning EMSGSIZE on stream sockets.

|| ((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. */
Expand Down
14 changes: 0 additions & 14 deletions os/osdep.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
9 changes: 9 additions & 0 deletions os/ossock.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
5 changes: 5 additions & 0 deletions os/ossock.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_ */