summaryrefslogtreecommitdiffstatshomepage
path: root/extmod/modlwip.c
diff options
context:
space:
mode:
authorPaul Sokolovsky <pfalcon@users.sourceforge.net>2017-05-01 18:20:09 +0300
committerPaul Sokolovsky <pfalcon@users.sourceforge.net>2017-05-01 18:20:09 +0300
commit5db55e63f3e7a5beda732c241693e37e3a7b099f (patch)
treeba3fe38d0be05ce416650f3d51bbff7bdae526b9 /extmod/modlwip.c
parentc41fe70ef287882467fa0978ca0c678094c0bbec (diff)
downloadmicropython-5db55e63f3e7a5beda732c241693e37e3a7b099f.tar.gz
micropython-5db55e63f3e7a5beda732c241693e37e3a7b099f.zip
extmod/modlwip: ioctl POLL: Fix handling of peer closed socket.
Peer-closed socket is both readable and writable: read will return EOF, write - error. Without this poll will hang on such socket. Note that we don't return POLLHUP, based on argumentation in http://www.greenend.org.uk/rjk/tech/poll.html that it should apply to deeper disconnects, for example for networking, that would be link layer disconnect (e.g. WiFi went down).
Diffstat (limited to 'extmod/modlwip.c')
-rw-r--r--extmod/modlwip.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/extmod/modlwip.c b/extmod/modlwip.c
index 6a1dcaef5a..c72849cf9d 100644
--- a/extmod/modlwip.c
+++ b/extmod/modlwip.c
@@ -1143,8 +1143,11 @@ STATIC mp_uint_t lwip_socket_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_
ret |= MP_STREAM_POLL_WR;
}
- if (flags & MP_STREAM_POLL_HUP && socket->state == STATE_PEER_CLOSED) {
- ret |= MP_STREAM_POLL_HUP;
+ if (socket->state == STATE_PEER_CLOSED) {
+ // Peer-closed socket is both readable and writable: read will
+ // return EOF, write - error. Without this poll will hang on a
+ // socket which was closed by peer.
+ ret |= flags & (MP_STREAM_POLL_RD | MP_STREAM_POLL_WR);
}
} else {