OpenTTD Source
12.0-beta2
|
Go to the documentation of this file.
14 #ifndef NETWORK_CORE_OS_ABSTRACTION_H
15 #define NETWORK_CORE_OS_ABSTRACTION_H
47 typedef unsigned long in_addr_t;
50 #if defined(__MINGW32__) && !defined(AI_ADDRCONFIG)
51 # define AI_ADDRCONFIG 0x00000400
54 #if !(defined(__MINGW32__) || defined(__CYGWIN__))
56 typedef SSIZE_T ssize_t;
57 typedef int socklen_t;
58 # define IPPROTO_IPV6 41
63 #if defined(UNIX) && !defined(__OS2__)
64 # if defined(OPENBSD) || defined(__NetBSD__)
65 # define AI_ADDRCONFIG 0
68 # define INVALID_SOCKET -1
69 # define closesocket close
75 # include <sys/ioctl.h>
76 # include <sys/socket.h>
77 # include <netinet/in.h>
78 # include <netinet/tcp.h>
79 # include <arpa/inet.h>
82 # if !defined(__sgi__) && !defined(SUNOS) && !defined(__INNOTEK_LIBC__) \
83 && !(defined(__GLIBC__) && (__GLIBC__ <= 2) && (__GLIBC_MINOR__ <= 2)) && !defined(__dietlibc__) && !defined(HPUX)
88 # define HAVE_GETIFADDRS
90 # if !defined(INADDR_NONE)
91 # define INADDR_NONE 0xffffffff
94 # if defined(__GLIBC__) && (__GLIBC__ <= 2) && (__GLIBC_MINOR__ <= 1)
95 typedef uint32_t in_addr_t;
99 # include <sys/time.h>
102 # if defined(__EMSCRIPTEN__)
104 # undef AI_ADDRCONFIG
105 # define AI_ADDRCONFIG 0
109 # define FD_SETSIZE 64
113 # if defined(__HAIKU__)
115 # define FD_SETSIZE 512
123 # define INVALID_SOCKET -1
124 # define closesocket close
129 # include <sys/ioctl.h>
130 # include <sys/socket.h>
131 # include <netinet/in.h>
132 # include <netinet/tcp.h>
133 # include <arpa/inet.h>
136 # include <sys/time.h>
139 # define INADDR_NONE 0xffffffff
140 # include "../../3rdparty/os2/getaddrinfo.h"
141 # include "../../3rdparty/os2/getnameinfo.h"
143 #define IPV6_V6ONLY 27
150 uint8_t __u6_addr8[16];
151 uint16_t __u6_addr16[8];
152 uint32_t __u6_addr32[4];
156 #define s6_addr __u6_addr.__u6_addr8
158 struct sockaddr_in6 {
160 sa_family_t sin6_family;
162 uint32_t sin6_flowinfo;
163 struct in6_addr sin6_addr;
164 uint32_t sin6_scope_id;
167 typedef int socklen_t;
168 #if !defined(__INNOTEK_LIBC__)
169 typedef unsigned long in_addr_t;
174 #ifdef __EMSCRIPTEN__
186 static inline socklen_t FixAddrLenForEmscripten(
struct sockaddr_storage &address)
188 switch (address.ss_family) {
189 case AF_INET6:
return sizeof(
struct sockaddr_in6);
190 case AF_INET:
return sizeof(
struct sockaddr_in);
191 default: NOT_REACHED();
203 static_assert(
sizeof(in_addr) == 4);
204 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 SetReusePort(SOCKET d)
Try to set the socket to reuse ports.
bool IsConnectionReset() const
Check whether this error describes a connection reset.
const std::string & AsString() const
Get the string representation of the error message.
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.