Re: Sockets in C on Linux

From: Randy Howard (randyhoward_at_FOOverizonBAR.net)
Date: 02/03/05


Date: Thu, 03 Feb 2005 21:07:36 GMT

In article <ggoMd.490243$b5.23126729@news3.tin.it>, do@notwrite.it says...
> Michael Jørgensen wrote:
> > Use the socket options SO_KEEPALIVE and TCP_KEEPALIVE.
>
> First of all, thanks for the answer.
>
> I'm working with a Mandrake Linux Distribution and I wasn't able to use
> the option TCP_KEEPALIVE because it isn't defined were I suppose it
> should be, that is in netinet/tcp.h
>
> Are there other files to look for it ?

TCP_KEEPALIVE is a relatively new POSIX option, which allows the timeout
interval to be set for each connection, but it is not implemented
everywhere. Relying upon it will invoke the evil queen of unportability.
It won't solve your problem anyway, if I understand the original question.

You (at the application level) need to know if the "other end" has gone
away, but for some you reason you don't want to generate any traffic
to find out. You may find that the best way to solve this is to use
a heartbeat mechanism to make sure the connection is good, even during
otherwise idle time (on the wire). The keepalive feature is usually
not useful to applications, the TCP stack sends a message, the peer
responds with an ACK, but, *the app does not get notified that the
exchange took place*. So, it doesn't help you know for sure.

It isn't exactly what you *want*, but it may be what you *need*.

Jon C. Snader has a very thorough coverage of this common (but rarely
understood) problem in his excellent book, "Effective TCP/IP
Programming", Addison-Wesley, 2000. If you really want to understand
TCP, I highly recommend you buy a copy and read it front to back.

Of course, any of the Stevens books are excellent as well, but for
"get the biggest improvement in the shortest time" approach, I
think Snader's book is very good, plus it has a lot of working
examples.

-- 
Randy Howard (2reply remove FOOBAR)
"Making it hard to do stupid things often makes it hard
 to do smart ones too." -- Andrew Koenig


Relevant Pages

  • Re: remote User VPN Disconnects
    ... It might also happen due to a setting on your server. ... Check in the remote ... the users and I both have our "Idle time before connecting" set to ... >> number of times the dial-up connection is automatically redialed if the ...
    (microsoft.public.win2000.ras_routing)
  • Re: remote User VPN Disconnects
    ... Right-click the dial-up connection you want to configure, ... On the Options tab, in Redial attempts, click the arrows to set the number of times the dial-up connection is automatically redialed if the first attempt to connect fails. ... In Idle time before hanging up, click the arrows to set the amount of idle time before a client hangs up a connection. ...
    (microsoft.public.win2000.ras_routing)
  • Re: HELP: NAT/Masquerading broken with 2.6.11 + pppoe (long)
    ... The TCP stack doesn't know the connection due ... connection and thus hits the INPUT chain and is given the local ...
    (comp.os.linux.networking)
  • Follow-up - Windows XP Pro - share - need advice
    ... the connection with the Share drive. ... I changed the NIC setup to be sure it doesn't turn off. ... the idle time as I don't know exactly how much time to give them. ... I can't find that message anynmore, ...
    (microsoft.public.windowsxp.general)
  • Re: TCP RST+data!
    ... The TCP stack on that device amazes me in how poorly it is written. ... Two things stand out even on the successful connection. ... Comparing that vs the connection with delayed acks, the only difference I see is this: ... Yet it still manages to send data along with the RST, which is something that no other TCP stack would do. ...
    (freebsd-current)