@@ -44,6 +44,7 @@ static const char *TAG = "socket";
44
44
STATIC socketpool_socket_obj_t * open_socket_handles [CONFIG_LWIP_MAX_SOCKETS ];
45
45
46
46
void socket_user_reset (void ) {
47
+ ESP_LOGW (TAG , "Reset sockets" );
47
48
for (size_t i = 0 ; i < MP_ARRAY_SIZE (open_socket_handles ); i ++ ) {
48
49
if (open_socket_handles [i ]) {
49
50
if (open_socket_handles [i ]-> num > 0 ) {
@@ -74,16 +75,14 @@ int socketpool_socket_accept(socketpool_socket_obj_t *self, uint8_t *ip, uint32_
74
75
uint64_t start_ticks = supervisor_ticks_ms64 ();
75
76
76
77
// Allow timeouts and interrupts
77
- while (newsoc == -1 &&
78
- !timed_out &&
79
- !mp_hal_is_interrupted ()) {
78
+ while (newsoc == -1 && !timed_out ) {
80
79
if (self -> timeout_ms != (uint )- 1 && self -> timeout_ms != 0 ) {
81
80
timed_out = supervisor_ticks_ms64 () - start_ticks >= self -> timeout_ms ;
82
81
}
83
82
RUN_BACKGROUND_TASKS ;
84
83
newsoc = lwip_accept (self -> num , (struct sockaddr * )& accept_addr , & socklen );
85
84
// In non-blocking mode, fail instead of timing out
86
- if (newsoc == -1 && self -> timeout_ms == 0 ) {
85
+ if (newsoc == -1 && ( self -> timeout_ms == 0 || mp_hal_is_interrupted ()) ) {
87
86
if (errno != EAGAIN ) {
88
87
ESP_LOGE (TAG , "accept failed %d" , errno );
89
88
}
@@ -283,8 +282,7 @@ int socketpool_socket_recv_into(socketpool_socket_obj_t *self,
283
282
uint64_t start_ticks = supervisor_ticks_ms64 ();
284
283
received = -1 ;
285
284
while (received == -1 &&
286
- !timed_out &&
287
- !mp_hal_is_interrupted ()) {
285
+ !timed_out ) {
288
286
if (self -> timeout_ms != (uint )- 1 && self -> timeout_ms != 0 ) {
289
287
timed_out = supervisor_ticks_ms64 () - start_ticks >= self -> timeout_ms ;
290
288
}
@@ -301,6 +299,14 @@ int socketpool_socket_recv_into(socketpool_socket_obj_t *self,
301
299
}
302
300
return - MP_EAGAIN ;
303
301
}
302
+ // Check this after going through the loop once so it can make
303
+ // progress while interrupted.
304
+ if (mp_hal_is_interrupted ()) {
305
+ if (received == -1 ) {
306
+ return - MP_EAGAIN ;
307
+ }
308
+ break ;
309
+ }
304
310
}
305
311
} else {
306
312
return - MP_EBADF ;
0 commit comments