Enable poll support on windows

This commit is contained in:
Sergey Lyubka 2022-07-02 11:52:16 +01:00
parent d6e1a3ab4c
commit 91fa2ad23b
2 changed files with 16 additions and 10 deletions

View File

@ -3859,9 +3859,13 @@ struct mg_connection *mg_sntp_connect(struct mg_mgr *mgr, const char *url,
#if MG_ENABLE_SOCKET
#if MG_ARCH == MG_ARCH_WIN32 && MG_ENABLE_WINSOCK
#define MG_SOCK_ERRNO WSAGetLastError()
#if defined(_MSC_VER)
#pragma comment(lib, "ws2_32.lib")
#define alloca(a) _alloca(a)
#endif
#define poll(a, b, c) WSAPoll((a), (b), (c))
#ifndef SO_EXCLUSIVEADDRUSE
#define SO_EXCLUSIVEADDRUSE ((int) (~SO_REUSEADDR))
#pragma comment(lib, "ws2_32.lib")
#endif
#elif MG_ARCH == MG_ARCH_FREERTOS_TCP
#define MG_SOCK_ERRNO errno
@ -4362,11 +4366,10 @@ static void mg_iotest(struct mg_mgr *mgr, int ms) {
eSELECT_READ | eSELECT_EXCEPT | eSELECT_WRITE);
}
#elif MG_ENABLE_POLL
nfds_t n = 0;
size_t n = 0;
for (struct mg_connection *c = mgr->conns; c != NULL; c = c->next) n++;
struct pollfd fds[n == 0 ? 1 : n]; // Avoid zero-length VLA
memset(fds, 0, sizeof(fds));
struct pollfd *fds = (struct pollfd *) alloca(n * sizeof(fds[0]));
if (n > 0) memset(fds, 0, sizeof(n * sizeof(fds[0])));
n = 0;
for (struct mg_connection *c = mgr->conns; c != NULL; c = c->next) {
c->is_readable = c->is_writable = 0;

View File

@ -11,9 +11,13 @@
#if MG_ENABLE_SOCKET
#if MG_ARCH == MG_ARCH_WIN32 && MG_ENABLE_WINSOCK
#define MG_SOCK_ERRNO WSAGetLastError()
#if defined(_MSC_VER)
#pragma comment(lib, "ws2_32.lib")
#define alloca(a) _alloca(a)
#endif
#define poll(a, b, c) WSAPoll((a), (b), (c))
#ifndef SO_EXCLUSIVEADDRUSE
#define SO_EXCLUSIVEADDRUSE ((int) (~SO_REUSEADDR))
#pragma comment(lib, "ws2_32.lib")
#endif
#elif MG_ARCH == MG_ARCH_FREERTOS_TCP
#define MG_SOCK_ERRNO errno
@ -514,11 +518,10 @@ static void mg_iotest(struct mg_mgr *mgr, int ms) {
eSELECT_READ | eSELECT_EXCEPT | eSELECT_WRITE);
}
#elif MG_ENABLE_POLL
nfds_t n = 0;
size_t n = 0;
for (struct mg_connection *c = mgr->conns; c != NULL; c = c->next) n++;
struct pollfd fds[n == 0 ? 1 : n]; // Avoid zero-length VLA
memset(fds, 0, sizeof(fds));
struct pollfd *fds = (struct pollfd *) alloca(n * sizeof(fds[0]));
if (n > 0) memset(fds, 0, sizeof(n * sizeof(fds[0])));
n = 0;
for (struct mg_connection *c = mgr->conns; c != NULL; c = c->next) {
c->is_readable = c->is_writable = 0;