Re: Sockets in C on Linux

From: Alex Fraser (me_at_privacy.net)
Date: 02/03/05


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



Relevant Pages

  • Re: DIY - Sometimes....
    ... So if they want their local system serviced, I do it, and one month later they leave me? ... From the standpoint of the alarm company, monitored accounts are worth far more effort than local alarms. ... There is no reason why you shoould have to service an alarm that only pays for the time when the same time can be spent on an RMR generating account. ... The problem is that for every company like yours there are at least a dozen Jiminexes who'll gladly gouge the client for all they can get and two dozen "authorized dealers" who haven't a clue what customer service means. ...
    (alt.security.alarms)
  • Re: Bad feelings in Wickes
    ... It is what you do when the alarm goes off that may do so. ... which make it clear that the expected reason ... Ignoring the sound does not amount to suspicious behaviour since ... Alex Heney, Global Villager ...
    (uk.legal)
  • Re: Security alarm hoax so they could check my bag at supermarket
    ... argument as to whether the alarm gives reasonable suspicion. ... A correct approach might be to ask the customer to agree to a search. ... I really haven't developed a firm position on this either way, which is why I would love to see a case brought and argued however, the alarm systems are there for a reason and one thing that can set them off is a customer who is trying to leave the store with goods that still have a security tag on them. ...
    (uk.legal)
  • Re: New Driveway
    ... || dropped kerb doesn't actually lead anywhere. ... The reason to stop other people blocking a persons ... Then you possibly have never lived in a street where there was already too little parking to go around, before people started paying for dropped curbs - effectively "buying" their bit of highway. ...
    (uk.legal)
  • Re: looking to buy a Bosch FCP-500
    ... The reason for choosing it as I have a site with mold growth and this ... There may be a very good reason why "the powers" won't allow it. ... thx spoken to the alarm guy and apparently in some of the states you require ... Australia wont import them - they would rather import one for the whole of ...
    (alt.security.alarms)