AdsLib
Loading...
Searching...
No Matches
AdsLib
wrap_socket.h
1
// SPDX-License-Identifier: MIT
6
#pragma once
7
8
#include <stdint.h>
9
10
#if !(defined(_WIN32) && !defined(__CYGWIN__))
11
#include <arpa/inet.h>
12
#include <netinet/in.h>
13
#include <netinet/tcp.h>
14
#include <netdb.h>
15
#include <sys/select.h>
16
#include <sys/socket.h>
17
#include <unistd.h>
18
typedef
int
SOCKET;
19
#define INVALID_SOCKET ((int)-1)
20
#define SOCKET_ERROR ((int)-1)
21
#define closesocket(X) ::close(X)
22
#define WSACleanup()
23
#define WSAGetLastError() errno
24
#define WSAENOTSOCK EBADF
25
#define CONNECTION_CLOSED ENOTCONN
26
#define CONNECTION_ABORTED ECONNABORTED
27
inline
int
InitSocketLibrary(
void
)
28
{
29
return
0;
30
}
31
#define NATIVE_SELECT(SOCK, READFDS, WRITEFDS, EXCEPTFDS, TIMEOUT) \
32
::select(SOCK, READFDS, WRITEFDS, EXCEPTFDS, TIMEOUT)
33
#else
// defined(_WIN32) && !defined(__CYGWIN__)
34
#define _WINSOCK_DEPRECATED_NO_WARNINGS 1
35
#include <winsock2.h>
36
#include <ws2tcpip.h>
37
inline
int
InitSocketLibrary(
void
)
38
{
39
WSADATA wsaData;
40
return
WSAStartup(0x0202, &wsaData);
41
}
42
43
#define NATIVE_SELECT(SOCK, READFDS, WRITEFDS, EXCEPTFDS, TIMEOUT) \
44
::select(0, READFDS, WRITEFDS, EXCEPTFDS, TIMEOUT)
45
46
#define s_addr S_un.S_addr
47
typedef
int
socklen_t;
48
#define SHUT_RDWR SD_BOTH
49
#define CONNECTION_CLOSED WSAESHUTDOWN
50
#define CONNECTION_ABORTED WSAECONNABORTED
51
#endif
Generated on Fri Dec 16 2022 11:37:25 for AdsLib by
1.9.5