mirror of
https://github.com/cesanta/mongoose.git
synced 2024-12-28 07:28:13 +08:00
Proper TLS handling for poll(). Make poll() default on linux
This commit is contained in:
parent
252e4715d4
commit
10596a8bdc
27
mongoose.c
27
mongoose.c
@ -4396,7 +4396,7 @@ static void mg_iotest(struct mg_mgr *mgr, int ms) {
|
|||||||
#elif MG_ENABLE_POLL
|
#elif MG_ENABLE_POLL
|
||||||
size_t i = 0, n = 0;
|
size_t i = 0, 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[n == 0 ? 1 : n]; // Avoid zero-length VLA
|
||||||
|
|
||||||
memset(fds, 0, sizeof(fds));
|
memset(fds, 0, sizeof(fds));
|
||||||
for (struct mg_connection *c = mgr->conns; c != NULL; c = c->next, i++) {
|
for (struct mg_connection *c = mgr->conns; c != NULL; c = c->next, i++) {
|
||||||
@ -4406,24 +4406,25 @@ static void mg_iotest(struct mg_mgr *mgr, int ms) {
|
|||||||
fds[i].fd = FD(c);
|
fds[i].fd = FD(c);
|
||||||
fds[i].events |= POLLIN;
|
fds[i].events |= POLLIN;
|
||||||
if (c->is_connecting || (c->send.len > 0 && c->is_tls_hs == 0)) {
|
if (c->is_connecting || (c->send.len > 0 && c->is_tls_hs == 0)) {
|
||||||
fds[i].events |= POLLOUT;
|
fds[i].events |= POLLOUT;
|
||||||
}
|
}
|
||||||
|
if (mg_tls_pending(c) > 0) ms = 0; // Don't wait if TLS is ready
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (poll(fds, n, ms) < 0) {
|
if (poll(fds, n, ms) < 0) {
|
||||||
MG_ERROR(("poll failed, errno: %d", MG_SOCK_ERRNO));
|
MG_ERROR(("poll failed, errno: %d", MG_SOCK_ERRNO));
|
||||||
return;
|
} else {
|
||||||
}
|
i = 0;
|
||||||
|
for (struct mg_connection *c = mgr->conns; c != NULL; c = c->next, i++) {
|
||||||
i = 0;
|
if (c->is_closing || c->is_resolving || FD(c) == INVALID_SOCKET) {
|
||||||
for (struct mg_connection *c = mgr->conns; c != NULL; c = c->next, i++) {
|
// Socket not valid, ignore
|
||||||
if (c->is_closing || c->is_resolving || FD(c) == INVALID_SOCKET) {
|
} else {
|
||||||
// Socket not valid, ignore
|
c->is_readable = (unsigned) (fds[i].revents & POLLIN ? true : false);
|
||||||
} else {
|
c->is_writable = (unsigned) (fds[i].revents & POLLOUT ? true : false);
|
||||||
c->is_readable = (unsigned)(fds[i].revents & POLLIN ? true : false);
|
fds[i].revents = 0;
|
||||||
c->is_writable = (unsigned)(fds[i].revents & POLLOUT ? true : false);
|
if (mg_tls_pending(c) > 0) c->is_readable = 1;
|
||||||
fds[i].revents = 0;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
@ -418,6 +418,10 @@ extern int SockSet(SOCKET hSock, int Type, int Prop, void *pbuf, int size);
|
|||||||
|
|
||||||
#define _DARWIN_UNLIMITED_SELECT 1 // No limit on file descriptors
|
#define _DARWIN_UNLIMITED_SELECT 1 // No limit on file descriptors
|
||||||
|
|
||||||
|
#if !defined(MG_ENABLE_POLL) && defined(__linux__)
|
||||||
|
#define MG_ENABLE_POLL 1
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
@ -436,7 +440,7 @@ extern int SockSet(SOCKET hSock, int Type, int Prop, void *pbuf, int size);
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#if defined(MG_ENABLE_POLL) && MG_ENABLE_POLL
|
#if MG_ENABLE_POLL
|
||||||
#include <poll.h>
|
#include <poll.h>
|
||||||
#else
|
#else
|
||||||
#include <sys/select.h>
|
#include <sys/select.h>
|
||||||
|
@ -4,6 +4,10 @@
|
|||||||
|
|
||||||
#define _DARWIN_UNLIMITED_SELECT 1 // No limit on file descriptors
|
#define _DARWIN_UNLIMITED_SELECT 1 // No limit on file descriptors
|
||||||
|
|
||||||
|
#if !defined(MG_ENABLE_POLL) && defined(__linux__)
|
||||||
|
#define MG_ENABLE_POLL 1
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
@ -22,7 +26,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#if defined(MG_ENABLE_POLL) && MG_ENABLE_POLL
|
#if MG_ENABLE_POLL
|
||||||
#include <poll.h>
|
#include <poll.h>
|
||||||
#else
|
#else
|
||||||
#include <sys/select.h>
|
#include <sys/select.h>
|
||||||
|
27
src/sock.c
27
src/sock.c
@ -478,7 +478,7 @@ static void mg_iotest(struct mg_mgr *mgr, int ms) {
|
|||||||
#elif MG_ENABLE_POLL
|
#elif MG_ENABLE_POLL
|
||||||
size_t i = 0, n = 0;
|
size_t i = 0, 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[n == 0 ? 1 : n]; // Avoid zero-length VLA
|
||||||
|
|
||||||
memset(fds, 0, sizeof(fds));
|
memset(fds, 0, sizeof(fds));
|
||||||
for (struct mg_connection *c = mgr->conns; c != NULL; c = c->next, i++) {
|
for (struct mg_connection *c = mgr->conns; c != NULL; c = c->next, i++) {
|
||||||
@ -488,24 +488,25 @@ static void mg_iotest(struct mg_mgr *mgr, int ms) {
|
|||||||
fds[i].fd = FD(c);
|
fds[i].fd = FD(c);
|
||||||
fds[i].events |= POLLIN;
|
fds[i].events |= POLLIN;
|
||||||
if (c->is_connecting || (c->send.len > 0 && c->is_tls_hs == 0)) {
|
if (c->is_connecting || (c->send.len > 0 && c->is_tls_hs == 0)) {
|
||||||
fds[i].events |= POLLOUT;
|
fds[i].events |= POLLOUT;
|
||||||
}
|
}
|
||||||
|
if (mg_tls_pending(c) > 0) ms = 0; // Don't wait if TLS is ready
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (poll(fds, n, ms) < 0) {
|
if (poll(fds, n, ms) < 0) {
|
||||||
MG_ERROR(("poll failed, errno: %d", MG_SOCK_ERRNO));
|
MG_ERROR(("poll failed, errno: %d", MG_SOCK_ERRNO));
|
||||||
return;
|
} else {
|
||||||
}
|
i = 0;
|
||||||
|
for (struct mg_connection *c = mgr->conns; c != NULL; c = c->next, i++) {
|
||||||
i = 0;
|
if (c->is_closing || c->is_resolving || FD(c) == INVALID_SOCKET) {
|
||||||
for (struct mg_connection *c = mgr->conns; c != NULL; c = c->next, i++) {
|
// Socket not valid, ignore
|
||||||
if (c->is_closing || c->is_resolving || FD(c) == INVALID_SOCKET) {
|
} else {
|
||||||
// Socket not valid, ignore
|
c->is_readable = (unsigned) (fds[i].revents & POLLIN ? true : false);
|
||||||
} else {
|
c->is_writable = (unsigned) (fds[i].revents & POLLOUT ? true : false);
|
||||||
c->is_readable = (unsigned)(fds[i].revents & POLLIN ? true : false);
|
fds[i].revents = 0;
|
||||||
c->is_writable = (unsigned)(fds[i].revents & POLLOUT ? true : false);
|
if (mg_tls_pending(c) > 0) c->is_readable = 1;
|
||||||
fds[i].revents = 0;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
Loading…
x
Reference in New Issue
Block a user