Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

be more careful when setting socket to non-blocking #7679

Merged
merged 1 commit into from
Mar 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions ports/espressif/common-hal/socketpool/Socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,7 @@ int socketpool_socket_accept(socketpool_socket_obj_t *self, uint8_t *ip, uint32_
uint64_t start_ticks = supervisor_ticks_ms64();

// Allow timeouts and interrupts
while (newsoc == -1 &&
!timed_out &&
!mp_hal_is_interrupted()) {
while (newsoc == -1 && !timed_out) {
if (self->timeout_ms != (uint)-1 && self->timeout_ms != 0) {
timed_out = supervisor_ticks_ms64() - start_ticks >= self->timeout_ms;
}
Expand All @@ -267,9 +265,6 @@ int socketpool_socket_accept(socketpool_socket_obj_t *self, uint8_t *ip, uint32_
}
}

// New client socket will not be non-blocking by default, so make it non-blocking.
lwip_fcntl(newsoc, F_SETFL, O_NONBLOCK);

if (!timed_out) {
// harmless on failure but avoiding memcpy is faster
memcpy((void *)ip, (void *)&accept_addr.sin_addr.s_addr, sizeof(accept_addr.sin_addr.s_addr));
Expand All @@ -280,6 +275,10 @@ int socketpool_socket_accept(socketpool_socket_obj_t *self, uint8_t *ip, uint32_
if (newsoc < 0) {
return -MP_EBADF;
}

// We got a socket. New client socket will not be non-blocking by default, so make it non-blocking.
lwip_fcntl(newsoc, F_SETFL, O_NONBLOCK);

if (!register_open_socket(newsoc)) {
lwip_close(newsoc);
return -MP_EBADF;
Expand Down