stdex
Additional custom or not Standard C++ covered algorithms
Loading...
Searching...
No Matches
socket.hpp
1/*
2 SPDX-License-Identifier: MIT
3 Copyright © 2023-2024 Amebis
4*/
5
6#pragma once
7
8#include "compat.hpp"
9#if defined(_WIN32)
10#include "windows.h"
11#include <WinSock2.h>
12#else
13#include <sys/socket.h>
14#include <unistd.h>
15#endif
16
17namespace stdex
18{
19#ifdef _WIN32
20 using socket_t = SOCKET;
21 constexpr socket_t invalid_socket = INVALID_SOCKET;
22 inline int closesocket(_In_ socket_t socket) { return ::closesocket(socket); }
23#else
24 using socket_t = int;
25 constexpr socket_t invalid_socket = ((socket_t)-1);
26 inline int closesocket(_In_ socket_t socket) { return ::close(socket); }
27#endif
28}