mirror of
https://github.com/cesanta/mongoose.git
synced 2026-11-10 16:31:44 +00:00
Enable poll support on windows
This commit is contained in:
1 parent
d6e1a3ab4c
commit
91fa2ad23b
2 files changed
+16
-10
No files matched your search
+8
-5
@@ -3859,9 +3859,13 @@ struct mg_connection *mg_sntp_connect(struct mg_mgr *mgr, const char *url,
|
|||||||
#if MG_ENABLE_SOCKET
|
#if MG_ENABLE_SOCKET
|
||||||
#if MG_ARCH == MG_ARCH_WIN32 && MG_ENABLE_WINSOCK
|
#if MG_ARCH == MG_ARCH_WIN32 && MG_ENABLE_WINSOCK
|
||||||
#define MG_SOCK_ERRNO WSAGetLastError()
|
#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
|
#ifndef SO_EXCLUSIVEADDRUSE
|
||||||
#define SO_EXCLUSIVEADDRUSE ((int) (~SO_REUSEADDR))
|
#define SO_EXCLUSIVEADDRUSE ((int) (~SO_REUSEADDR))
|
||||||
#pragma comment(lib, "ws2_32.lib")
|
|
||||||
#endif
|
#endif
|
||||||
#elif MG_ARCH == MG_ARCH_FREERTOS_TCP
|
#elif MG_ARCH == MG_ARCH_FREERTOS_TCP
|
||||||
#define MG_SOCK_ERRNO errno
|
#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);
|
eSELECT_READ | eSELECT_EXCEPT | eSELECT_WRITE);
|
||||||
}
|
}
|
||||||
#elif MG_ENABLE_POLL
|
#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++;
|
for (struct mg_connection *c = mgr->conns; c != NULL; c = c->next) n++;
|
||||||
struct pollfd fds[n == 0 ? 1 : n]; // Avoid zero-length VLA
|
struct pollfd *fds = (struct pollfd *) alloca(n * sizeof(fds[0]));
|
||||||
|
if (n > 0) memset(fds, 0, sizeof(n * sizeof(fds[0])));
|
||||||
memset(fds, 0, sizeof(fds));
|
|
||||||
n = 0;
|
n = 0;
|
||||||
for (struct mg_connection *c = mgr->conns; c != NULL; c = c->next) {
|
for (struct mg_connection *c = mgr->conns; c != NULL; c = c->next) {
|
||||||
c->is_readable = c->is_writable = 0;
|
c->is_readable = c->is_writable = 0;
|
||||||
|
|||||||
+8
-5
@@ -11,9 +11,13 @@
|
|||||||
#if MG_ENABLE_SOCKET
|
#if MG_ENABLE_SOCKET
|
||||||
#if MG_ARCH == MG_ARCH_WIN32 && MG_ENABLE_WINSOCK
|
#if MG_ARCH == MG_ARCH_WIN32 && MG_ENABLE_WINSOCK
|
||||||
#define MG_SOCK_ERRNO WSAGetLastError()
|
#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
|
#ifndef SO_EXCLUSIVEADDRUSE
|
||||||
#define SO_EXCLUSIVEADDRUSE ((int) (~SO_REUSEADDR))
|
#define SO_EXCLUSIVEADDRUSE ((int) (~SO_REUSEADDR))
|
||||||
#pragma comment(lib, "ws2_32.lib")
|
|
||||||
#endif
|
#endif
|
||||||
#elif MG_ARCH == MG_ARCH_FREERTOS_TCP
|
#elif MG_ARCH == MG_ARCH_FREERTOS_TCP
|
||||||
#define MG_SOCK_ERRNO errno
|
#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);
|
eSELECT_READ | eSELECT_EXCEPT | eSELECT_WRITE);
|
||||||
}
|
}
|
||||||
#elif MG_ENABLE_POLL
|
#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++;
|
for (struct mg_connection *c = mgr->conns; c != NULL; c = c->next) n++;
|
||||||
struct pollfd fds[n == 0 ? 1 : n]; // Avoid zero-length VLA
|
struct pollfd *fds = (struct pollfd *) alloca(n * sizeof(fds[0]));
|
||||||
|
if (n > 0) memset(fds, 0, sizeof(n * sizeof(fds[0])));
|
||||||
memset(fds, 0, sizeof(fds));
|
|
||||||
n = 0;
|
n = 0;
|
||||||
for (struct mg_connection *c = mgr->conns; c != NULL; c = c->next) {
|
for (struct mg_connection *c = mgr->conns; c != NULL; c = c->next) {
|
||||||
c->is_readable = c->is_writable = 0;
|
c->is_readable = c->is_writable = 0;
|
||||||
|
|||||||
Reference in new issue
Block a user