diff options
| author | Paul Sokolovsky | 2015-12-29 20:35:41 +0200 |
|---|---|---|
| committer | Paul Sokolovsky | 2015-12-29 20:37:22 +0200 |
| commit | a63d4a6cc20b6e9b03f1a5fab5a189765b27b749 (patch) | |
| tree | 93deec5a04d6bcadeebc3af92e7c1e0d5748eb43 /extmod/modlwip.c | |
| parent | 0dce9a21ced22ff4f7883177c24bf3358474dc98 (diff) | |
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.
Diffstat (limited to 'extmod/modlwip.c')
| -rw-r--r-- | extmod/modlwip.c | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/extmod/modlwip.c b/extmod/modlwip.c index 274a07daa..afd606729 100644 --- a/extmod/modlwip.c +++ b/extmod/modlwip.c @@ -203,6 +203,11 @@ typedef struct _lwip_socket_obj_t { int8_t connected; } 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. @@ -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->timeout != -1) { - for (mp_uint_t retries = socket->timeout / 100; retries--;) { - mp_hal_delay_ms(100); - if (socket->incoming.pbuf != NULL) break; - } - if (socket->incoming.pbuf == NULL) { + mp_uint_t start = mp_hal_ticks_ms(); + while (socket->incoming.pbuf == NULL) { + if (socket->timeout != -1 && mp_hal_ticks_ms() - start > socket->timeout) { *_errno = ETIMEDOUT; return -1; } - } else { - while (socket->incoming.pbuf == NULL) { - mp_hal_delay_ms(100); - } + poll_sockets(); } } |
