diff options
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;
|