Skip to content
This repository was archived by the owner on Jan 20, 2025. It is now read-only.

Commit 79dafc5

Browse files
committed
Perform acks of any written buffers on poll
When data is enqueued and then sent to the socket with the send() method, buffers are enqueued and then written as much as possible into the socket, but the buffers are not yet acked. Prior to this commit, the only place where written buffers were acked was inside the _sockIsWriteable() method, invoked when the socket becomes writable. However, if the socket remains non-writable, the data queue would fill with written-but-not-acked buffers. This in turn breaks the TX timeout logic and causes the code to never signal a TX timeout to the application. Fixed by adding ack code in the _sockPoll() method so all ack callbacks are made from the "asyncTcpSock" task.
1 parent abb4a8e commit 79dafc5

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

src/AsyncTCP.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -900,6 +900,20 @@ void AsyncClient::_sockPoll(void)
900900
{
901901
if (!connected()) return;
902902

903+
// The AsyncClient::send() call may be invoked from tasks other than "asyncTcpSock"
904+
// and may have written buffers via _flushWriteQueue(), but the ack callbacks have
905+
// not been called yet, nor buffers removed from the write queue. For consistency,
906+
// written buffers are now acked here.
907+
std::deque<notify_writebuf> notifylist;
908+
int sent_errno = 0;
909+
xSemaphoreTake(_write_mutex, (TickType_t)portMAX_DELAY);
910+
if (_writeQueue.size() > 0) {
911+
_collectNotifyWrittenBuffers(notifylist, sent_errno);
912+
}
913+
xSemaphoreGive(_write_mutex);
914+
915+
_notifyWrittenBuffers(notifylist, sent_errno);
916+
903917
uint32_t now = millis();
904918

905919
// ACK Timeout - simulated by write queue staleness

0 commit comments

Comments
 (0)