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