@@ -168,7 +168,9 @@ STATIC void unregister_open_socket(int fd) {
168
168
if (open_socket_fds [i ] == fd ) {
169
169
open_socket_fds [i ] = -1 ;
170
170
user_socket [i ] = false;
171
- write (socket_change_fd , & fd , sizeof (fd ));
171
+ // Write must be 8 bytes for an eventfd.
172
+ uint64_t signal = 1 ;
173
+ write (socket_change_fd , & signal , sizeof (signal ));
172
174
return ;
173
175
}
174
176
}
@@ -251,7 +253,9 @@ int socketpool_socket_accept(socketpool_socket_obj_t *self, uint8_t *ip, uint32_
251
253
uint64_t start_ticks = supervisor_ticks_ms64 ();
252
254
253
255
// Allow timeouts and interrupts
254
- while (newsoc == -1 && !timed_out ) {
256
+ while (newsoc == -1 &&
257
+ !timed_out &&
258
+ !mp_hal_is_interrupted ()) {
255
259
if (self -> timeout_ms != (uint )- 1 && self -> timeout_ms != 0 ) {
256
260
timed_out = supervisor_ticks_ms64 () - start_ticks >= self -> timeout_ms ;
257
261
}
@@ -263,6 +267,9 @@ int socketpool_socket_accept(socketpool_socket_obj_t *self, uint8_t *ip, uint32_
263
267
}
264
268
}
265
269
270
+ // New client socket will not be non-blocking by default, so make it non-blocking.
271
+ lwip_fcntl (newsoc , F_SETFL , O_NONBLOCK );
272
+
266
273
if (!timed_out ) {
267
274
// harmless on failure but avoiding memcpy is faster
268
275
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_
284
291
if (!common_hal_socketpool_socket_get_closed (accepted )) {
285
292
common_hal_socketpool_socket_close (accepted );
286
293
}
287
- // Create the socket
294
+ // Replace the old accepted socket with the new one.
288
295
accepted -> num = newsoc ;
289
296
accepted -> pool = self -> pool ;
290
297
accepted -> connected = true;
291
- lwip_fcntl (newsoc , F_SETFL , O_NONBLOCK );
292
298
}
293
299
294
300
return newsoc ;
0 commit comments