#include "matador/net/os.hpp" #ifdef _WIN32 #include #else #include #include #endif namespace matador { namespace net { void init() { #ifdef _WIN32 WSADATA wsaData; // if this doesn't work if (WSAStartup(MAKEWORD(1,1), &wsaData) != 0) { fprintf(stderr, "WSAStartup failed.\n"); exit(1); } #endif } void cleanup() { #ifdef _WIN32 WSACleanup(); #endif } } bool is_valid_socket(socket_type fd) { #ifdef _WIN32 return fd != INVALID_SOCKET; #else return fd >= 0; #endif } namespace os { int inet_pton(int af, const char *src, void *dst) { #ifdef _WIN32 return ::InetPton(af, src, dst); #else return ::inet_pton(af, src, dst); #endif } const char* inet_ntop(int af, const void* src, char* dst, size_t size) { #ifdef _WIN32 return ::InetNtop(af, const_cast(src), dst, size); #else return ::inet_ntop(af, src, dst, size); #endif } int close(socket_type fd) { #ifdef _WIN32 return ::closesocket(fd); #else return ::close(fd); #endif } int shutdown(socket_type fd, shutdown_type type) { #ifdef _WIN32 return ::shutdown(fd, static_cast(type)); #else return ::shutdown(fd, static_cast(type)); #endif } } }