diff options
Diffstat (limited to 'src/network/core/os_abstraction.h')
-rw-r--r-- | src/network/core/os_abstraction.h | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/src/network/core/os_abstraction.h b/src/network/core/os_abstraction.h index 836cfeae8..a015c4374 100644 --- a/src/network/core/os_abstraction.h +++ b/src/network/core/os_abstraction.h @@ -23,9 +23,17 @@ #include <ws2tcpip.h> #include <windows.h> -#define GET_LAST_ERROR() WSAGetLastError() +/** + * Get the last error code from any of the OS's network functions. + * What it returns and when it is reset, is implementation defined. + * @return The last error code. + */ +#define NetworkGetLastError() WSAGetLastError() #undef EWOULDBLOCK #define EWOULDBLOCK WSAEWOULDBLOCK + +const char *NetworkGetErrorString(int error); + /* Windows has some different names for some types */ typedef unsigned long in_addr_t; @@ -51,7 +59,8 @@ typedef unsigned long in_addr_t; # define INVALID_SOCKET -1 # define ioctlsocket ioctl # define closesocket close -# define GET_LAST_ERROR() (errno) +# define NetworkGetLastError() (errno) +# define NetworkGetErrorString(error) (strerror(error)) /* Need this for FIONREAD on solaris */ # define BSD_COMP @@ -101,7 +110,8 @@ typedef unsigned long in_addr_t; # define INVALID_SOCKET -1 # define ioctlsocket ioctl # define closesocket close -# define GET_LAST_ERROR() (sock_errno()) +# define NetworkGetLastError() (sock_errno()) +# define NetworkGetErrorString(error) (strerror(error)) /* Includes needed for OS/2 systems */ # include <types.h> @@ -174,6 +184,15 @@ static inline socklen_t FixAddrLenForEmscripten(struct sockaddr_storage &address #endif /** + * Return the string representation of the last error from the OS's network functions. + * @return The error message, potentially an empty string but never \c nullptr. + */ +static inline const char *NetworkGetLastErrorString() +{ + return NetworkGetErrorString(NetworkGetLastError()); +} + +/** * Try to set the socket into non-blocking mode. * @param d The socket to set the non-blocking more for. * @return True if setting the non-blocking mode succeeded, otherwise false. |