Skip to content

Commit a4eef90

Browse files
iabdalkaderdpgeorge
authored andcommitted
extmod/modusocket: Fix polling of closed sockets.
Unbound sockets in NEW state should return HUP|WR when polled, and return NVAL when in CLOSED state.
1 parent 70bf6ab commit a4eef90

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

extmod/modusocket.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -501,14 +501,19 @@ mp_uint_t socket_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *
501501
if (self->nic != MP_OBJ_NULL) {
502502
self->nic_type->close(self);
503503
self->nic = MP_OBJ_NULL;
504-
self->state = MOD_NETWORK_SS_CLOSED;
505504
}
505+
self->state = MOD_NETWORK_SS_CLOSED;
506506
return 0;
507507
}
508508
if (self->nic == MP_OBJ_NULL) {
509509
if (request == MP_STREAM_POLL) {
510-
// New sockets are writable and not connected.
511-
return MP_STREAM_POLL_HUP | MP_STREAM_POLL_WR;
510+
if (self->state == MOD_NETWORK_SS_NEW) {
511+
// New sockets are writable and not connected.
512+
return MP_STREAM_POLL_HUP | MP_STREAM_POLL_WR;
513+
} else if (self->state == MOD_NETWORK_SS_CLOSED) {
514+
// Closed socket, return invalid.
515+
return MP_STREAM_POLL_NVAL;
516+
}
512517
}
513518
*errcode = MP_EINVAL;
514519
return MP_STREAM_ERROR;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy