18 #ifndef INCLUDE_UTIL_PLATFORM_OS_WINDOWS_BSDSOCKETS_HPP 19 #define INCLUDE_UTIL_PLATFORM_OS_WINDOWS_BSDSOCKETS_HPP 22 #if !defined(WIN16) && !defined(WIN32) && !defined(_WIN64) 42 #if !defined(NDEBUG) && !defined(_DEBUG) 49 #ifndef WSAID_ACCEPTEX 53 (PASCAL FAR * LPFN_ACCEPTEX)(
54 IN SOCKET sListenSocket,
55 IN SOCKET sAcceptSocket,
56 IN PVOID lpOutputBuffer,
57 IN DWORD dwReceiveDataLength,
58 IN DWORD dwLocalAddressLength,
59 IN DWORD dwRemoteAddressLength,
60 OUT LPDWORD lpdwBytesReceived,
61 IN LPOVERLAPPED lpOverlapped
64 #define WSAID_ACCEPTEX \ 65 {0xb5367df1,0xcbac,0x11cf,{0x95,0xca,0x00,0x80,0x5f,0x48,0xa1,0x92}} 67 #endif // ! WSAID_ACCEPTEX 69 #ifndef WSAID_GETACCEPTEXSOCKADDRS 73 (PASCAL FAR * LPFN_GETACCEPTEXSOCKADDRS)(
74 IN PVOID lpOutputBuffer,
75 IN DWORD dwReceiveDataLength,
76 IN DWORD dwLocalAddressLength,
77 IN DWORD dwRemoteAddressLength,
78 OUT
struct sockaddr **LocalSockaddr,
79 OUT LPINT LocalSockaddrLength,
80 OUT
struct sockaddr **RemoteSockaddr,
81 OUT LPINT RemoteSockaddrLength
84 #define WSAID_GETACCEPTEXSOCKADDRS \ 85 {0xb5367df2,0xcbac,0x11cf,{0x95,0xca,0x00,0x80,0x5f,0x48,0xa1,0x92}} 87 #endif // ! WSAID_GETACCEPTEXSOCKADDRS 96 inline std::string GetErrorString(
int err)
98 std::string errorString =
"Error string lookup failed";
101 FORMAT_MESSAGE_ALLOCATE_BUFFER |
102 FORMAT_MESSAGE_FROM_SYSTEM |
103 FORMAT_MESSAGE_IGNORE_INSERTS,
106 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
111 errorString = (
const char *) lpMsgBuf;
112 LocalFree( lpMsgBuf );
117 !errorString.empty() &&
118 errorString.at(errorString.size()-1) <= 13)
120 errorString = errorString.substr(0, errorString.size()-1);
126 inline std::string GetErrorString() {
return GetErrorString( ::GetLastError() ); }
128 namespace BsdSockets {
130 typedef int socklen_t;
132 inline int recv(
int fd,
char *buf,
int len,
int flags)
134 return ::recv(fd, buf, len, flags);
137 inline int send(
int fd,
const char *buf,
int len,
int flags)
139 return ::send(fd, buf, len, flags);
142 inline int sendto(
int fd,
const char *buf,
int len,
int flags,
const sockaddr *to,
int tolen)
144 return ::sendto(fd, buf, len, flags, to, tolen);
147 inline int recvfrom(
int fd,
char *buf,
int len,
int flags, sockaddr *from,
int *fromlen)
149 return ::recvfrom(fd, buf, len, flags, from, fromlen);
152 inline int accept(
int fd, sockaddr *addr,
int *addrlen)
154 return (
int) ::accept(fd, addr, addrlen);
157 inline int connect(
int fd,
const sockaddr *name,
int namelen)
159 return ::connect(fd, name, namelen);
162 inline int select(
int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
struct timeval *timeout)
164 return ::select(nfds, readfds, writefds, exceptfds, const_cast<struct timeval *>(timeout) );
167 inline int closesocket(
int fd)
169 return ::closesocket(fd);
172 inline void setblocking(
int fd,
bool bBlocking)
174 u_long arg = bBlocking ? 0 : 1;
175 ioctlsocket(fd, FIONBIO, &arg);
178 inline int GetLastError()
180 return ::WSAGetLastError();
183 inline void disableBrokenPipeSignals()
187 static const int ERR_EWOULDBLOCK = WSAEWOULDBLOCK;
188 static const int ERR_EINPROGRESS = WSAEINPROGRESS;
189 static const int ERR_ECONNRESET = WSAECONNRESET;
190 static const int ERR_ECONNABORTED = WSAECONNABORTED;
191 static const int ERR_ECONNREFUSED = WSAECONNREFUSED;
192 static const int ERR_EMSGSIZE = WSAEMSGSIZE;
193 static const int ERR_EADDRINUSE = WSAEADDRINUSE;
201 #endif // ! INCLUDE_UTIL_PLATFORM_OS_WINDOWS_BSDSOCKETS_HPP