commit fb056573c62c51f99c9e74826ffa3ab804899ccd parent 62c7edc5c098ab36422a42bebb18ec6c897bd9b1 Author: Yersa Nordman <yersa@finwo.nl> Date: Sun, 31 Dec 2023 01:12:49 +0100 Attempt windows compatibility Diffstat:
| M | src/fpoll.h | | | 2 | +- |
| A | src/poll_compat.h | | | 62 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
2 files changed, 63 insertions(+), 1 deletion(-)
diff --git a/src/fpoll.h b/src/fpoll.h @@ -3,7 +3,7 @@ #include <stdbool.h> -#include <poll.h> +#include "poll_compat.h" #ifndef FPOLL_STATUS #define FPOLL_STATUS int diff --git a/src/poll_compat.h b/src/poll_compat.h @@ -0,0 +1,62 @@ +/* + * Public domain + * + * poll(2) emulation for Windows + * + * This emulates just-enough poll functionality on Windows to work in the + * context of this program. This is not a replacement for POSIX.1-2001 poll(2). + * + * Dongsheng Song <dongsheng.song@gmail.com> + * Brent Cook <bcook@openbsd.org> + */ + +#ifndef COMPAT_POLL_H +#define COMPAT_POLL_H + +#ifndef _WIN32 +#include_next <poll.h> +#else + +#include <winsock2.h> + +/* Type used for the number of file descriptors. */ +typedef unsigned long int nfds_t; + +#if !defined(_WIN32_WINNT) || (_WIN32_WINNT < 0x0600) +/* Data structure describing a polling request. */ +struct pollfd { + int fd; /* file descriptor */ + short events; /* requested events */ + short revents; /* returned events */ +}; + +/* Event types that can be polled */ +#define POLLIN 0x001 /* There is data to read. */ +#define POLLPRI 0x002 /* There is urgent data to read. */ +#define POLLOUT 0x004 /* Writing now will not block. */ + +# define POLLRDNORM 0x040 /* Normal data may be read. */ +# define POLLRDBAND 0x080 /* Priority data may be read. */ +# define POLLWRNORM 0x100 /* Writing now will not block. */ +# define POLLWRBAND 0x200 /* Priority data may be written. */ + +/* Event types always implicitly polled. */ +#define POLLERR 0x008 /* Error condition. */ +#define POLLHUP 0x010 /* Hung up. */ +#define POLLNVAL 0x020 /* Invalid polling request. */ + +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +int poll(struct pollfd *pfds, nfds_t nfds, int timeout); + +#ifdef __cplusplus +} +#endif + +#endif /* HAVE_POLL */ + +#endif /* COMPAT_POLL_H */