diff --git a/mongoose.c b/mongoose.c index 6e41a8c0..55d7badd 100644 --- a/mongoose.c +++ b/mongoose.c @@ -12008,7 +12008,7 @@ static void mg_tcpip_poll(struct mg_tcpip_if *ifp, uint64_t now) { if (expired_1000ms) { // ifp->state rules over state6 mg_ip_link(ifp, drv_up, l2_up); // Handle IPv4 mg_ip6_link(ifp, drv_up, l2_up); // Handle IPv6 - if (ifp->state < MG_TCPIP_STATE_UP) MG_ERROR(("Network is down")); + if (ifp->state < MG_TCPIP_STATE_UP) MG_ERROR(("Network is down, state %hhu", ifp->state)); mg_tcpip_call(ifp, MG_TCPIP_EV_TIMER_1S, NULL); } } @@ -12254,8 +12254,10 @@ static void write_conn(struct mg_connection *c) { } static bool can_write(struct mg_connection *c) { - return c->is_connecting == 0 && c->is_resolving == 0 && c->send.len > 0 && - c->is_tls_hs == 0 && c->is_arplooking == 0; + struct mg_tcpip_if *ifp = c->mgr->ifp; + bool ready = (ifp->ip != 0 && ifp->state == MG_TCPIP_STATE_READY); + return ready && c->is_connecting == 0 && c->is_resolving == 0 && + c->send.len > 0 && c->is_tls_hs == 0 && c->is_arplooking == 0; } void mg_mgr_poll(struct mg_mgr *mgr, int ms) { diff --git a/src/net_builtin.c b/src/net_builtin.c index 9db296be..c142cdf7 100644 --- a/src/net_builtin.c +++ b/src/net_builtin.c @@ -2200,7 +2200,7 @@ static void mg_tcpip_poll(struct mg_tcpip_if *ifp, uint64_t now) { if (expired_1000ms) { // ifp->state rules over state6 mg_ip_link(ifp, drv_up, l2_up); // Handle IPv4 mg_ip6_link(ifp, drv_up, l2_up); // Handle IPv6 - if (ifp->state < MG_TCPIP_STATE_UP) MG_ERROR(("Network is down")); + if (ifp->state < MG_TCPIP_STATE_UP) MG_ERROR(("Network is down, state %hhu", ifp->state)); mg_tcpip_call(ifp, MG_TCPIP_EV_TIMER_1S, NULL); } } @@ -2446,8 +2446,10 @@ static void write_conn(struct mg_connection *c) { } static bool can_write(struct mg_connection *c) { - return c->is_connecting == 0 && c->is_resolving == 0 && c->send.len > 0 && - c->is_tls_hs == 0 && c->is_arplooking == 0; + struct mg_tcpip_if *ifp = c->mgr->ifp; + bool ready = (ifp->ip != 0 && ifp->state == MG_TCPIP_STATE_READY); + return ready && c->is_connecting == 0 && c->is_resolving == 0 && + c->send.len > 0 && c->is_tls_hs == 0 && c->is_arplooking == 0; } void mg_mgr_poll(struct mg_mgr *mgr, int ms) { diff --git a/test/mip_test.c b/test/mip_test.c index 59d4346b..17cbb9c3 100644 --- a/test/mip_test.c +++ b/test/mip_test.c @@ -1280,6 +1280,8 @@ static void test_frag_send_path(void) { mif.driver = &driver; mif.driver_data = &s_driver_data; mg_tcpip_init(&mgr, &mif); + mif.ip = mg_htonl(0xa00001); + mif.state = MG_TCPIP_STATE_READY; // so can_write() lets the data out mif.mtu = 500; // force ad hoc small MTU to fragment IP mg_http_listen(&mgr, "http://0.0.0.0:80", frag_send_fn, NULL); mgr.conns->pfn = NULL;