Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 17 additions & 16 deletions libraries/ESP8266WiFi/src/include/ClientContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -308,39 +308,40 @@ class ClientContext
if (!_pcb)
return true;

int loop = -1;
int prevsndbuf = -1;
max_wait_ms++;

// wait for peer's acks to flush lwIP's output buffer

uint32_t last_sent = millis();
while (1) {
if (millis() - last_sent > (uint32_t) max_wait_ms) {
#ifdef DEBUGV
// wait until sent: timeout
DEBUGV(":wustmo\n");
#endif
// All data was not flushed, timeout hit
return false;
}

// force lwIP to send what can be sent
tcp_output(_pcb);

int sndbuf = tcp_sndbuf(_pcb);
if (sndbuf != prevsndbuf) {
// send buffer has changed (or first iteration)
// we received an ack: restart the loop counter
prevsndbuf = sndbuf;
loop = max_wait_ms;
// We just sent a bit, move timeout forward
last_sent = millis();
}

if (state() != ESTABLISHED || sndbuf == TCP_SND_BUF || --loop <= 0)
break;

delay(1);
}
yield();

#ifdef DEBUGV
if (loop <= 0) {
// wait until sent: timeout
DEBUGV(":wustmo\n");
if ((state() != ESTABLISHED) || (sndbuf == TCP_SND_BUF)) {
break;
}
}
#endif

return max_wait_ms > 0;
// All data flushed
return true;
}

uint8_t state() const
Expand Down