aboutsummaryrefslogtreecommitdiff
path: root/extmod/modlwip.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2018-05-04 15:15:04 +1000
committerDamien George <damien.p.george@gmail.com>2018-05-04 15:15:04 +1000
commit318f874cda22567a55bb004434ed0ec891fd7d61 (patch)
tree55ca61e7b3d9fd152e2a5133c5893b9e72446667 /extmod/modlwip.c
parent12a3fccc7e07124afd8634353baa2a2a32a04c8d (diff)
extmod/modlwip: In ioctl handle case when socket is in an error state.
Using MP_STREAM_POLL_HUP for ERR_RST state follows how *nix handles this case.
Diffstat (limited to 'extmod/modlwip.c')
-rw-r--r--extmod/modlwip.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/extmod/modlwip.c b/extmod/modlwip.c
index b23f53961..3aa023707 100644
--- a/extmod/modlwip.c
+++ b/extmod/modlwip.c
@@ -1132,7 +1132,8 @@ STATIC mp_uint_t lwip_socket_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_
ret |= MP_STREAM_POLL_RD;
}
- if (flags & MP_STREAM_POLL_WR && tcp_sndbuf(socket->pcb.tcp) > 0) {
+ // Note: pcb.tcp==NULL if state<0, and in this case we can't call tcp_sndbuf
+ if (flags & MP_STREAM_POLL_WR && socket->pcb.tcp != NULL && tcp_sndbuf(socket->pcb.tcp) > 0) {
ret |= MP_STREAM_POLL_WR;
}
@@ -1141,6 +1142,13 @@ STATIC mp_uint_t lwip_socket_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_
// 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 if (socket->state == ERR_RST) {
+ // Socket was reset by peer, a write will return an error
+ ret |= flags & (MP_STREAM_POLL_WR | MP_STREAM_POLL_HUP);
+ } else if (socket->state < 0) {
+ // Socket in some other error state, use catch-all ERR flag
+ // TODO: may need to set other return flags here
+ ret |= flags & MP_STREAM_POLL_ERR;
}
} else if (request == MP_STREAM_CLOSE) {