diff options
author | Damien George <damien.p.george@gmail.com> | 2018-05-17 23:17:36 +1000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2018-05-17 23:17:36 +1000 |
commit | 1e2a6a84a263e069d7be5f27d73e7fc124413fa5 (patch) | |
tree | 2eab0c7e849aa5c3dcc5ef14f5893d058a0e7230 /extmod/modlwip.c | |
parent | dd13065843060b8351c80ba62a32a24713fd27b1 (diff) |
extmod/modlwip: Set POLLHUP flag for sockets that are new.
This matches CPython behaviour on Linux: a socket that is new and not
listening or connected is considered "hung up".
Thanks to @rkojedzinszky for the initial patch, PR #3457.
Diffstat (limited to 'extmod/modlwip.c')
-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 19766c0c8..7c0a20a1b 100644 --- a/extmod/modlwip.c +++ b/extmod/modlwip.c @@ -723,6 +723,9 @@ STATIC mp_obj_t lwip_socket_listen(mp_obj_t self_in, mp_obj_t backlog_in) { socket->pcb.tcp = new_pcb; tcp_accept(new_pcb, _lwip_tcp_accept); + // Socket is no longer considered "new" for purposes of polling + socket->state = STATE_CONNECTING; + return mp_const_none; } STATIC MP_DEFINE_CONST_FUN_OBJ_2(lwip_socket_listen_obj, lwip_socket_listen); @@ -1176,7 +1179,10 @@ STATIC mp_uint_t lwip_socket_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_ ret |= MP_STREAM_POLL_WR; } - if (socket->state == STATE_PEER_CLOSED) { + if (socket->state == STATE_NEW) { + // New sockets are not connected so set HUP + ret |= flags & MP_STREAM_POLL_HUP; + } else 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. |