37
37
#include "shared/timeutils/timeutils.h"
38
38
#include "supervisor/fatfs_port.h"
39
39
#include "supervisor/filesystem.h"
40
+ #include "supervisor/port.h"
40
41
#include "supervisor/shared/reload.h"
41
42
#include "supervisor/shared/translate/translate.h"
42
43
#include "supervisor/shared/web_workflow/web_workflow.h"
@@ -323,22 +324,31 @@ void supervisor_start_web_workflow(void) {
323
324
#endif
324
325
}
325
326
326
- static void _send_raw (socketpool_socket_obj_t * socket , const uint8_t * buf , int len ) {
327
+ void web_workflow_send_raw (socketpool_socket_obj_t * socket , const uint8_t * buf , int len ) {
328
+ int total_sent = 0 ;
327
329
int sent = - EAGAIN ;
328
- while (sent == - EAGAIN && common_hal_socketpool_socket_get_connected (socket )) {
329
- sent = socketpool_socket_send (socket , buf , len );
330
+ while ((sent == - EAGAIN || (sent > 0 && total_sent < len )) &&
331
+ common_hal_socketpool_socket_get_connected (socket )) {
332
+ sent = socketpool_socket_send (socket , buf + total_sent , len - total_sent );
333
+ if (sent > 0 ) {
334
+ total_sent += sent ;
335
+ if (total_sent < len ) {
336
+ // Yield so that network code can run.
337
+ port_idle_until_interrupt ();
338
+ }
339
+ }
330
340
}
331
- if (sent < len ) {
341
+ if (total_sent < len ) {
332
342
ESP_LOGE (TAG , "short send %d %d" , sent , len );
333
343
}
334
344
}
335
345
336
346
STATIC void _print_raw (void * env , const char * str , size_t len ) {
337
- _send_raw ((socketpool_socket_obj_t * )env , (const uint8_t * )str , (size_t )len );
347
+ web_workflow_send_raw ((socketpool_socket_obj_t * )env , (const uint8_t * )str , (size_t )len );
338
348
}
339
349
340
350
static void _send_str (socketpool_socket_obj_t * socket , const char * str ) {
341
- _send_raw (socket , (const uint8_t * )str , strlen (str ));
351
+ web_workflow_send_raw (socket , (const uint8_t * )str , strlen (str ));
342
352
}
343
353
344
354
// The last argument must be NULL! Otherwise, it won't stop.
@@ -357,15 +367,15 @@ static void _send_strs(socketpool_socket_obj_t *socket, ...) {
357
367
static void _send_chunk (socketpool_socket_obj_t * socket , const char * chunk ) {
358
368
mp_print_t _socket_print = {socket , _print_raw };
359
369
mp_printf (& _socket_print , "%X\r\n" , strlen (chunk ));
360
- _send_raw (socket , (const uint8_t * )chunk , strlen (chunk ));
361
- _send_raw (socket , (const uint8_t * )"\r\n" , 2 );
370
+ web_workflow_send_raw (socket , (const uint8_t * )chunk , strlen (chunk ));
371
+ web_workflow_send_raw (socket , (const uint8_t * )"\r\n" , 2 );
362
372
}
363
373
364
374
STATIC void _print_chunk (void * env , const char * str , size_t len ) {
365
375
mp_print_t _socket_print = {env , _print_raw };
366
376
mp_printf (& _socket_print , "%X\r\n" , len );
367
- _send_raw ((socketpool_socket_obj_t * )env , (const uint8_t * )str , len );
368
- _send_raw ((socketpool_socket_obj_t * )env , (const uint8_t * )"\r\n" , 2 );
377
+ web_workflow_send_raw ((socketpool_socket_obj_t * )env , (const uint8_t * )str , len );
378
+ web_workflow_send_raw ((socketpool_socket_obj_t * )env , (const uint8_t * )"\r\n" , 2 );
369
379
}
370
380
371
381
// A bit of a misnomer because it sends all arguments as one chunk.
@@ -938,7 +948,7 @@ static void _reply_static(socketpool_socket_obj_t *socket, _request *request, co
938
948
"Content-Length: " , encoded_len , "\r\n" ,
939
949
"Content-Type: " , content_type , "\r\n" ,
940
950
"\r\n" , NULL );
941
- _send_raw (socket , response , response_len );
951
+ web_workflow_send_raw (socket , response , response_len );
942
952
}
943
953
944
954
#define _REPLY_STATIC (socket , request , filename ) _reply_static(socket, request, filename, filename##_length, filename##_content_type)
0 commit comments