+#ifdef SOCK_CLOEXEC
+ fd = socket(family, type | SOCK_CLOEXEC, proto);
+ if (fd == -1 && errno == EINVAL)
+#endif
+ {
+ fd = socket(family, type, proto);
+#ifndef _WIN32
+ if (fd >= 0)
+ fcntl(fd, F_SETFD, FD_CLOEXEC);
+#endif
+ }
+ return fd;
+}
+
+
+static int _xcb_do_connect(int fd, const struct sockaddr* addr, int addrlen) {
+ int on = 1;
+
+ if(fd < 0)
+ return -1;
+
+ setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &on, sizeof(on));
+ setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &on, sizeof(on));
+
+ return connect(fd, addr, addrlen);
+}
+
+static int _xcb_open_tcp(const char *host, char *protocol, const unsigned short port)
+{
+ int fd = -1;
+#if HAVE_GETADDRINFO
+ struct addrinfo hints;
+ char service[6]; /* "65535" with the trailing '\0' */
+ struct addrinfo *results, *addr;
+ char *bracket;
+#endif
+
+ if (protocol && strcmp("tcp",protocol) && strcmp("inet",protocol)
+#ifdef AF_INET6
+ && strcmp("inet6",protocol)
+#endif
+ )