Re: Sockets in C on Linux
From: Alex Fraser (me_at_privacy.net)
Date: 02/03/05
- Next message: Dave Neary: "Re: Basic bit question (in C)"
- Previous message: CBFalconer: "Re: Need help porting simple program Windows-->Linux"
- In reply to: Michael Jørgensen: "Re: Sockets in C on Linux"
- Next in thread: Rene Moehring: "Re: Sockets in C on Linux"
- Reply: Rene Moehring: "Re: Sockets in C on Linux"
- Reply: Michael Jørgensen: "Re: Sockets in C on Linux"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 3 Feb 2005 08:01:23 -0000
"Michael Jørgensen" <mij@tpack.net> wrote in message
news:4201cae0$0$251$edfadb0f@dread12.news.tele.dk...
> "Andrea Sini" <do@notwrite.it> wrote in message
> news:ZXcMd.488391$b5.23081497@news3.tin.it...
> > I'd like to know if there is a way to know if one of the sides of a TCP
> > connection is down without sending any message, using some API (in
> > UNIX)
>
> Use the socket options SO_KEEPALIVE and TCP_KEEPALIVE.
This will fail to detect the possibility that the software at the other side
has (for some reason) stopped reading/writing the socket. For this reason it
is usually preferable to use a timeout. That is, if you are unable to move
any data for a certain period of time, assume something has gone wrong and
give up.
For Linux/Unix, use either alarm() (looks relatively simple but isn't
really) or select()/poll() and non-blocking sockets (see fcntl()). On Linux,
using select() it is easy to write functions that act like blocking
read()/write() (or send()/recv()) calls with a timeout exactly as you'd get
using alarm() and blocking calls, but without the complications.
Alex
- Next message: Dave Neary: "Re: Basic bit question (in C)"
- Previous message: CBFalconer: "Re: Need help porting simple program Windows-->Linux"
- In reply to: Michael Jørgensen: "Re: Sockets in C on Linux"
- Next in thread: Rene Moehring: "Re: Sockets in C on Linux"
- Reply: Rene Moehring: "Re: Sockets in C on Linux"
- Reply: Michael Jørgensen: "Re: Sockets in C on Linux"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|