19 #ifndef INCLUDE_UTIL_PLATFORM_OS_WINDOWS_BSDSOCKETS_HPP 20 #define INCLUDE_UTIL_PLATFORM_OS_WINDOWS_BSDSOCKETS_HPP 23 #if !defined(WIN16) && !defined(WIN32) && !defined(_WIN64) 43 #if !defined(NDEBUG) && !defined(_DEBUG) 50 #ifndef WSAID_ACCEPTEX 54 (PASCAL FAR * LPFN_ACCEPTEX)(
55 IN SOCKET sListenSocket,
56 IN SOCKET sAcceptSocket,
57 IN PVOID lpOutputBuffer,
58 IN DWORD dwReceiveDataLength,
59 IN DWORD dwLocalAddressLength,
60 IN DWORD dwRemoteAddressLength,
61 OUT LPDWORD lpdwBytesReceived,
62 IN LPOVERLAPPED lpOverlapped
65 #define WSAID_ACCEPTEX \ 66 {0xb5367df1,0xcbac,0x11cf,{0x95,0xca,0x00,0x80,0x5f,0x48,0xa1,0x92}} 68 #endif // ! WSAID_ACCEPTEX 70 #ifndef WSAID_GETACCEPTEXSOCKADDRS 74 (PASCAL FAR * LPFN_GETACCEPTEXSOCKADDRS)(
75 IN PVOID lpOutputBuffer,
76 IN DWORD dwReceiveDataLength,
77 IN DWORD dwLocalAddressLength,
78 IN DWORD dwRemoteAddressLength,
79 OUT
struct sockaddr **LocalSockaddr,
80 OUT LPINT LocalSockaddrLength,
81 OUT
struct sockaddr **RemoteSockaddr,
82 OUT LPINT RemoteSockaddrLength
85 #define WSAID_GETACCEPTEXSOCKADDRS \ 86 {0xb5367df2,0xcbac,0x11cf,{0x95,0xca,0x00,0x80,0x5f,0x48,0xa1,0x92}} 88 #endif // ! WSAID_GETACCEPTEXSOCKADDRS 97 inline std::string GetErrorString(
int err)
99 std::string errorString =
"Error string lookup failed";
102 FORMAT_MESSAGE_ALLOCATE_BUFFER |
103 FORMAT_MESSAGE_FROM_SYSTEM |
104 FORMAT_MESSAGE_IGNORE_INSERTS,
107 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
112 errorString = (
const char *) lpMsgBuf;
113 LocalFree( lpMsgBuf );
118 !errorString.empty() &&
119 errorString.at(errorString.size()-1) <= 13)
121 errorString = errorString.substr(0, errorString.size()-1);
127 inline std::string GetErrorString() {
return GetErrorString( ::GetLastError() ); }
129 namespace BsdSockets {
131 typedef int socklen_t;
133 inline int recv(
int fd,
char *buf,
int len,
int flags)
135 return ::recv(fd, buf, len, flags);
138 inline int send(
int fd,
const char *buf,
int len,
int flags)
140 return ::send(fd, buf, len, flags);
143 inline int sendto(
int fd,
const char *buf,
int len,
int flags,
const sockaddr *to,
int tolen)
145 return ::sendto(fd, buf, len, flags, to, tolen);
148 inline int recvfrom(
int fd,
char *buf,
int len,
int flags, sockaddr *from,
int *fromlen)
150 return ::recvfrom(fd, buf, len, flags, from, fromlen);
153 inline int accept(
int fd, sockaddr *addr,
int *addrlen)
155 return (
int) ::accept(fd, addr, addrlen);
158 inline int connect(
int fd,
const sockaddr *name,
int namelen)
160 return ::connect(fd, name, namelen);
163 inline int select(
int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
struct timeval *timeout)
165 return ::select(nfds, readfds, writefds, exceptfds, const_cast<struct timeval *>(timeout) );
168 inline int closesocket(
int fd)
170 return ::closesocket(fd);
173 inline void setblocking(
int fd,
bool bBlocking)
175 u_long arg = bBlocking ? 0 : 1;
176 ioctlsocket(fd, FIONBIO, &arg);
179 inline int GetLastError()
181 return ::WSAGetLastError();
184 inline void disableBrokenPipeSignals()
188 static const int ERR_EWOULDBLOCK = WSAEWOULDBLOCK;
189 static const int ERR_EINPROGRESS = WSAEINPROGRESS;
190 static const int ERR_ECONNRESET = WSAECONNRESET;
191 static const int ERR_ECONNABORTED = WSAECONNABORTED;
192 static const int ERR_ECONNREFUSED = WSAECONNREFUSED;
193 static const int ERR_EMSGSIZE = WSAEMSGSIZE;
194 static const int ERR_EADDRINUSE = WSAEADDRINUSE;
202 #endif // ! INCLUDE_UTIL_PLATFORM_OS_WINDOWS_BSDSOCKETS_HPP