Skip to content

Commit

Permalink
extmod/modlwip: In ioctl handle case when socket is in an error state.
Browse files Browse the repository at this point in the history
Using MP_STREAM_POLL_HUP for ERR_RST state follows how *nix handles this
case.
  • Loading branch information
dpgeorge committed May 4, 2018
1 parent 12a3fcc commit 318f874
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion extmod/modlwip.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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) {
Expand Down

0 comments on commit 318f874

Please sign in to comment.