Skip to content
Open
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
6 changes: 5 additions & 1 deletion ports/raspberrypi/common-hal/socketpool/Socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ static mp_obj_t socketpool_ip_addr_and_port_to_tuple(const ip_addr_t *addr, int
// Timeout between closing a TCP socket and doing a tcp_abort on that
// socket, if the connection isn't closed cleanly in that time.
#define MICROPY_PY_LWIP_TCP_CLOSE_TIMEOUT_MS (10000)
// lwIP's tcp_poll interval is measured in slow timer ticks.
#define TCP_CLOSE_POLL_TICKS \
((MICROPY_PY_LWIP_TCP_CLOSE_TIMEOUT_MS + TCP_SLOW_INTERVAL - 1) / TCP_SLOW_INTERVAL)
_Static_assert(TCP_CLOSE_POLL_TICKS <= UINT8_MAX, "TCP close poll interval exceeds lwIP range");

// All socket options should be globally distinct,
// because we ignore option levels for efficiency.
Expand Down Expand Up @@ -950,7 +954,7 @@ void socketpool_socket_close(socketpool_socket_obj_t *socket) {
// Schedule a callback to abort the connection if it's not cleanly closed after
// the given timeout. The callback must be set before calling tcp_close since
// the latter may free the pcb; if it doesn't then the callback will be active.
tcp_poll(socket->pcb.tcp, _lwip_tcp_close_poll, MICROPY_PY_LWIP_TCP_CLOSE_TIMEOUT_MS / 500);
tcp_poll(socket->pcb.tcp, _lwip_tcp_close_poll, TCP_CLOSE_POLL_TICKS);
}
if (tcp_close(socket->pcb.tcp) != ERR_OK) {
DEBUG_printf("lwip_close: had to call tcp_abort()\n");
Expand Down
Loading