espressif: always make new client sockets be non-blocking
This commit is contained in:
parent
72f4a8ebbc
commit
40534da92a
@ -168,7 +168,9 @@ STATIC void unregister_open_socket(int fd) {
|
|||||||
if (open_socket_fds[i] == fd) {
|
if (open_socket_fds[i] == fd) {
|
||||||
open_socket_fds[i] = -1;
|
open_socket_fds[i] = -1;
|
||||||
user_socket[i] = false;
|
user_socket[i] = false;
|
||||||
write(socket_change_fd, &fd, sizeof(fd));
|
// Write must be 8 bytes for an eventfd.
|
||||||
|
uint64_t signal = 1;
|
||||||
|
write(socket_change_fd, &signal, sizeof(signal));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -251,7 +253,9 @@ int socketpool_socket_accept(socketpool_socket_obj_t *self, uint8_t *ip, uint32_
|
|||||||
uint64_t start_ticks = supervisor_ticks_ms64();
|
uint64_t start_ticks = supervisor_ticks_ms64();
|
||||||
|
|
||||||
// Allow timeouts and interrupts
|
// Allow timeouts and interrupts
|
||||||
while (newsoc == -1 && !timed_out) {
|
while (newsoc == -1 &&
|
||||||
|
!timed_out &&
|
||||||
|
!mp_hal_is_interrupted()) {
|
||||||
if (self->timeout_ms != (uint)-1 && self->timeout_ms != 0) {
|
if (self->timeout_ms != (uint)-1 && self->timeout_ms != 0) {
|
||||||
timed_out = supervisor_ticks_ms64() - start_ticks >= self->timeout_ms;
|
timed_out = supervisor_ticks_ms64() - start_ticks >= self->timeout_ms;
|
||||||
}
|
}
|
||||||
@ -263,6 +267,9 @@ 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) {
|
if (!timed_out) {
|
||||||
// harmless on failure but avoiding memcpy is faster
|
// 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));
|
memcpy((void *)ip, (void *)&accept_addr.sin_addr.s_addr, sizeof(accept_addr.sin_addr.s_addr));
|
||||||
@ -284,11 +291,10 @@ int socketpool_socket_accept(socketpool_socket_obj_t *self, uint8_t *ip, uint32_
|
|||||||
if (!common_hal_socketpool_socket_get_closed(accepted)) {
|
if (!common_hal_socketpool_socket_get_closed(accepted)) {
|
||||||
common_hal_socketpool_socket_close(accepted);
|
common_hal_socketpool_socket_close(accepted);
|
||||||
}
|
}
|
||||||
// Create the socket
|
// Replace the old accepted socket with the new one.
|
||||||
accepted->num = newsoc;
|
accepted->num = newsoc;
|
||||||
accepted->pool = self->pool;
|
accepted->pool = self->pool;
|
||||||
accepted->connected = true;
|
accepted->connected = true;
|
||||||
lwip_fcntl(newsoc, F_SETFL, O_NONBLOCK);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return newsoc;
|
return newsoc;
|
||||||
|
Loading…
Reference in New Issue
Block a user