2019-01-06 05:38:43 +01:00
|
|
|
/*
|
|
|
|
* IXNetSystem.h
|
|
|
|
* Author: Benjamin Sergeant
|
|
|
|
* Copyright (c) 2019 Machine Zone. All rights reserved.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2023-02-25 22:50:35 +01:00
|
|
|
#include <cstdint>
|
|
|
|
|
2019-01-06 05:38:43 +01:00
|
|
|
#ifdef _WIN32
|
2021-03-16 03:58:18 +01:00
|
|
|
|
|
|
|
#ifndef WIN32_LEAN_AND_MEAN
|
|
|
|
#define WIN32_LEAN_AND_MEAN
|
|
|
|
#endif
|
|
|
|
|
2021-12-23 07:48:20 +01:00
|
|
|
#include <ws2tcpip.h>
|
|
|
|
#include <winsock2.h>
|
2019-05-30 17:46:50 +02:00
|
|
|
#include <basetsd.h>
|
|
|
|
#include <io.h>
|
|
|
|
#include <ws2def.h>
|
2022-01-04 21:13:19 +01:00
|
|
|
#include <cerrno>
|
2019-08-20 07:26:25 +02:00
|
|
|
|
2021-05-18 04:04:02 +02:00
|
|
|
#undef EWOULDBLOCK
|
|
|
|
#undef EAGAIN
|
|
|
|
#undef EINPROGRESS
|
|
|
|
#undef EBADF
|
|
|
|
#undef EINVAL
|
|
|
|
|
|
|
|
// map to WSA error codes
|
|
|
|
#define EWOULDBLOCK WSAEWOULDBLOCK
|
|
|
|
#define EAGAIN WSATRY_AGAIN
|
|
|
|
#define EINPROGRESS WSAEINPROGRESS
|
|
|
|
#define EBADF WSAEBADF
|
|
|
|
#define EINVAL WSAEINVAL
|
|
|
|
|
2019-09-08 20:14:49 +02:00
|
|
|
// Define our own poll on Windows, as a wrapper on top of select
|
2019-08-22 19:34:17 +02:00
|
|
|
typedef unsigned long int nfds_t;
|
|
|
|
|
2021-11-17 00:22:51 +01:00
|
|
|
// pollfd is not defined by some versions of mingw64 since _WIN32_WINNT is too low
|
|
|
|
#if _WIN32_WINNT < 0x0600
|
2021-03-16 17:56:08 +01:00
|
|
|
struct pollfd
|
|
|
|
{
|
|
|
|
int fd; /* file descriptor */
|
|
|
|
short events; /* requested events */
|
|
|
|
short revents; /* returned events */
|
2021-03-14 03:49:29 +01:00
|
|
|
};
|
|
|
|
|
2021-03-16 17:56:08 +01:00
|
|
|
#define POLLIN 0x001 /* There is data to read. */
|
|
|
|
#define POLLOUT 0x004 /* Writing now will not block. */
|
|
|
|
#define POLLERR 0x008 /* Error condition. */
|
|
|
|
#define POLLHUP 0x010 /* Hung up. */
|
|
|
|
#define POLLNVAL 0x020 /* Invalid polling request. */
|
2021-03-14 03:49:29 +01:00
|
|
|
#endif
|
|
|
|
|
2019-01-06 05:38:43 +01:00
|
|
|
#else
|
2019-05-30 17:46:50 +02:00
|
|
|
#include <arpa/inet.h>
|
|
|
|
#include <errno.h>
|
2020-05-07 01:26:30 +02:00
|
|
|
#include <fcntl.h>
|
2019-05-30 17:46:50 +02:00
|
|
|
#include <netdb.h>
|
2019-10-10 00:38:40 +02:00
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/ip.h>
|
2019-10-13 22:37:34 +02:00
|
|
|
#include <netinet/tcp.h>
|
2019-08-22 19:34:17 +02:00
|
|
|
#include <poll.h>
|
2019-05-30 17:46:50 +02:00
|
|
|
#include <sys/select.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <unistd.h>
|
2019-01-06 05:38:43 +01:00
|
|
|
#endif
|
2019-04-26 01:26:53 +02:00
|
|
|
|
|
|
|
namespace ix
|
|
|
|
{
|
2020-12-12 20:00:55 +01:00
|
|
|
#ifdef _WIN32
|
|
|
|
typedef SOCKET socket_t;
|
|
|
|
#else
|
|
|
|
typedef int socket_t;
|
|
|
|
#endif
|
|
|
|
|
2019-04-26 01:26:53 +02:00
|
|
|
bool initNetSystem();
|
|
|
|
bool uninitNetSystem();
|
2019-09-08 20:14:49 +02:00
|
|
|
|
2022-01-05 19:21:33 +01:00
|
|
|
int poll(struct pollfd* fds, nfds_t nfds, int timeout, void** event);
|
2021-03-24 04:53:19 +01:00
|
|
|
|
|
|
|
const char* inet_ntop(int af, const void* src, char* dst, socklen_t size);
|
|
|
|
int inet_pton(int af, const char* src, void* dst);
|
2021-10-22 19:23:43 +02:00
|
|
|
|
|
|
|
unsigned short network_to_host_short(unsigned short value);
|
2019-05-30 17:46:50 +02:00
|
|
|
} // namespace ix
|