Orbit Framework
An ultra-modern, asynchronous, cross-platform C++ Web Framework.
Loading...
Searching...
No Matches
PlatformSocket.hpp
Go to the documentation of this file.
1#pragma once
2
3#ifdef _WIN32
4 #ifndef WIN32_LEAN_AND_MEAN
5 #define WIN32_LEAN_AND_MEAN
6 #endif
7 #include <windows.h>
8 #include <winsock2.h>
9 #include <ws2tcpip.h>
10 #undef min
11 #undef max
12#else
13 #include <sys/socket.h>
14 #include <netinet/in.h>
15 #include <netinet/tcp.h>
16 #include <arpa/inet.h>
17 #include <unistd.h>
18 #include <fcntl.h>
19 #include <cerrno>
20 #include <netdb.h>
21#endif
22
23namespace network {
24
25#ifdef _WIN32
26 using socket_t = SOCKET;
27 constexpr socket_t INVALID_SOCKET_FD = INVALID_SOCKET;
28 constexpr int SOCKET_ERROR_VAL = SOCKET_ERROR;
29
30 using socklen_t = int;
31 using ssize_t = intptr_t;
32
33 inline int get_last_socket_error() { return WSAGetLastError(); }
34 inline bool is_would_block_error() { return WSAGetLastError() == WSAEWOULDBLOCK; }
35#else
36 using socket_t = int;
38 constexpr int SOCKET_ERROR_VAL = -1;
39
42
43 inline int get_last_socket_error() { return errno; }
44 inline bool is_would_block_error() { return errno == EWOULDBLOCK || errno == EAGAIN; }
45#endif
46
49 void close_socket(socket_t fd);
51}
Definition ResponseWriter.hpp:7
void cleanup_platform_networking()
Definition PlatformSocket.cpp:21
::socklen_t socklen_t
Definition PlatformSocket.hpp:40
void initialize_platform_networking()
Definition PlatformSocket.cpp:11
constexpr int SOCKET_ERROR_VAL
Definition PlatformSocket.hpp:38
int socket_t
Definition PlatformSocket.hpp:36
bool is_would_block_error()
Definition PlatformSocket.hpp:44
void close_socket(socket_t fd)
Definition PlatformSocket.cpp:27
::ssize_t ssize_t
Definition PlatformSocket.hpp:41
constexpr socket_t INVALID_SOCKET_FD
Definition PlatformSocket.hpp:37
int get_last_socket_error()
Definition PlatformSocket.hpp:43
void set_non_blocking(socket_t fd)
Definition PlatformSocket.cpp:36