Skip to content

Commit 318f874

Browse files
committed
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.
1 parent 12a3fcc commit 318f874

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

extmod/modlwip.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1132,7 +1132,8 @@ STATIC mp_uint_t lwip_socket_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_
11321132
ret |= MP_STREAM_POLL_RD;
11331133
}
11341134

1135-
if (flags & MP_STREAM_POLL_WR && tcp_sndbuf(socket->pcb.tcp) > 0) {
1135+
// Note: pcb.tcp==NULL if state<0, and in this case we can't call tcp_sndbuf
1136+
if (flags & MP_STREAM_POLL_WR && socket->pcb.tcp != NULL && tcp_sndbuf(socket->pcb.tcp) > 0) {
11361137
ret |= MP_STREAM_POLL_WR;
11371138
}
11381139

@@ -1141,6 +1142,13 @@ STATIC mp_uint_t lwip_socket_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_
11411142
// return EOF, write - error. Without this poll will hang on a
11421143
// socket which was closed by peer.
11431144
ret |= flags & (MP_STREAM_POLL_RD | MP_STREAM_POLL_WR);
1145+
} else if (socket->state == ERR_RST) {
1146+
// Socket was reset by peer, a write will return an error
1147+
ret |= flags & (MP_STREAM_POLL_WR | MP_STREAM_POLL_HUP);
1148+
} else if (socket->state < 0) {
1149+
// Socket in some other error state, use catch-all ERR flag
1150+
// TODO: may need to set other return flags here
1151+
ret |= flags & MP_STREAM_POLL_ERR;
11441152
}
11451153

11461154
} else if (request == MP_STREAM_CLOSE) {

0 commit comments

Comments
 (0)