[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [Libevent-users] Q: Exception callbacks and events that should run immediately



On Wed, Dec 05, 2012 at 11:10:04AM +0200, Nir Soffer wrote:
> On Wed, Dec 5, 2012 at 10:54 AM, Sashan Govender <sashang@xxxxxxxxx> wrote:
> 
> > Hi!
> >
> >
> >> 1) I don't see any notion of event notification on FD exception - e.g.
> >> socket close.
> >>     There are some words for buffer events, but nothing for regular file
> >>     descriptor based callbacks. So what is a good way to get a callback
> >> when specific
> >>     FD is closed/disconnected?
> >>
> >
> > If the fd is a socket and the peer closes then you'll get a read callback.
> > When you read from the fd 'read' will return 0 indicating that the peer
> > closed.
> >
> 
> But if the peer die without closing the socket, you will never get a read
> event. In this case you will fail when writing to the socket.
> 
> You can simulate this by disconnecting the peer from the network.

Writing to the socket, in most cases, not something you want to do just
to determine if the socket is alive.

If a peer is disconnected, e.g., it shuts down, the OS *should* 
eventually time-out the session which will result in your eventcb being
executed. 

Another option is to set your own read timeout on the socket.
***********************************************************************
To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
unsubscribe libevent-users    in the body.