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