Browse Source

extmod/modlwip: Make socket poll return POLLNVAL in case of bad file.

pull/5254/head
Damien George 5 years ago
parent
commit
feaa251674
  1. 2
      extmod/modlwip.c
  2. 6
      tests/extmod/uselect_poll_basic.py

2
extmod/modlwip.c

@ -1477,6 +1477,8 @@ STATIC mp_uint_t lwip_socket_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_
} 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 == _ERR_BADF) {
ret |= MP_STREAM_POLL_NVAL;
} 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

6
tests/extmod/uselect_poll_basic.py

@ -33,3 +33,9 @@ try:
poller.modify(s, select.POLLIN)
except OSError as e:
assert e.args[0] == errno.ENOENT
# poll after closing the socket, should return POLLNVAL
poller.register(s)
s.close()
p = poller.poll(0)
print(len(p), p[0][-1])

Loading…
Cancel
Save