Skip to content

Commit

Permalink
feat: add timeout to wait event
Browse files Browse the repository at this point in the history
  • Loading branch information
jean-roland committed Mar 4, 2025
1 parent 8098fba commit 415ea04
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 8 deletions.
5 changes: 4 additions & 1 deletion src/system/arduino/esp32/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ z_result_t _z_socket_wait_event(void *ctx) {
curr = _z_transport_unicast_peer_list_tail(curr);
}
// Wait for events
int result = select(max_fd + 1, &read_fds, NULL, NULL, NULL);
struct timeval timeout;
timeout.tv_sec = Z_CONFIG_SOCKET_TIMEOUT / 1000;
timeout.tv_usec = (Z_CONFIG_SOCKET_TIMEOUT % 1000) * 1000;
int result = select(max_fd + 1, &read_fds, NULL, NULL, &timeout);
if (result <= 0) {
return _Z_ERR_GENERIC;
}
Expand Down
5 changes: 4 additions & 1 deletion src/system/espidf/network.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ z_result_t _z_socket_wait_event(void *ctx) {
curr = _z_transport_unicast_peer_list_tail(curr);
}
// Wait for events
int result = select(max_fd + 1, &read_fds, NULL, NULL, NULL);
struct timeval timeout;
timeout.tv_sec = Z_CONFIG_SOCKET_TIMEOUT / 1000;
timeout.tv_usec = (Z_CONFIG_SOCKET_TIMEOUT % 1000) * 1000;
int result = select(max_fd + 1, &read_fds, NULL, NULL, &timeout);
if (result <= 0) {
return _Z_ERR_GENERIC;
}
Expand Down
5 changes: 4 additions & 1 deletion src/system/rpi_pico/network.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ z_result_t _z_socket_wait_event(void *ctx) {
curr = _z_transport_unicast_peer_list_tail(curr);
}
// Wait for events
if (lwip_select(max_fd + 1, &read_fds, NULL, NULL, NULL) <= 0) {
struct timeval timeout;
timeout.tv_sec = Z_CONFIG_SOCKET_TIMEOUT / 1000;
timeout.tv_usec = (Z_CONFIG_SOCKET_TIMEOUT % 1000) * 1000;
if (lwip_select(max_fd + 1, &read_fds, NULL, NULL, &timeout) <= 0) {
return _Z_ERR_GENERIC; // Error or no data ready
}
// Mark sockets that are pending
Expand Down
9 changes: 6 additions & 3 deletions src/system/unix/network.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,10 @@ z_result_t _z_socket_wait_event(void *ctx) {
curr = _z_transport_unicast_peer_list_tail(curr);
}
// Wait for events
// FIXME: Need highest file descriptor
int result = select(max_fd + 1, &read_fds, NULL, NULL, NULL);
struct timeval timeout;
timeout.tv_sec = Z_CONFIG_SOCKET_TIMEOUT / 1000;
timeout.tv_usec = (Z_CONFIG_SOCKET_TIMEOUT % 1000) * 1000;
int result = select(max_fd + 1, &read_fds, NULL, NULL, &timeout);
if (result <= 0) {
_Z_ERROR("Errno: %d\n", errno);
return _Z_ERR_GENERIC;
Expand Down Expand Up @@ -238,7 +240,8 @@ void _z_close_tcp(_z_sys_net_socket_t *sock) {
size_t _z_read_tcp(const _z_sys_net_socket_t sock, uint8_t *ptr, size_t len) {
ssize_t rb = recv(sock._fd, ptr, len, 0);
if (rb < (ssize_t)0) {
_Z_ERROR("Errno: %d\n", errno);
// Errno can be -11(EAGAIN) because of SO_RCVTIMEO
_Z_INFO("Errno: %d\n", errno);
return SIZE_MAX;
}

Expand Down
5 changes: 4 additions & 1 deletion src/system/windows/network.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ z_result_t _z_socket_wait_event(void *ctx) {
curr = _z_transport_unicast_peer_list_tail(curr);
}
// Wait for events
int result = select(0, &read_fds, NULL, NULL, NULL);
struct timeval timeout;
timeout.tv_sec = Z_CONFIG_SOCKET_TIMEOUT / 1000;
timeout.tv_usec = (Z_CONFIG_SOCKET_TIMEOUT % 1000) * 1000;
int result = select(0, &read_fds, NULL, NULL, &timeout);
if (result <= 0) {
return _Z_ERR_GENERIC;
}
Expand Down
5 changes: 4 additions & 1 deletion src/system/zephyr/network.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ z_result_t _z_socket_wait_event(void *ctx) {
curr = _z_transport_unicast_peer_list_tail(curr);
}
// Wait for events
int result = select(max_fd + 1, &read_fds, NULL, NULL, NULL);
struct timeval timeout;
timeout.tv_sec = Z_CONFIG_SOCKET_TIMEOUT / 1000;
timeout.tv_usec = (Z_CONFIG_SOCKET_TIMEOUT % 1000) * 1000;
int result = select(max_fd + 1, &read_fds, NULL, NULL, &timeout);
if (result <= 0) {
return _Z_ERR_GENERIC;
}
Expand Down

0 comments on commit 415ea04

Please sign in to comment.