aboutsummaryrefslogtreecommitdiff
path: root/libxcb/src/xcb_util.c
diff options
context:
space:
mode:
Diffstat (limited to 'libxcb/src/xcb_util.c')
-rw-r--r--libxcb/src/xcb_util.c30
1 files changed, 29 insertions, 1 deletions
diff --git a/libxcb/src/xcb_util.c b/libxcb/src/xcb_util.c
index 9cdfbff3f..af163185a 100644
--- a/libxcb/src/xcb_util.c
+++ b/libxcb/src/xcb_util.c
@@ -49,6 +49,10 @@
#include "xcbext.h"
#include "xcbint.h"
+#ifdef _MSC_VER
+#define close(fd) closesocket(fd)
+#endif
+
static const int error_connection = 1;
int xcb_popcount(uint32_t mask)
@@ -232,8 +236,10 @@ static int _xcb_socket(int family, int type, int proto)
#endif
{
fd = socket(family, type, proto);
+#ifndef _MSC_VER
if (fd >= 0)
fcntl(fd, F_SETFD, FD_CLOEXEC);
+#endif
}
return fd;
}
@@ -278,6 +284,23 @@ static int _xcb_open_decnet(const char *host, const char *protocol, const unsign
}
#endif
+#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;
@@ -317,6 +340,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 */
@@ -326,7 +354,7 @@ static int _xcb_open_tcp(const char *host, char *protocol, const unsigned short
{
fd = _xcb_socket(addr->ai_family, addr->ai_socktype, addr->ai_protocol);
if(fd >= 0) {
- int on = 1;
+ char on = 1;
setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &on, sizeof(on));
setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &on, sizeof(on));