[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [lwip-users] Disconnect client from LWIP server on various occassion
From: |
Indan Zupancic |
Subject: |
Re: [lwip-users] Disconnect client from LWIP server on various occassions |
Date: |
Thu, 17 Mar 2022 11:25:07 +0100 |
User-agent: |
Roundcube Webmail/1.3.16 |
Hello Paul,
On 2022-03-16 14:43, Matthias Paul wrote:
If the LWIP server sends a long data stream (some megabytes of data)
while receiving the remote disconnect, I'll run into problems because
the server stalls: tcp_sent() is never called afterwards, so the
server cannot push further data to the client .
If the other end closes its TCP connection it just means that it closes
its write end, you can still keep your end open and finish transmission
of outstanding data.
It depends on the protocol whether that makes sense or not. If the
client
fully closed its socket your data will be either silently dropped or you
may receive a TCP reset, depending on the TCP/IP stack used. The
read-side
close of a TCP connection is a TCP/IP stack implementation feature, not
something you see on the wire. That is, you can't know whether the peer
closed its read-side or not, the expected behaviour must be agreed on by
the protocol used.
tcp_sent should be called, it only stops te be called if the connection
is reset or also closed by your side, or if the remote never ACKs your
data. Maybe you should install an error callback with tcp_err() to
detect resets?
Can anyone explain why the connection isn't closed instantly by call
to tcpecho_raw_close()?
That would mean that the client needs to keep its end open till it
received
all data. That implies it can't use closing the socket to indicate end
of
data towards the server. That means the server either has no idea how
much data to expect, or it needs to be told by the protocol on top of
TCP.
If the server doesn't know how much to expect, it doesn't know when to
close
its end of the connection. End result: Connection is never closed.
One end needs to close the TCP connection first and it's better if
that's
the client side (because of FIN_WAIT).
TCP is designed to be able to recover link up/down transitions, so link
down won't immediately close all connections automatically.
Greetings,
Indan