[Xcb-commit] 8 commits - src

Peter Harris peterh at kemper.freedesktop.org
Tue Aug 31 15:40:06 PDT 2010


 src/xcb.h         |    4 ++++
 src/xcb_auth.c    |   11 ++++++++---
 src/xcb_conn.c    |   49 +++++++++++++++++++++++++++++++++++++++++++++++--
 src/xcb_in.c      |   30 ++++++++++++++++++++++++++----
 src/xcb_util.c    |   26 ++++++++++++++++++++------
 src/xcb_windefs.h |   45 +++++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 150 insertions(+), 15 deletions(-)

New commits:
commit 20da10490f8dac75ec9fe1df28cb9e862e171be5
Merge: 7f5cfcc... 2dcf8b0...
Author: Peter Harris <pharris at opentext.com>
Date:   Tue Aug 31 18:33:36 2010 -0400

    Merge branch 'master' of git://github.com/topcat/xcb-win32
    
    Conflicts:
    	src/xcb_conn.c
    	src/xcb_util.c
    
    Signed-off-by: Peter Harris <pharris at opentext.com>

diff --cc src/xcb_conn.c
index 803f7aa,870c438..ebaa6e2
--- a/src/xcb_conn.c
+++ b/src/xcb_conn.c
@@@ -42,11 -41,12 +41,17 @@@
  #include <sys/select.h>
  #endif
  
+ #ifdef _WIN32
+ #include "xcb_windefs.h"
+ #else
+ #include <netinet/in.h>
+ #endif /* _WIN32 */
+ 
 +/* SHUT_RDWR is fairly recent and is not available on all platforms */
 +#if !defined(SHUT_RDWR)
 +#define SHUT_RDWR 2
 +#endif
 +
  typedef struct {
      uint8_t  status;
      uint8_t  pad0[5];
diff --cc src/xcb_in.c
index 5a87466,e2f9936..57d7e01
--- a/src/xcb_in.c
+++ b/src/xcb_in.c
@@@ -37,10 -37,15 +37,16 @@@
  #include "xcbint.h"
  #if USE_POLL
  #include <poll.h>
- #else
 -#elif !defined _WIN32
++#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
diff --cc src/xcb_util.c
index 5a82ac1,e08a320..0e3728a
--- a/src/xcb_util.c
+++ b/src/xcb_util.c
@@@ -27,11 -27,6 +27,7 @@@
  
  #include <assert.h>
  #include <sys/types.h>
- #include <sys/socket.h>
 +#include <limits.h>
- #include <sys/un.h>
- #include <netinet/in.h>
- #include <netinet/tcp.h>
  #ifdef DNETCONN
  #include <netdnet/dnetdb.h>
  #include <netdnet/dn.h>
@@@ -138,8 -126,10 +143,10 @@@ int xcb_parse_display(const char *name
      return _xcb_parse_display(name, host, NULL, displayp, screenp);
  }
  
 -static int _xcb_open_tcp(char *host, char *protocol, const unsigned short port);
 +static int _xcb_open_tcp(const char *host, char *protocol, const unsigned short port);
+ #ifndef _WIN32
  static int _xcb_open_unix(char *protocol, const char *file);
+ #endif /* !WIN32 */
  #ifdef DNETCONN
  static int _xcb_open_decnet(const char *host, char *protocol, const unsigned short port);
  #endif
@@@ -187,39 -169,21 +194,42 @@@ static int _xcb_open(const char *host, 
                  return _xcb_open_tcp(host, protocol, port);
              }
      }
 +
+ #ifndef _WIN32
 +    filelen = strlen(base) + 1 + sizeof(display) * 3 + 1;
 +    file = malloc(filelen);
 +    if(file == NULL)
 +        return -1;
 +
      /* display specifies Unix socket */
 -    filelen = snprintf(file, sizeof(file), "%s%d", base, display);
 -    if(filelen < 0)
 +#ifdef HAVE_LAUNCHD
 +    if(strncmp(base, "/tmp/launch", 11) == 0)
 +        actual_filelen = snprintf(file, filelen, "%s:%d", base, display);
 +    else
 +#endif
 +        actual_filelen = snprintf(file, filelen, "%s%d", base, display);
 +    if(actual_filelen < 0)
 +    {
 +        free(file);
          return -1;
 +    }
      /* snprintf may truncate the file */
 -    filelen = MIN(filelen, sizeof(file) - 1);
 +    filelen = MIN(actual_filelen, filelen - 1);
  #ifdef HAVE_ABSTRACT_SOCKETS
      fd = _xcb_open_abstract(protocol, file, filelen);
      if (fd >= 0 || (errno != ENOENT && errno != ECONNREFUSED))
 +    {
 +        free(file);
          return fd;
 +    }
 +
  #endif
 -    return  _xcb_open_unix(protocol, file);
 +    fd = _xcb_open_unix(protocol, file);
 +    free(file);
 +
 +    return fd;
+ #endif /* !_WIN32 */
+     return -1; /* if control reaches here then something has gone wrong */
  }
  
  static int _xcb_socket(int family, int type, int proto)
commit 2dcf8b025be88a25d4333abdc28d425b88238d96
Author: Jeetu Golani <jeetu.golani at gmail.com>
Date:   Fri Apr 23 00:47:16 2010 +0530

    Replaced read() in read_block and _xcb_in_read() with recv for all
    platforms. MSG_WAITALL is undefined in MinGW so it's been explicitly
    defined in xcb_in.c

diff --git a/src/xcb_in.c b/src/xcb_in.c
index b481295..e2f9936 100644
--- a/src/xcb_in.c
+++ b/src/xcb_in.c
@@ -39,6 +39,7 @@
 #include <poll.h>
 #elif !defined _WIN32
 #include <sys/select.h>
+#include <sys/socket.h>
 #endif
 
 #ifdef _WIN32
@@ -49,6 +50,11 @@
 #define XCB_REPLY 1
 #define XCB_XGE_EVENT 35
 
+/* 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;
@@ -271,12 +277,7 @@ static int read_block(const int fd, void *buf, const ssize_t len)
     int done = 0;
     while(done < len)
     {
-#ifndef _WIN32
-        int ret = read(fd, ((char *) buf) + done, len - done);
-#else
-        int ret = recv(fd, ((char *) buf) + done, len - done,0);
-#endif /* !_WIN32 */
-
+        int ret = recv(fd, ((char *) buf) + done, len - done,MSG_WAITALL);
         if(ret > 0)
             done += ret;
 #ifndef _WIN32
@@ -681,11 +682,7 @@ void _xcb_in_replies_done(xcb_connection_t *c)
 
 int _xcb_in_read(xcb_connection_t *c)
 {
-#ifndef _WIN32
-    int n = read(c->fd, c->in.queue + c->in.queue_len, sizeof(c->in.queue) - c->in.queue_len);
-#else
-    int n = recv(c->fd, c->in.queue + c->in.queue_len, sizeof(c->in.queue) - c->in.queue_len,0);
-#endif /* !_WIN32 */
+    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))
commit 56962e42a509dc4d0d9541e46b93689dac61c4fd
Author: Jeetu Golani <jeetu.golani at gmail.com>
Date:   Thu Apr 22 23:23:27 2010 +0530

    Set errno=0 in read_block. On Win32 there is no errno and this makes the
    do..while loop execute only once. Also set the return value to -1 in
    _xcb_open if control reaches the end - if all goes well it shouldn't
    reach there.

diff --git a/src/xcb_in.c b/src/xcb_in.c
index 8689344..b481295 100644
--- a/src/xcb_in.c
+++ b/src/xcb_in.c
@@ -297,15 +297,12 @@ static int read_block(const int fd, void *buf, const ssize_t len)
             fd_set fds;
             FD_ZERO(&fds);
             FD_SET(fd, &fds);
-#ifndef _WIN32
+
+	    /* 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);
-#else
-	    /* the do while loop used for the non-windows version isn't required*/
-	    /* for windows since there are no signals in Windows hence no EINTR*/	    
-	    ret = select(fd + 1, &fds, 0, 0, 0);
-#endif /* !_WIN32 */
 #endif /* USE_POLL */
         }
         if(ret <= 0)
diff --git a/src/xcb_util.c b/src/xcb_util.c
index 2be59d2..e08a320 100644
--- a/src/xcb_util.c
+++ b/src/xcb_util.c
@@ -180,10 +180,10 @@ static int _xcb_open(char *host, char *protocol, const int display)
     fd = _xcb_open_abstract(protocol, file, filelen);
     if (fd >= 0 || (errno != ENOENT && errno != ECONNREFUSED))
         return fd;
-
 #endif
     return  _xcb_open_unix(protocol, file);
 #endif /* !_WIN32 */
+    return -1; /* if control reaches here then something has gone wrong */
 }
 
 static int _xcb_socket(int family, int type, int proto)
commit 0e0c80e749eccf121e55c1e855c48d03b54f33ef
Author: Jeetu Golani <jeetu.golani at gmail.com>
Date:   Wed Mar 31 22:00:04 2010 +0530

    xcb_in.c #ifndef _WIN32 inside of #if USE_POLL redundant and removed

diff --git a/src/xcb_in.c b/src/xcb_in.c
index 4191dc3..8689344 100644
--- a/src/xcb_in.c
+++ b/src/xcb_in.c
@@ -286,7 +286,6 @@ static int read_block(const int fd, void *buf, const ssize_t len)
 #endif /* !_Win32 */
         {
 #if USE_POLL
-#ifndef _WIN32
             struct pollfd pfd;
             pfd.fd = fd;
             pfd.events = POLLIN;
@@ -294,7 +293,6 @@ static int read_block(const int fd, void *buf, const ssize_t len)
             do {
                 ret = poll(&pfd, 1, -1);
             } while (ret == -1 && errno == EINTR);
-#endif /* !_WIN32 */
 #else
             fd_set fds;
             FD_ZERO(&fds);
commit e8009194c9f5a6995c4a9b03a7a49d5bc09e96fc
Author: Jeetu Golani <jeetu.golani at gmail.com>
Date:   Wed Mar 31 09:50:51 2010 +0530

    restablished inclusion of fcntl.h and netinet/tcp.h in xcb_util.c -- without these the code no longer compiled on *ix

diff --git a/src/xcb_util.c b/src/xcb_util.c
index 882db52..2be59d2 100644
--- a/src/xcb_util.c
+++ b/src/xcb_util.c
@@ -44,6 +44,8 @@
 #include <sys/socket.h>
 #include <sys/un.h>
 #include <netinet/in.h>
+#include <netinet/tcp.h>
+#include <fcntl.h>
 #include <netdb.h>
 #endif /* _WIN32 */
 
commit d302f1e9b158d0a51936c28e5dc66251d90d1d56
Author: Jeetu Golani <jeetu.golani at gmail.com>
Date:   Mon Mar 29 22:37:33 2010 +0530

    changes in xcb_windefs.h - the flag  _XCB_WINDEFS_H replaces WINDEFS_H

diff --git a/src/xcb_windefs.h b/src/xcb_windefs.h
index a7c0104..d6c7329 100644
--- a/src/xcb_windefs.h
+++ b/src/xcb_windefs.h
@@ -24,8 +24,8 @@
  */
 
 
-#ifndef _WINDEFS_H
-#define _WINDEFS_H
+#ifndef _XCB_WINDEFS_H
+#define _XCB_WINDEFS_H
 
 #ifndef WINVER
 #define WINVER 0x0501 /* required for getaddrinfo/freeaddrinfo defined only for WinXP and above */
@@ -42,4 +42,4 @@ struct iovec  {
 
 typedef unsigned int in_addr_t;
 
-#endif /* windefs.h */
+#endif /* xcb_windefs.h */
commit 36c9a985aaee655c118c9f7b8425d3ac9ce0f840
Author: Jeetu Golani <jeetu.golani at gmail.com>
Date:   Mon Mar 29 22:31:49 2010 +0530

    windefs.h is now called xcb_windefs.h - changed all includes to reflect that.Replaced one instance ofWIN32 with _WIN32 in each xcb_in.c and xcb_conn.c

diff --git a/src/xcb.h b/src/xcb.h
index bd9b635..14244a7 100644
--- a/src/xcb.h
+++ b/src/xcb.h
@@ -38,7 +38,7 @@
 #ifndef _WIN32
 #include <sys/uio.h>
 #else
-#include "windefs.h"
+#include "xcb_windefs.h"
 #endif
 #include <pthread.h>
 
diff --git a/src/xcb_auth.c b/src/xcb_auth.c
index a52f922..8fcfafd 100644
--- a/src/xcb_auth.c
+++ b/src/xcb_auth.c
@@ -32,7 +32,7 @@
 #include <stdlib.h>
 
 #ifdef _WIN32
-#include "windefs.h"
+#include "xcb_windefs.h"
 #else
 #include <sys/socket.h>
 #include <netinet/in.h>
diff --git a/src/xcb_conn.c b/src/xcb_conn.c
index 4a50af3..870c438 100644
--- a/src/xcb_conn.c
+++ b/src/xcb_conn.c
@@ -37,12 +37,12 @@
 #include "xcbint.h"
 #if USE_POLL
 #include <poll.h>
-#elif !defined WIN32
+#elif !defined _WIN32
 #include <sys/select.h>
 #endif
 
 #ifdef _WIN32
-#include "windefs.h"
+#include "xcb_windefs.h"
 #else
 #include <netinet/in.h>
 #endif /* _WIN32 */
@@ -77,7 +77,7 @@ static int set_fd_flags(const int fd)
     if(fcntl(fd, F_SETFD, FD_CLOEXEC) == -1)
         return 0;
     return 1;
-#endif /* WIN32 */
+#endif /* _WIN32 */
 }
 
 static int write_setup(xcb_connection_t *c, xcb_auth_info_t *auth_info)
diff --git a/src/xcb_in.c b/src/xcb_in.c
index 20ff4f2..4191dc3 100644
--- a/src/xcb_in.c
+++ b/src/xcb_in.c
@@ -37,12 +37,12 @@
 #include "xcbint.h"
 #if USE_POLL
 #include <poll.h>
-#elif !defined WIN32
+#elif !defined _WIN32
 #include <sys/select.h>
 #endif
 
 #ifdef _WIN32
-#include "windefs.h"
+#include "xcb_windefs.h"
 #endif /* _WIN32 */
 
 #define XCB_ERROR 0
diff --git a/src/xcb_util.c b/src/xcb_util.c
index 1848abc..882db52 100644
--- a/src/xcb_util.c
+++ b/src/xcb_util.c
@@ -39,7 +39,7 @@
 #include <string.h>
 
 #ifdef _WIN32
-#include "windefs.h"
+#include "xcb_windefs.h"
 #else
 #include <sys/socket.h>
 #include <sys/un.h>
diff --git a/src/xcb_windefs.h b/src/xcb_windefs.h
new file mode 100644
index 0000000..a7c0104
--- /dev/null
+++ b/src/xcb_windefs.h
@@ -0,0 +1,45 @@
+/* Copyright (C) 2009 Jatin Golani.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ * 
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ * 
+ * Except as contained in this notice, the names of the authors or their
+ * institutions shall not be used in advertising or otherwise to promote the
+ * sale, use or other dealings in this Software without prior written
+ * authorization from the authors.
+ */
+
+
+#ifndef _WINDEFS_H
+#define _WINDEFS_H
+
+#ifndef WINVER
+#define WINVER 0x0501 /* required for getaddrinfo/freeaddrinfo defined only for WinXP and above */
+#endif
+
+#include <winsock2.h>
+#include <ws2tcpip.h>
+#include <windef.h>
+
+struct iovec  {
+    void *iov_base;	/* Pointer to data.  */
+    int iov_len;	/* Length of data.  */ 
+};
+
+typedef unsigned int in_addr_t;
+
+#endif /* windefs.h */
commit bce72f63d2dfb61661f81e305ad3a7db0334403c
Author: Jeetu Golani <jeetu.golani at gmail.com>
Date:   Fri Mar 26 09:40:09 2010 +0530

    Win32 code for xcb-1.5

diff --git a/src/xcb.h b/src/xcb.h
index 35d8768..bd9b635 100644
--- a/src/xcb.h
+++ b/src/xcb.h
@@ -35,7 +35,11 @@
 #include <stdint.h>
 #endif
 
+#ifndef _WIN32
 #include <sys/uio.h>
+#else
+#include "windefs.h"
+#endif
 #include <pthread.h>
 
 
diff --git a/src/xcb_auth.c b/src/xcb_auth.c
index 104f2f0..a52f922 100644
--- a/src/xcb_auth.c
+++ b/src/xcb_auth.c
@@ -27,13 +27,18 @@
 
 #include <assert.h>
 #include <X11/Xauth.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <sys/un.h>
 #include <sys/param.h>
 #include <unistd.h>
 #include <stdlib.h>
 
+#ifdef _WIN32
+#include "windefs.h"
+#else
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <sys/un.h>
+#endif /* _WIN32 */
+
 #include "xcb.h"
 #include "xcbint.h"
 
diff --git a/src/xcb_conn.c b/src/xcb_conn.c
index ed2153d..4a50af3 100644
--- a/src/xcb_conn.c
+++ b/src/xcb_conn.c
@@ -30,7 +30,6 @@
 #include <stdio.h>
 #include <unistd.h>
 #include <stdlib.h>
-#include <netinet/in.h>
 #include <fcntl.h>
 #include <errno.h>
 
@@ -38,10 +37,16 @@
 #include "xcbint.h"
 #if USE_POLL
 #include <poll.h>
-#else
+#elif !defined WIN32
 #include <sys/select.h>
 #endif
 
+#ifdef _WIN32
+#include "windefs.h"
+#else
+#include <netinet/in.h>
+#endif /* _WIN32 */
+
 typedef struct {
     uint8_t  status;
     uint8_t  pad0[5];
@@ -52,6 +57,17 @@ static const int error_connection = 1;
 
 static int set_fd_flags(const int fd)
 {
+/* Win32 doesn't have file descriptors and the fcntl function. This block sets the socket in non-blocking mode */
+
+#ifdef _WIN32
+   u_long iMode = 1; /* non-zero puts it in non-blocking mode, 0 in blocking mode */   
+   int ret = 0;
+
+   ret = ioctlsocket(fd, FIONBIO, &iMode);
+   if(ret != 0) 
+       return 0;
+   return 1;
+#else
     int flags = fcntl(fd, F_GETFL, 0);
     if(flags == -1)
         return 0;
@@ -61,6 +77,7 @@ static int set_fd_flags(const int fd)
     if(fcntl(fd, F_SETFD, FD_CLOEXEC) == -1)
         return 0;
     return 1;
+#endif /* WIN32 */
 }
 
 static int write_setup(xcb_connection_t *c, xcb_auth_info_t *auth_info)
@@ -156,9 +173,37 @@ static int write_vec(xcb_connection_t *c, struct iovec **vector, int *count)
 {
     int n;
     assert(!c->out.queue_len);
+
+#ifdef _WIN32
+    int i = 0;
+    int ret = 0,err = 0;
+    struct iovec *vec;
+    n = 0;
+
+    /* Could use the WSASend win32 function for scatter/gather i/o but setting up the WSABUF struct from
+       an iovec would require more work and I'm not sure of the benefit....works for now */
+    vec = *vector;
+    while(i < *count)
+    {         	 
+         ret = send(c->fd,vec->iov_base,vec->iov_len,0);	 
+         if(ret == SOCKET_ERROR)
+         {
+             err  = WSAGetLastError();
+             if(err == WSAEWOULDBLOCK)
+             {
+                 return 1;
+             }
+         }
+         n += ret;
+         *vec++;
+         i++;
+    }
+#else
     n = writev(c->fd, *vector, *count);
     if(n < 0 && errno == EAGAIN)
         return 1;
+#endif /* _WIN32 */    
+
     if(n <= 0)
     {
         _xcb_conn_shutdown(c);
diff --git a/src/xcb_in.c b/src/xcb_in.c
index 80f5523..20ff4f2 100644
--- a/src/xcb_in.c
+++ b/src/xcb_in.c
@@ -37,10 +37,14 @@
 #include "xcbint.h"
 #if USE_POLL
 #include <poll.h>
-#else
+#elif !defined WIN32
 #include <sys/select.h>
 #endif
 
+#ifdef _WIN32
+#include "windefs.h"
+#endif /* _WIN32 */
+
 #define XCB_ERROR 0
 #define XCB_REPLY 1
 #define XCB_XGE_EVENT 35
@@ -267,12 +271,22 @@ static int read_block(const int fd, void *buf, const ssize_t len)
     int done = 0;
     while(done < len)
     {
+#ifndef _WIN32
         int ret = read(fd, ((char *) buf) + done, len - done);
+#else
+        int ret = recv(fd, ((char *) buf) + done, len - done,0);
+#endif /* !_WIN32 */
+
         if(ret > 0)
             done += ret;
+#ifndef _WIN32
         if(ret < 0 && errno == EAGAIN)
+#else
+        if(ret == SOCKET_ERROR && WSAGetLastError() == WSAEWOULDBLOCK)
+#endif /* !_Win32 */
         {
 #if USE_POLL
+#ifndef _WIN32
             struct pollfd pfd;
             pfd.fd = fd;
             pfd.events = POLLIN;
@@ -280,14 +294,21 @@ static int read_block(const int fd, void *buf, const ssize_t len)
             do {
                 ret = poll(&pfd, 1, -1);
             } while (ret == -1 && errno == EINTR);
+#endif /* !_WIN32 */
 #else
             fd_set fds;
             FD_ZERO(&fds);
             FD_SET(fd, &fds);
+#ifndef _WIN32
 	    do {
 		ret = select(fd + 1, &fds, 0, 0, 0);
 	    } while (ret == -1 && errno == EINTR);
-#endif
+#else
+	    /* the do while loop used for the non-windows version isn't required*/
+	    /* for windows since there are no signals in Windows hence no EINTR*/	    
+	    ret = select(fd + 1, &fds, 0, 0, 0);
+#endif /* !_WIN32 */
+#endif /* USE_POLL */
         }
         if(ret <= 0)
             return ret;
@@ -665,12 +686,20 @@ void _xcb_in_replies_done(xcb_connection_t *c)
 
 int _xcb_in_read(xcb_connection_t *c)
 {
+#ifndef _WIN32
     int n = read(c->fd, c->in.queue + c->in.queue_len, sizeof(c->in.queue) - c->in.queue_len);
+#else
+    int n = recv(c->fd, c->in.queue + c->in.queue_len, sizeof(c->in.queue) - c->in.queue_len,0);
+#endif /* !_WIN32 */
     if(n > 0)
         c->in.queue_len += n;
     while(read_packet(c))
         /* empty */;
+#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;
diff --git a/src/xcb_util.c b/src/xcb_util.c
index 996ff25..1848abc 100644
--- a/src/xcb_util.c
+++ b/src/xcb_util.c
@@ -27,23 +27,26 @@
 
 #include <assert.h>
 #include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/un.h>
-#include <netinet/in.h>
-#include <netinet/tcp.h>
 #ifdef DNETCONN
 #include <netdnet/dnetdb.h>
 #include <netdnet/dn.h>
 #endif
-#include <netdb.h>
 #include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <stddef.h>
 #include <unistd.h>
-#include <fcntl.h>
 #include <string.h>
 
+#ifdef _WIN32
+#include "windefs.h"
+#else
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <netinet/in.h>
+#include <netdb.h>
+#endif /* _WIN32 */
+
 #include "xcb.h"
 #include "xcbext.h"
 #include "xcbint.h"
@@ -122,7 +125,9 @@ int xcb_parse_display(const char *name, char **host, int *displayp,
 }
 
 static int _xcb_open_tcp(char *host, char *protocol, const unsigned short port);
+#ifndef _WIN32
 static int _xcb_open_unix(char *protocol, const char *file);
+#endif /* !WIN32 */
 #ifdef DNETCONN
 static int _xcb_open_decnet(const char *host, char *protocol, const unsigned short port);
 #endif
@@ -162,7 +167,7 @@ static int _xcb_open(char *host, char *protocol, const int display)
                 return _xcb_open_tcp(host, protocol, port);
             }
     }
-
+#ifndef _WIN32
     /* display specifies Unix socket */
     filelen = snprintf(file, sizeof(file), "%s%d", base, display);
     if(filelen < 0)
@@ -176,6 +181,7 @@ static int _xcb_open(char *host, char *protocol, const int display)
 
 #endif
     return  _xcb_open_unix(protocol, file);
+#endif /* !_WIN32 */
 }
 
 static int _xcb_socket(int family, int type, int proto)
@@ -188,8 +194,10 @@ static int _xcb_socket(int family, int type, int proto)
 #endif
     {
 	fd = socket(family, type, proto);
+#ifndef _WIN32
 	if (fd >= 0)
 	    fcntl(fd, F_SETFD, FD_CLOEXEC);
+#endif
     }
     return fd;
 }
@@ -289,6 +297,7 @@ static int _xcb_open_tcp(char *host, char *protocol, const unsigned short port)
     return fd;
 }
 
+#ifndef _WIN32
 static int _xcb_open_unix(char *protocol, const char *file)
 {
     int fd;
@@ -311,6 +320,7 @@ static int _xcb_open_unix(char *protocol, const char *file)
     }
     return fd;
 }
+#endif /* !_WIN32 */
 
 #ifdef HAVE_ABSTRACT_SOCKETS
 static int _xcb_open_abstract(char *protocol, const char *file, size_t filelen)


More information about the xcb-commit mailing list