lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lwip-users] TCP keep-alive not working on half-closed connections


From: R. Diez
Subject: [lwip-users] TCP keep-alive not working on half-closed connections
Date: Wed, 6 Jun 2018 11:42:38 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0

Hi all:

I am using lwIP 2.0.3. I have a raw (embedded software) client that establishes a TCP connection to a server. When the server detects the incoming connection, it automatically sends data, so the client receives data without doing anything else.

Because the client never sends any data, I thought I could shutdown the Tx side of the connection on the client. The idea is that, if the server tries to read any data from the client, it will immediately fail. It is a way to detect programming errors early, because this kind of connections will never deliver any data to the server, so the software on the server should not try to read at all. The same applies to the client: any attempt to send data on this kind of connection would immediately be noticed.

In any case, I thought it was OK to keep using a half-closed TCP connection. In fact, it seems to be working fine (except for the keep-alive problem described below).

So the client calls tcp_connect( ... tcp_connected_fn connected ), and on that 'connected' callback, I am calling tcp_shutdown() like this:

  const int shutdownRx = 0;
  const int shutdownTx = 1;
  tcp_shutdown( m_pcb, shutdownRx, shutdownTx );

The trouble is, this changes the connection state (pcb->state) from ESTABLISHED to FIN_WAIT_1, which then turns quickly into FIN_WAIT_2. Afterwards, TCP keep-alive does not work anymore, because of this logic in tcp_slowtmr():

  /* Check if KEEPALIVE should be sent */
  if (ip_get_option(pcb, SOF_KEEPALIVE) &&
     ((pcb->state == ESTABLISHED) ||
      (pcb->state == CLOSE_WAIT))) {

If I then pull the server's Ethernet cable while the connection is transferring data, the connection never times out on the client.

I am no TCP/IP expert. Is there an error in my reasoning regarding half-closed connections? Can TCP keep-alive packets, whatever they are, still be sent and/or received on half-closed TCP connections?

Please copy me on any answers, as I am not (effectively) subscribed to this list.

Thanks in advance,
  rdiez



reply via email to

[Prev in Thread] Current Thread [Next in Thread]