diff options
Diffstat (limited to 'libxcb/src/xcb_util.c')
-rw-r--r-- | libxcb/src/xcb_util.c | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/libxcb/src/xcb_util.c b/libxcb/src/xcb_util.c index 45f66cbfe..065fe1407 100644 --- a/libxcb/src/xcb_util.c +++ b/libxcb/src/xcb_util.c @@ -57,6 +57,13 @@ # include <sys/stat.h> #endif +#ifdef _MSC_VER +#ifdef close +#undef close +#endif +#define close(fd) closesocket(fd) +#endif + int xcb_popcount(uint32_t mask) { uint32_t y; @@ -265,7 +272,7 @@ static int _xcb_socket(int family, int type, int proto) static int _xcb_do_connect(int fd, const struct sockaddr* addr, int addrlen) { - int on = 1; + char on = 1; if(fd < 0) return -1; @@ -276,6 +283,23 @@ static int _xcb_do_connect(int fd, const struct sockaddr* addr, int addrlen) { return connect(fd, addr, addrlen); } +#ifdef WIN32 +int InitWSA(void) +{ + static WSADATA wsadata; + + if (!wsadata.wVersion) + { + ptw32_processInitialize(); + if (WSAStartup(0x0202, &wsadata)) + return -1; + } + return 0; +} +#else +#define InitWSA() +#endif + static int _xcb_open_tcp(const char *host, char *protocol, const unsigned short port) { int fd = -1; @@ -315,6 +339,11 @@ static int _xcb_open_tcp(const char *host, char *protocol, const unsigned short } #endif +#ifdef WIN32 + if (InitWSA()<0) + return -1; +#endif + snprintf(service, sizeof(service), "%hu", port); if(getaddrinfo(host, service, &hints, &results)) /* FIXME: use gai_strerror, and fill in error connection */ |