mirror of
https://github.com/cesanta/mongoose.git
synced 2025-08-05 21:18:32 +08:00
Enable poll support on windows
This commit is contained in:
parent
d6e1a3ab4c
commit
91fa2ad23b
13
mongoose.c
13
mongoose.c
@ -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;
|
||||
|
13
src/sock.c
13
src/sock.c
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user