diff options
author | Christian Hammacher <bmasterc@gmail.com> | 2022-06-15 12:43:44 +0300 |
---|---|---|
committer | David Crocker <dcrocker@eschertech.com> | 2022-06-22 10:51:03 +0300 |
commit | 4d2b41e9ab69ef139a98f422a2357d14e83b4420 (patch) | |
tree | c98f3db984d3d9713b626b1010b7ac9fedeedde8 /src/Networking/LwipEthernet/LwipSocket.cpp | |
parent | 06ea3d1675b7c23740d25ca7788e33e67b090320 (diff) |
Fixed one more bug affecting short data transfers
Fixed bug causing short transfers to be ignored on MB6HC
Diffstat (limited to 'src/Networking/LwipEthernet/LwipSocket.cpp')
-rw-r--r-- | src/Networking/LwipEthernet/LwipSocket.cpp | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/src/Networking/LwipEthernet/LwipSocket.cpp b/src/Networking/LwipEthernet/LwipSocket.cpp index 5390c809..fc015ba2 100644 --- a/src/Networking/LwipEthernet/LwipSocket.cpp +++ b/src/Networking/LwipEthernet/LwipSocket.cpp @@ -332,6 +332,13 @@ void LwipSocket::Taken(size_t len) noexcept // Poll a socket to see if it needs to be serviced void LwipSocket::Poll() noexcept { + // Deal with transfers that went so quickly that we haven't got a responder yet + bool wasShortTransfer = !responderFound && (state == SocketState::clientDisconnecting); + if (wasShortTransfer) + { + state = SocketState::connected; + } + switch (state) { case SocketState::listening: @@ -365,9 +372,11 @@ void LwipSocket::Poll() noexcept case SocketState::clientDisconnecting: case SocketState::closing: + { // The connection is being closed, but we may be waiting for sent data to be ACKed // or for the received data to be processed by a NetworkResponder - if (unAcked == 0 || millis() - whenClosed > MaxAckTime) + bool timeoutExceeded = millis() - whenClosed > MaxAckTime; + if (unAcked == 0 || timeoutExceeded) { if (connectionPcb != nullptr) { @@ -385,14 +394,25 @@ void LwipSocket::Poll() noexcept connectionPcb = nullptr; } - state = (localPort == 0) ? SocketState::disabled : SocketState::listening; + if (receivedData == nullptr || timeoutExceeded) + { + DiscardReceivedData(); + state = (localPort == 0) ? SocketState::disabled : SocketState::listening; + } } break; + } default: // Nothing to do break; } + + // Restore previous disconnecting state if necessary + if (wasShortTransfer) + { + state = SocketState::clientDisconnecting; + } } // Discard any received data for this transaction |