Eagerly flush as much data as possible from write queue

This commit implements a policy of writing as many queued buffers as the
writable socket allows, until non-writable, or the write queue is empty.
This has two objectives: 1) any allocated buffers for data copies will
be freed sooner, 2) the write output will be more responsive, fixing at
least one known delay in WiFi scanlist output in YUBOX Now.
This commit is contained in:
Alex Villacís Lasso
2021-08-03 18:16:32 -05:00
parent 01f436bbcb
commit 78953656ef
2 changed files with 86 additions and 42 deletions

View File

@@ -184,6 +184,12 @@ class AsyncClient : public AsyncSocketBase
// If false, app owns the memory and should ensure it remains valid until acked
} queued_writebuf;
// Internal struct used to implement sent buffer notification
typedef struct {
uint32_t length;
uint32_t delay;
} notify_writebuf;
// Queue of buffers to write to socket
SemaphoreHandle_t _write_mutex;
std::deque<queued_writebuf> _writeQueue;
@@ -200,6 +206,8 @@ class AsyncClient : public AsyncSocketBase
void _removeAllCallbacks(void);
bool _flushWriteQueue(void);
void _clearWriteQueue(void);
void _collectNotifyWrittenBuffers(std::deque<notify_writebuf> &, int &);
void _notifyWrittenBuffers(std::deque<notify_writebuf> &, int);
friend void _tcpsock_dns_found(const char * name, struct ip_addr * ipaddr, void * arg);
};