diff options
author | marha <marha@users.sourceforge.net> | 2010-09-01 08:01:36 +0000 |
---|---|---|
committer | marha <marha@users.sourceforge.net> | 2010-09-01 08:01:36 +0000 |
commit | e09e8cbeb878fc881b6987280e18ce5430318451 (patch) | |
tree | e201d29fb7ae5483f9500d60b98661d3ab7b3ad5 /libxcb/src/xcb_in.c | |
parent | 1244ac35b027dbaa716057f990646adbf93e4a39 (diff) | |
parent | 2062b62455963bd62c0be570b3cac4ad481336d0 (diff) | |
download | vcxsrv-e09e8cbeb878fc881b6987280e18ce5430318451.tar.gz vcxsrv-e09e8cbeb878fc881b6987280e18ce5430318451.tar.bz2 vcxsrv-e09e8cbeb878fc881b6987280e18ce5430318451.zip |
svn merge ^/branches/released .
Diffstat (limited to 'libxcb/src/xcb_in.c')
-rw-r--r-- | libxcb/src/xcb_in.c | 76 |
1 files changed, 32 insertions, 44 deletions
diff --git a/libxcb/src/xcb_in.c b/libxcb/src/xcb_in.c index aaec5c8b4..77278742d 100644 --- a/libxcb/src/xcb_in.c +++ b/libxcb/src/xcb_in.c @@ -30,9 +30,6 @@ #include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
-#ifdef _MSC_VER
-#include <X11/Xwinsock.h>
-#endif
#include <errno.h>
#include "xcb.h"
@@ -40,14 +37,31 @@ #include "xcbint.h"
#if USE_POLL
#include <poll.h>
-#else
+#endif
+#ifndef _WIN32
#include <sys/select.h>
+#include <sys/socket.h>
#endif
+#ifdef _WIN32
+#include "xcb_windefs.h"
+#endif /* _WIN32 */
+
#define XCB_ERROR 0
#define XCB_REPLY 1
#define XCB_XGE_EVENT 35
+#ifdef _MSC_VER
+#ifdef MSG_WAITALL
+#undef MSG_WAITALL
+#endif
+#endif
+
+/* required for compiling for Win32 using MinGW */
+#ifndef MSG_WAITALL
+#define MSG_WAITALL 0
+#endif
+
struct event_list {
xcb_generic_event_t *event;
struct event_list *next;
@@ -255,44 +269,17 @@ static void free_reply_list(struct reply_list *head) static int read_block(const int fd, void *buf, const ssize_t len)
{
-#ifdef _MSC_VER
int done = 0;
while(done < len)
{
- int Err;
- int ret = recv(fd, ((char *) buf) + done, len - done,0);
- if(ret > 0)
- done += ret;
- else
- Err=WSAGetLastError();
- if(ret < 0 && Err == WSAEWOULDBLOCK)
- {
- fd_set fds;
- FD_ZERO(&fds);
- FD_SET(fd, &fds);
- do {
- ret = select(fd + 1, &fds, 0, 0, 0);
- if (ret==SOCKET_ERROR)
- {
- ret=-1;
- errno = WSAGetLastError();
- if (errno == WSAEINTR)
- errno=EINTR;
- }
- } while (ret == -1 && errno == EINTR);
- }
- if(ret <= 0)
- return ret;
- }
- return len;
-#else
- int done = 0;
- while(done < len)
- {
- int ret = read(fd, ((char *) buf) + done, len - done);
+ int ret = recv(fd, ((char *) buf) + done, len - done,MSG_WAITALL);
if(ret > 0)
done += ret;
+#ifndef _WIN32
if(ret < 0 && errno == EAGAIN)
+#else
+ if(ret == SOCKET_ERROR && WSAGetLastError() == WSAEWOULDBLOCK)
+#endif /* !_Win32 */
{
#if USE_POLL
struct pollfd pfd;
@@ -306,16 +293,18 @@ static int read_block(const int fd, void *buf, const ssize_t len) fd_set fds;
FD_ZERO(&fds);
FD_SET(fd, &fds);
+
+ /* Initializing errno here makes sure that for Win32 this loop will execute only once */
+ errno = 0;
do {
ret = select(fd + 1, &fds, 0, 0, 0);
} while (ret == -1 && errno == EINTR);
-#endif
+#endif /* USE_POLL */
}
if(ret <= 0)
return ret;
}
return len;
-#endif
}
static int poll_for_reply(xcb_connection_t *c, unsigned int request, void **reply, xcb_generic_error_t **error)
@@ -698,17 +687,16 @@ void _xcb_in_replies_done(xcb_connection_t *c) int _xcb_in_read(xcb_connection_t *c)
{
- int n = recv(c->fd, c->in.queue + c->in.queue_len, sizeof(c->in.queue) - c->in.queue_len,0); //MH
+ int n = recv(c->fd, c->in.queue + c->in.queue_len, sizeof(c->in.queue) - c->in.queue_len,MSG_WAITALL);
if(n > 0)
c->in.queue_len += n;
while(read_packet(c))
/* empty */;
-#ifdef _MSC_VER
- errno=WSAGetLastError();
- if (errno==WSAEWOULDBLOCK)
- errno=EAGAIN;
-#endif
+#ifndef _WIN32
if((n > 0) || (n < 0 && errno == EAGAIN))
+#else
+ if((n > 0) || (n < 0 && WSAGetLastError() == WSAEWOULDBLOCK))
+#endif /* !_WIN32 */
return 1;
_xcb_conn_shutdown(c);
return 0;
|