20 #ifndef VISIONTRANSFER_NETWORKING_H 21 #define VISIONTRANSFER_NETWORKING_H 26 #define _WIN32_WINNT 0x501 28 #define _WINSOCK_DEPRECATED_NO_WARNINGS 58 #define EWOULDBLOCK WSAEWOULDBLOCK 59 #define ECONNRESET WSAECONNRESET 60 #define ETIMEDOUT WSAETIMEDOUT 61 #define EPIPE WSAECONNABORTED 62 #define MSG_DONTWAIT 0 63 #define SHUT_WR SD_BOTH 65 inline int close(SOCKET s) {
66 return closesocket(s);
71 #define snprintf _snprintf_s 74 typedef int socklen_t;
76 typedef unsigned long error_int_type;
79 #include <arpa/inet.h> 80 #include <netinet/tcp.h> 81 #include <sys/types.h> 82 #include <sys/socket.h> 83 #include <sys/select.h> 85 #include <netinet/in.h> 96 #define INVALID_SOCKET -1 99 #define WSA_IO_PENDING 0 100 #define WSAECONNRESET 0 102 typedef int error_int_type;
114 static void initNetworking();
115 static addrinfo* resolveAddress(
const char* address,
const char* service);
116 static SOCKET connectTcpSocket(
const addrinfo* address);
117 static void setSocketTimeout(SOCKET socket,
int timeoutMillisec);
118 static void closeSocket(SOCKET& socket);
119 static void setSocketBlocking(SOCKET socket,
bool blocking);
120 static void enableReuseAddress(SOCKET socket,
bool reuse);
121 static void bindSocket(SOCKET socket,
const addrinfo* addressInfo);
122 static SOCKET acceptConnection(SOCKET socket, sockaddr_in& remoteAddress);
123 static error_int_type getErrno();
124 static std::string getErrorString(error_int_type error);
125 static std::string getLastErrorString();
A collection of helper functions for implementing network communication.