MLIB
Loading...
Searching...
No Matches
safe_winsock.h
1#pragma once
2
3#if defined(_MSC_VER)
4# ifndef _WINSOCK_DEPRECATED_NO_WARNINGS
5 /* inet_ntoa triggers some deprecation warnings. Disable them for now. */
6# define _WINSOCK_DEPRECATED_NO_WARNINGS
7# endif
8
9# if !defined(_WINSOCK2API_) && defined(_WINSOCKAPI_)
10# error <winsock.h> has been included before <winsock2.h>
11# else
12# ifndef WIN32_LEAN_AND_MEAN
13# define WIN32_LEAN_AND_MEAN
14# define MLIB_MUST_UNDEF_LEAN_AND_MEAN
15# endif
16# include <windows.h>
17# include <WinSock2.h>
18# ifdef MLIB_MUST_UNDEF_LEAN_AND_MEAN
19# undef WIN32_LEAN_AND_MEAN
20# endif
21# endif
22typedef int socklen_t;
23#else
24#include <sys/socket.h>
25#include <sys/ioctl.h>
26#include <netinet/in.h>
27#include <netinet/ip.h>
28#include <arpa/inet.h>
29#include <netinet/tcp.h> /* for TCP_NODELAY */
30#include <fcntl.h> /* for nonblocking */
31#include <netdb.h> // for hostent
32#include <cerrno>
33
34#define ioctlsocket ioctl
35inline int WSAGetLastError () {return errno;}
36
37typedef int SOCKET;
38typedef void* HANDLE;
39typedef struct hostent HOSTENT;
40#define INVALID_HANDLE ((HANDLE)(-1))
41#define INVALID_HANDLE_VALUE ((HANDLE)(std::intptr_t) - 1)
42#define INVALID_SOCKET (-1)
43#define SOCKET_ERROR (-1)
44#define WSAENOTSOCK ENOTSOCK
45#define WSAETIMEDOUT ETIMEDOUT
46#define WSAEINPROGRESS EINPROGRESS
47#define WSAEWOULDBLOCK EWOULDBLOCK
48#define WSAECONNABORTED ECONNABORTED
49#define WSAECONNRESET ECONNRESET
50#define WSAESHUTDOWN ESHUTDOWN
51#define WSAHOST_NOT_FOUND HOST_NOT_FOUND
52#define WSANO_DATA NO_DATA
53#define WSANO_RECOVERY NO_RECOVERY
54#define WSATRY_AGAIN TRY_AGAIN
55#endif