Skip to content

Commit e5b0473

Browse files
committed
extmod/modlwip: Use MICROPY_EVENT_POLL_HOOK for event polling if defined.
Instead of just delaying 100ms if event isn't yet ready. So far applies only to default, "infinite" socket timeout.
1 parent 54fc247 commit e5b0473

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

extmod/modlwip.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,11 @@ typedef struct _lwip_socket_obj_t {
211211
} lwip_socket_obj_t;
212212

213213
static inline void poll_sockets(void) {
214-
// TODO: Allow to override by ports
214+
#ifdef MICROPY_EVENT_POLL_HOOK
215+
MICROPY_EVENT_POLL_HOOK;
216+
#else
215217
mp_hal_delay_ms(1);
218+
#endif
216219
}
217220

218221
/*******************************************************************************/
@@ -348,7 +351,7 @@ STATIC mp_uint_t lwip_udp_receive(lwip_socket_obj_t *socket, byte *buf, mp_uint_
348351
}
349352
} else {
350353
while (socket->incoming.pbuf == NULL) {
351-
mp_hal_delay_ms(100);
354+
poll_sockets();
352355
}
353356
}
354357
}
@@ -605,7 +608,7 @@ STATIC mp_obj_t lwip_socket_accept(mp_obj_t self_in) {
605608
}
606609
} else {
607610
while (socket->incoming.connection == NULL) {
608-
mp_hal_delay_ms(100);
611+
poll_sockets();
609612
}
610613
}
611614
}
@@ -688,7 +691,7 @@ STATIC mp_obj_t lwip_socket_connect(mp_obj_t self_in, mp_obj_t addr_in) {
688691
}
689692
} else {
690693
while (socket->state == STATE_CONNECTING) {
691-
mp_hal_delay_ms(100);
694+
poll_sockets();
692695
}
693696
}
694697
if (socket->state == STATE_CONNECTED) {
@@ -1011,7 +1014,7 @@ STATIC mp_obj_t lwip_getaddrinfo(mp_obj_t host_in, mp_obj_t port_in) {
10111014
}
10121015
case ERR_INPROGRESS: {
10131016
while(!lwip_dns_returned) {
1014-
mp_hal_delay_ms(100);
1017+
poll_sockets();
10151018
}
10161019
if (lwip_dns_returned == 2) {
10171020
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(ENOENT)));

0 commit comments

Comments
 (0)