Go to the documentation of this file.
14 #ifndef NETWORK_CORE_OS_ABSTRACTION_H
15 #define NETWORK_CORE_OS_ABSTRACTION_H
49 typedef unsigned long in_addr_t;
52 #if defined(__MINGW32__) && !defined(AI_ADDRCONFIG)
53 # define AI_ADDRCONFIG 0x00000400
56 #if !(defined(__MINGW32__) || defined(__CYGWIN__))
58 typedef SSIZE_T ssize_t;
59 typedef int socklen_t;
60 # define IPPROTO_IPV6 41
65 #if defined(UNIX) && !defined(__OS2__)
66 # if defined(OPENBSD) || defined(__NetBSD__)
67 # define AI_ADDRCONFIG 0
70 # define INVALID_SOCKET -1
71 # define closesocket close
77 # include <sys/ioctl.h>
78 # include <sys/socket.h>
79 # include <netinet/in.h>
80 # include <netinet/tcp.h>
81 # include <arpa/inet.h>
84 # if !defined(__sgi__) && !defined(SUNOS) && !defined(__INNOTEK_LIBC__) \
85 && !(defined(__GLIBC__) && (__GLIBC__ <= 2) && (__GLIBC_MINOR__ <= 2)) && !defined(__dietlibc__) && !defined(HPUX)
90 # define HAVE_GETIFADDRS
92 # if !defined(INADDR_NONE)
93 # define INADDR_NONE 0xffffffff
96 # if defined(__GLIBC__) && (__GLIBC__ <= 2) && (__GLIBC_MINOR__ <= 1)
97 typedef uint32_t in_addr_t;
101 # include <sys/time.h>
104 # if defined(__EMSCRIPTEN__)
106 # undef AI_ADDRCONFIG
107 # define AI_ADDRCONFIG 0
111 # define FD_SETSIZE 64
118 # define INVALID_SOCKET -1
119 # define closesocket close
124 # include <sys/ioctl.h>
125 # include <sys/socket.h>
126 # include <netinet/in.h>
127 # include <netinet/tcp.h>
128 # include <arpa/inet.h>
131 # include <sys/time.h>
134 # define INADDR_NONE 0xffffffff
135 # include "../../3rdparty/os2/getaddrinfo.h"
136 # include "../../3rdparty/os2/getnameinfo.h"
138 #define IPV6_V6ONLY 27
145 uint8_t __u6_addr8[16];
146 uint16_t __u6_addr16[8];
147 uint32_t __u6_addr32[4];
151 #define s6_addr __u6_addr.__u6_addr8
153 struct sockaddr_in6 {
155 sa_family_t sin6_family;
157 uint32_t sin6_flowinfo;
158 struct in6_addr sin6_addr;
159 uint32_t sin6_scope_id;
162 typedef int socklen_t;
163 #if !defined(__INNOTEK_LIBC__)
164 typedef unsigned long in_addr_t;
169 #ifdef __EMSCRIPTEN__
181 static inline socklen_t FixAddrLenForEmscripten(
struct sockaddr_storage &address)
183 switch (address.ss_family) {
184 case AF_INET6:
return sizeof(
struct sockaddr_in6);
185 case AF_INET:
return sizeof(
struct sockaddr_in);
186 default: NOT_REACHED();
197 static_assert(
sizeof(in_addr) == 4);
198 static_assert(
sizeof(in6_addr) == 16);
bool HasError() const
Check whether an error was actually set.
std::string message
The string representation of the error (set on first call to AsString).
bool WouldBlock() const
Check whether this error describes that the operation would block.
static NetworkError GetLast()
Get the last network error.
int error
The underlying error number from errno or WSAGetLastError.
bool SetNonBlocking(SOCKET d)
Try to set the socket into non-blocking mode.
bool IsConnectInProgress() const
Check whether this error describes a connect is in progress.
bool IsConnectionReset() const
Check whether this error describes a connection reset.
Abstraction of a network error where all implementation details of the error codes are encapsulated i...
bool SetNoDelay(SOCKET d)
Try to set the socket to not delay sending.
NetworkError GetSocketError(SOCKET d)
Get the error from a socket, if any.
NetworkError(int error)
Construct the network error with the given error code.
const char * AsString() const
Get the string representation of the error message.