Ensure background tasks are serviced during a lengthy sendall

This commit is contained in:
Jeff Epler 2022-10-19 09:22:32 -05:00
parent 3b7feccd9b
commit de0dda989d
No known key found for this signature in database
GPG Key ID: D5BF15AB975AB4DE

View File

@ -37,6 +37,7 @@
#include "py/mperrno.h" #include "py/mperrno.h"
#include "shared/netutils/netutils.h" #include "shared/netutils/netutils.h"
#include "shared/runtime/interrupt_char.h"
//| class Socket: //| class Socket:
//| """TCP, UDP and RAW socket. Cannot be created directly. Instead, call //| """TCP, UDP and RAW socket. Cannot be created directly. Instead, call
@ -283,6 +284,13 @@ STATIC mp_obj_t _socketpool_socket_sendall(mp_obj_t self_in, mp_obj_t buf_in) {
} }
bufinfo.len -= ret; bufinfo.len -= ret;
bufinfo.buf += ret; bufinfo.buf += ret;
if (bufinfo.len > 0) {
RUN_BACKGROUND_TASKS;
// Allow user to break out of sendall with a KeyboardInterrupt.
if (mp_hal_is_interrupted()) {
return 0;
}
}
} }
return mp_const_none; return mp_const_none;
} }