diff options
author | Damien George <damien.p.george@gmail.com> | 2015-12-30 19:03:58 +0000 |
---|---|---|
committer | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2016-03-09 12:29:40 +0700 |
commit | 6d2e9e70b33a2e545bcb888d80117385fcd24ae5 (patch) | |
tree | 9ee1e010c12a130144feb1401f2320a82cffd485 | |
parent | 6185dc5f3d0ebc0047395c76eb968f08aac67fd7 (diff) | |
download | micropython-6d2e9e70b33a2e545bcb888d80117385fcd24ae5.tar.gz micropython-6d2e9e70b33a2e545bcb888d80117385fcd24ae5.zip |
extmod/modlwip: Check for state change during recv busy-wait loop.
For example, the peer may close the connection while recv is waiting for
incoming data.
-rw-r--r-- | extmod/modlwip.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/extmod/modlwip.c b/extmod/modlwip.c index 1f93cde836..05b6208f2a 100644 --- a/extmod/modlwip.c +++ b/extmod/modlwip.c @@ -391,13 +391,19 @@ STATIC mp_uint_t lwip_tcp_receive(lwip_socket_obj_t *socket, byte *buf, mp_uint_ if (socket->incoming.pbuf == NULL) { mp_uint_t start = mp_hal_ticks_ms(); - while (socket->incoming.pbuf == NULL) { + while (socket->state == STATE_CONNECTED && socket->incoming.pbuf == NULL) { if (socket->timeout != -1 && mp_hal_ticks_ms() - start > socket->timeout) { *_errno = ETIMEDOUT; return -1; } poll_sockets(); } + if (socket->state == STATE_PEER_CLOSED) { + return 0; + } else if (socket->state != STATE_CONNECTED) { + *_errno = -socket->state; + return -1; + } } struct pbuf *p = socket->incoming.pbuf; |