openMSX
Socket.hh
Go to the documentation of this file.
1#ifndef SOCKET_HH
2#define SOCKET_HH
3
4#include <cstddef>
5#include <string>
6
7#ifndef _WIN32
8#include <sys/types.h>
9#include <sys/socket.h>
10#include <sys/un.h>
11#include <netinet/in.h>
12#include <fcntl.h>
13#include <unistd.h>
14#else
15#include <winsock2.h>
16#endif
17
18namespace openmsx {
19
20#ifndef _WIN32
21inline constexpr int OPENMSX_INVALID_SOCKET = -1;
22inline constexpr int SOCKET_ERROR = -1;
23using SOCKET = int;
24#else
25// INVALID_SOCKET is #defined as (SOCKET)(~0)
26// but that gives a old-style-cast warning
27static const SOCKET OPENMSX_INVALID_SOCKET = static_cast<SOCKET>(~0);
28#endif
29
30[[nodiscard]] std::string sock_error();
31void sock_startup();
32void sock_cleanup();
33void sock_close(SOCKET sd);
34[[nodiscard]] ptrdiff_t sock_recv(SOCKET sd, char* buf, size_t count);
35[[nodiscard]] ptrdiff_t sock_send(SOCKET sd, const char* buf, size_t count);
36
37} // namespace openmsx
38
39#endif
ALWAYS_INLINE unsigned count(const uint8_t *pIn, const uint8_t *pMatch, const uint8_t *pInLimit)
Definition: lz4.cc:147
This file implemented 3 utility functions:
Definition: Autofire.cc:9
constexpr int OPENMSX_INVALID_SOCKET
Definition: Socket.hh:21
ptrdiff_t sock_send(SOCKET sd, const char *buf, size_t count)
Definition: Socket.cc:85
constexpr int SOCKET_ERROR
Definition: Socket.hh:22
void sock_close(SOCKET sd)
Definition: Socket.cc:52
void sock_startup()
Definition: Socket.cc:27
std::string sock_error()
Definition: Socket.cc:9
int SOCKET
Definition: Socket.hh:23
void sock_cleanup()
Definition: Socket.cc:42
ptrdiff_t sock_recv(SOCKET sd, char *buf, size_t count)
Definition: Socket.cc:62