Commit a63d4a6c authored by Paul Sokolovsky's avatar Paul Sokolovsky

extmod/modlwip: tcp_recv: Use more regular and responsive poll pattern.

Polling once in 100ms means dismal performance.

TODO: Propagate this pattern to other polling places.
parent 0dce9a21
...@@ -203,6 +203,11 @@ typedef struct _lwip_socket_obj_t { ...@@ -203,6 +203,11 @@ typedef struct _lwip_socket_obj_t {
int8_t connected; int8_t connected;
} lwip_socket_obj_t; } lwip_socket_obj_t;
static inline void poll_sockets(void) {
// TODO: Allow to override by ports
mp_hal_delay_ms(1);
}
/*******************************************************************************/ /*******************************************************************************/
// Callback functions for the lwIP raw API. // Callback functions for the lwIP raw API.
...@@ -378,19 +383,13 @@ STATIC mp_uint_t lwip_tcp_receive(lwip_socket_obj_t *socket, byte *buf, mp_uint_ ...@@ -378,19 +383,13 @@ STATIC mp_uint_t lwip_tcp_receive(lwip_socket_obj_t *socket, byte *buf, mp_uint_
} }
if (socket->incoming.pbuf == NULL) { if (socket->incoming.pbuf == NULL) {
if (socket->timeout != -1) { mp_uint_t start = mp_hal_ticks_ms();
for (mp_uint_t retries = socket->timeout / 100; retries--;) { while (socket->incoming.pbuf == NULL) {
mp_hal_delay_ms(100); if (socket->timeout != -1 && mp_hal_ticks_ms() - start > socket->timeout) {
if (socket->incoming.pbuf != NULL) break;
}
if (socket->incoming.pbuf == NULL) {
*_errno = ETIMEDOUT; *_errno = ETIMEDOUT;
return -1; return -1;
} }
} else { poll_sockets();
while (socket->incoming.pbuf == NULL) {
mp_hal_delay_ms(100);
}
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment