More SNtp debug 6

This commit is contained in:
Sergey Lyubka committed 2022-05-27 21:59:13 +01:00
1 parent 4aad859e20
commit 9029593691
3 files changed
+31 -32

No files matched your search

+15 -12
View File
@@ -4395,20 +4395,22 @@ 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
size_t i = 0, 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[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++) { n = 0;
for (struct mg_connection *c = mgr->conns; c != NULL; c = c->next) {
if (c->is_closing || c->is_resolving || FD(c) == INVALID_SOCKET) { if (c->is_closing || c->is_resolving || FD(c) == INVALID_SOCKET) {
// Socket not valid, ignore // Socket not valid, ignore
} else { } else {
fds[i].fd = FD(c); fds[n].fd = FD(c);
fds[i].events |= POLLIN; fds[n].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[n].events |= POLLOUT;
} }
n++;
if (mg_tls_pending(c) > 0) ms = 0; // Don't wait if TLS is ready if (mg_tls_pending(c) > 0) ms = 0; // Don't wait if TLS is ready
} }
} }
@@ -4418,17 +4420,18 @@ static void mg_iotest(struct mg_mgr *mgr, int ms) {
if (res < 0) { if (res < 0) {
MG_ERROR(("poll failed, errno: %d", MG_SOCK_ERRNO)); MG_ERROR(("poll failed, errno: %d", MG_SOCK_ERRNO));
} else { } else {
i = 0; n = 0;
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) {
if (c->is_closing || c->is_resolving || FD(c) == INVALID_SOCKET) { if (c->is_closing || c->is_resolving || FD(c) == INVALID_SOCKET) {
// Socket not valid, ignore // Socket not valid, ignore
} else { } else {
c->is_readable = (unsigned) (fds[i].revents & POLLIN ? 1 : 0); c->is_readable = (unsigned) (fds[n].revents & POLLIN ? 1 : 0);
c->is_writable = (unsigned) (fds[i].revents & POLLOUT ? 1 : 0); c->is_writable = (unsigned) (fds[n].revents & POLLOUT ? 1 : 0);
fds[i].revents = 0; fds[n].revents = 0;
if (mg_tls_pending(c) > 0) c->is_readable = 1; if (mg_tls_pending(c) > 0) c->is_readable = 1;
MG_DEBUG((" fd=%d events=%d revents=%d", fds[i].fd, fds[i].events, MG_DEBUG((" fd=%d events=%d revents=%d", fds[n].fd, fds[n].events,
fds[i].revents)); fds[n].revents));
n++;
} }
} }
} }
+15 -12
View File
@@ -476,20 +476,22 @@ 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
size_t i = 0, 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[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++) { n = 0;
for (struct mg_connection *c = mgr->conns; c != NULL; c = c->next) {
if (c->is_closing || c->is_resolving || FD(c) == INVALID_SOCKET) { if (c->is_closing || c->is_resolving || FD(c) == INVALID_SOCKET) {
// Socket not valid, ignore // Socket not valid, ignore
} else { } else {
fds[i].fd = FD(c); fds[n].fd = FD(c);
fds[i].events |= POLLIN; fds[n].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[n].events |= POLLOUT;
} }
n++;
if (mg_tls_pending(c) > 0) ms = 0; // Don't wait if TLS is ready if (mg_tls_pending(c) > 0) ms = 0; // Don't wait if TLS is ready
} }
} }
@@ -499,17 +501,18 @@ static void mg_iotest(struct mg_mgr *mgr, int ms) {
if (res < 0) { if (res < 0) {
MG_ERROR(("poll failed, errno: %d", MG_SOCK_ERRNO)); MG_ERROR(("poll failed, errno: %d", MG_SOCK_ERRNO));
} else { } else {
i = 0; n = 0;
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) {
if (c->is_closing || c->is_resolving || FD(c) == INVALID_SOCKET) { if (c->is_closing || c->is_resolving || FD(c) == INVALID_SOCKET) {
// Socket not valid, ignore // Socket not valid, ignore
} else { } else {
c->is_readable = (unsigned) (fds[i].revents & POLLIN ? 1 : 0); c->is_readable = (unsigned) (fds[n].revents & POLLIN ? 1 : 0);
c->is_writable = (unsigned) (fds[i].revents & POLLOUT ? 1 : 0); c->is_writable = (unsigned) (fds[n].revents & POLLOUT ? 1 : 0);
fds[i].revents = 0; fds[n].revents = 0;
if (mg_tls_pending(c) > 0) c->is_readable = 1; if (mg_tls_pending(c) > 0) c->is_readable = 1;
MG_DEBUG((" fd=%d events=%d revents=%d", fds[i].fd, fds[i].events, MG_DEBUG((" fd=%d events=%d revents=%d", fds[n].fd, fds[n].events,
fds[i].revents)); fds[n].revents));
n++;
} }
} }
} }
+1 -8
View File
@@ -13,12 +13,6 @@ static int s_num_tests = 0;
#define FETCH_BUF_SIZE (256 * 1024) #define FETCH_BUF_SIZE (256 * 1024)
#define POLL_UNTIL(_mgr, _timeout, _condition) \
do { \
uint64_t until = mg_millis() + _timeout; \
while (mg_millis() < until && (_condition)) mg_mgr_poll(_mgr, 5); \
} while (0)
// Important: we use different port numbers for the Windows bug workaround. See // Important: we use different port numbers for the Windows bug workaround. See
// https://support.microsoft.com/en-ae/help/3039044/error-10013-wsaeacces-is-returned-when-a-second-bind-to-a-excluded-por // https://support.microsoft.com/en-ae/help/3039044/error-10013-wsaeacces-is-returned-when-a-second-bind-to-a-excluded-por
@@ -307,7 +301,7 @@ static void test_sntp_server(const char *url) {
c = mg_sntp_connect(&mgr, url, sntp_cb, &ms); c = mg_sntp_connect(&mgr, url, sntp_cb, &ms);
ASSERT(c != NULL); ASSERT(c != NULL);
ASSERT(c->is_udp == 1); ASSERT(c->is_udp == 1);
POLL_UNTIL(&mgr, 3000, ms == 0); for (int i = 0; i < 60 && ms == 0; i++) mg_mgr_poll(&mgr, 50);
MG_DEBUG(("server: %s, ms: %lld", url ? url : "(default)", ms)); MG_DEBUG(("server: %s, ms: %lld", url ? url : "(default)", ms));
ASSERT(ms > 0); ASSERT(ms > 0);
mg_mgr_free(&mgr); mg_mgr_free(&mgr);
@@ -316,7 +310,6 @@ static void test_sntp_server(const char *url) {
static void test_sntp(void) { static void test_sntp(void) {
test_sntp_server("udp://time.windows.com:123"); test_sntp_server("udp://time.windows.com:123");
test_sntp_server(NULL); test_sntp_server(NULL);
exit(0);
{ {
int64_t ms; int64_t ms;