GREM 3.12.0
Game/Rendering Engine Modules for C++
Loading...
Searching...
No Matches
platform.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 Ivar Härnqvist
2// SPDX-License-Identifier: MIT
3
4#ifndef GREM_NETWORKING_PLATFORM_HPP
5#define GREM_NETWORKING_PLATFORM_HPP
6
8
9#include <system_error> // std::error_code
10
11#ifdef _WIN32
12
13#define _WINSOCK_DEPRECATED_NO_WARNINGS
14#include <winsock2.h> // IWYU pragma: export // DWORD, AF_INET, AF_INET6, PF_INET, SOCK_DGRAM, SOCK_STREAM, SOCKET, INVALID_SOCKET, INADDR_..., IN6ADDR_..., SOL_SOCKET, SO_REUSEADDR, SOMAXCONN, FD_.., WSADATA, WSAE..., FIONBIO, struct addrinfo, struct sockaddr, struct sockaddr_storage, struct sockaddr_in, struct sockaddr_in6, struct in_addr, struct in6_addr, accept, bind, closesocket, connect, getpeername, getsockname, inet_addr, ioctlsocket, listen, recv, recvfrom, select, send, sendto, setsockopt, socket, WSACleanup, WSAGetLastError, WSAStartup, fd_set, timeval, u_long, SD_RECEIVE, SD_SEND, SD_BOTH
15#include <ws2ipdef.h> // IWYU pragma: export // INET_ADDRSTRLEN, INET6_ADDRSTRLEN
16#include <ws2tcpip.h> // IWYU pragma: export // EAI_..., gai_strerror, freeaddrinfo, getaddrinfo, socklen_t, inet_pton, inet_ntop
17
18#ifndef __MINGW32__
19#pragma comment(lib, "Ws2_32.lib")
20#endif
21
22#else
23
24#include <arpa/inet.h> // IWYU pragma: export // inet_pton, inet_ntop
25#include <fcntl.h> // IWYU pragma: export // fcntl, F_GETFL, F_SETFL, O_NONBLOCK
26#include <netdb.h> // IWYU pragma: export // EAI_..., gai_strerror, struct addrinfo, freeaddrinfo, getaddrinfo
27#include <netinet/in.h> // IWYU pragma: export // INADDR_..., IN6ADDR_..., struct sockaddr_in, struct sockaddr_in6, struct in_addr, struct in6_addr, INET_ADDRSTRLEN, INET6_ADDRSTRLEN
28#include <poll.h> // IWYU pragma: export // POLLIN, POLLOUT, nfds_t, pollfd, poll
29#include <sys/socket.h> // IWYU pragma: export // AF_INET, AF_INET6, PF_INET, SOCK_DGRAM, SOCK_STREAM, SO_REUSEADDR, SOMAXCONN, MSG_NOSIGNAL, socklen_t, struct sockaddr, struct sockaddr_storage, accept, bind, connect, getpeername, getsockname, listen, recv, recvfrom, send, sendto, setsockopt, socket, SHUT_RD, SHUT_WR, SHUT_RDWR
30#include <time.h> // IWYU pragma: export // timeval // NOLINT(modernize-deprecated-headers)
31#include <unistd.h> // IWYU pragma: export // close
32
34inline constexpr int SD_RECEIVE = SHUT_RD;
35inline constexpr int SD_SEND = SHUT_WR;
36inline constexpr int SD_BOTH = SHUT_RDWR;
37
38using SOCKET = int;
39
40inline constexpr int INVALID_SOCKET = -1;
41
42inline int closesocket(SOCKET handle) {
43 return close(handle);
44}
46
47#endif
48
49namespace grem::networking {
50
66GREM_API(networking) void ensurePlatformInitialized(std::error_code& errorCode);
67
68} // namespace grem::networking
69
70#endif
Definition Endpoint.hpp:28
void ensurePlatformInitialized(std::error_code &errorCode)
Initialize the underlying platform of the native socket API if it has not already been initialized.