diff --git a/mip/mip.c b/mip/mip.c index 0954249a..1b0374e7 100644 --- a/mip/mip.c +++ b/mip/mip.c @@ -925,6 +925,10 @@ void mg_mgr_poll(struct mg_mgr *mgr, int ms) { mg_timer_poll(&mgr->timers, now); for (c = mgr->conns; c != NULL; c = tmp) { tmp = c->next; + mg_call(c, MG_EV_POLL, &now); + MG_VERBOSE(("%lu .. %c%c%c%c%c", c->id, c->is_tls ? 'T' : 't', + c->is_connecting ? 'C' : 'c', c->is_tls_hs ? 'H' : 'h', + c->is_resolving ? 'R' : 'r', c->is_closing ? 'C' : 'c')); if (c->is_tls_hs) mg_tls_handshake(c); if (can_write(c)) write_conn(c); if (c->is_draining && c->send.len == 0) c->is_closing = 1; diff --git a/mongoose.c b/mongoose.c index 290174af..e0223e2e 100644 --- a/mongoose.c +++ b/mongoose.c @@ -7451,6 +7451,10 @@ void mg_mgr_poll(struct mg_mgr *mgr, int ms) { mg_timer_poll(&mgr->timers, now); for (c = mgr->conns; c != NULL; c = tmp) { tmp = c->next; + mg_call(c, MG_EV_POLL, &now); + MG_VERBOSE(("%lu .. %c%c%c%c%c", c->id, c->is_tls ? 'T' : 't', + c->is_connecting ? 'C' : 'c', c->is_tls_hs ? 'H' : 'h', + c->is_resolving ? 'R' : 'r', c->is_closing ? 'C' : 'c')); if (c->is_tls_hs) mg_tls_handshake(c); if (can_write(c)) write_conn(c); if (c->is_draining && c->send.len == 0) c->is_closing = 1; diff --git a/test/driver_mock.c b/test/driver_mock.c index eb3bcdf9..88a54d7a 100644 --- a/test/driver_mock.c +++ b/test/driver_mock.c @@ -10,7 +10,7 @@ static size_t mock_tx(const void *buf, size_t len, void *data) { static size_t mock_rx(void *buf, size_t len, void *data) { (void) buf, (void) len, (void) data; - return len; + return 0; } static bool mock_up(void *data) { diff --git a/test/mip_test.c b/test/mip_test.c index 2f03f5cd..9be1581c 100644 --- a/test/mip_test.c +++ b/test/mip_test.c @@ -4,6 +4,7 @@ #define MG_ENABLE_PACKED_FS 0 #include +#include #include #include #include @@ -259,10 +260,31 @@ static void test_http_fetch(void) { close(fd); } +static void ph(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { + if (ev == MG_EV_POLL) ++(*(int *) fn_data); + (void) c, (void) ev_data; +} + +static void test_poll(void) { + int count = 0, i; + struct mg_mgr mgr; + mg_mgr_init(&mgr); + struct mip_if mif; + memset(&mif, 0, sizeof(mif)); + mif.driver = &mip_driver_mock; + mip_init(&mgr, &mif); + mg_http_listen(&mgr, "http://127.0.0.1:12346", ph, &count); + for (i = 0; i < 10; i++) mg_mgr_poll(&mgr, 0); + ASSERT(count == 10); + mip_free(&mif); + mg_mgr_free(&mgr); +} + int main(void) { test_queue(); test_statechange(); test_http_fetch(); + test_poll(); printf("SUCCESS. Total tests: %d\n", s_num_tests); return 0; } diff --git a/test/unit_test.c b/test/unit_test.c index 3806d772..7c1ad85f 100644 --- a/test/unit_test.c +++ b/test/unit_test.c @@ -333,7 +333,7 @@ static void test_sntp(void) { ASSERT(mg_sntp_parse(NULL, 0) == -1); // NOTE(cpq): temporarily disabled until Github Actions fix their NTP // port blockage issue, https://github.com/actions/runner-images/issues/5615 - //test_sntp_server("udp://time.apple.com:123"); + // test_sntp_server("udp://time.apple.com:123"); test_sntp_server("udp://time.windows.com:123"); test_sntp_server(NULL); } @@ -2304,7 +2304,7 @@ static void w2(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { } else if (ev == MG_EV_WS_MSG) { struct mg_ws_message *wm = (struct mg_ws_message *) ev_data; MG_INFO(("Got WS, %lu", wm->data.len)); - //mg_hexdump(wm->data.ptr, wm->data.len); + // mg_hexdump(wm->data.ptr, wm->data.len); if (wm->data.len == 9) { ASSERT(mg_strcmp(wm->data, mg_str("hi there!")) == 0); } else if (wm->data.len == 3) { @@ -2625,6 +2625,21 @@ static void test_rpc(void) { ASSERT(head == NULL); } +static void ph(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { + if (ev == MG_EV_POLL) ++(*(int *) fn_data); + (void) c, (void) ev_data; +} + +static void test_poll(void) { + int count = 0, i; + struct mg_mgr mgr; + mg_mgr_init(&mgr); + mg_http_listen(&mgr, "http://127.0.0.1:12346", ph, &count); + for (i = 0; i < 10; i++) mg_mgr_poll(&mgr, 0); + ASSERT(count == 10); + mg_mgr_free(&mgr); +} + int main(void) { const char *debug_level = getenv("V"); if (debug_level == NULL) debug_level = "3"; @@ -2666,6 +2681,7 @@ int main(void) { test_http_range(); test_sntp(); test_mqtt(); + test_poll(); printf("SUCCESS. Total tests: %d\n", s_num_tests); return EXIT_SUCCESS;