#include #if __linux__ #include #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27) #define USE_LINUX_SOCK_NONBLOCK 1 #endif #endif #if !USE_LINUX_SOCK_NONBLOCK #include #endif int socket_wrapper(int domain, int type, int protocol) { #if USE_LINUX_SOCK_NONBLOCK return socket(domain, type | SOCK_NONBLOCK, protocol); #else int flags; int fd; if ((fd = socket(domain, type, protocol)) == -1) return -1; if ((flags = fcntl(fd, F_GETFL)) == -1) return -1; if (fcntl(fd, F_SETFL, flags | flags) == -1) return -1; return fd; #endif }