public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Inadequate documentation: sockets
@ 2001-03-06 18:14 Alessandro Baretta
  2001-03-06 18:34 ` Alan Cox
  2001-03-06 19:26 ` kuznet
  0 siblings, 2 replies; 5+ messages in thread
From: Alessandro Baretta @ 2001-03-06 18:14 UTC (permalink / raw)
  To: Linux Kernel Mailing List

Hello everybody!

I am a newbie in this list, so please accept my apologies for not
being adeqately informed on many technical issues many a kernel
programmer might consider banal.

I wish to bring your attention to the documentation available on
the topic of of the _disconnection_ of stream oriented sockets.
I'm writing a user space program that uses TCP sockets. I need to
know if and when a given connection is broken, and more
specifically if and when _one_ direction of the stream is shut
down by the peer. The following documentation seems to apply to my
case:

1) man poll:
The manual specifies the following flag to be returned by the
kernel
> #define POLLHUP     0x0010    /* Hung up */

Hanging up is ambiguous. Does it mean that the client is dead,
that he closed his end of the socket, or that he shut down one or
both directions of the data flow? The following man page clears
this up, but I think the following information would best be
placed in man poll.

2) man 7 socket
> The user can then wait for
> various events via poll(2) or select(2).

      
+-----------+-----------+--------------------------------------------+
       |Read       | POLLHUP   | A disconnection request has been
initiated |
       |           |           | by the other
end.                          |
      
+-----------+-----------+--------------------------------------------+
       |Read       | POLLHUP   | A connection is broken (only 
for  connec­ |
       |           |           | tion-oriented protocols).  When
the socket |
       |           |           | is writen SIGPIPE is also
sent.            |
      
+-----------+-----------+--------------------------------------------+
      
+-----------+-----------+--------------------------------------------+
       |Read/Write | POLLHUP   | The other end has shut down one
direction. |
      
+-----------+-----------+--------------------------------------------+

This means that I get a POLLHUP in all the time, but it does not
allow me to distinguish among the three different relevant cases:
a) the client shutting down reads only, b) the client shutting
down writes only, c) the client going down entirely.

I figured the following documentation might help, but it did not.
3) man 2 send
>ERRORS
>       EPIPE  The  local  end  has been shut down on a connection
>              oriented socket.  In this  case  the  process  will
>              also  receive a SIGPIPE unless MSG_NOSIGNAL is set.
4) man recv
>       The flags argument to a recv call is formed by OR'ing  one
>       or more of the following values:
>       MSG_NOSIGNAL
>              This flag turns off raising of  SIGPIPE  on  stream
>              sockets when the other end disappears.
Yet, although the manpage mentions an MSG_NOSIGNAL flag, it never
mentions either raising a SIGPIPE when the socket is disconnected,
nor setting errno to EPIPE upon execution of recv on a socket
closed by the peer. This is very ambiguous. I would be very
greatful to anyone who clear up this point.

Finally I'm left with my original problem: how am I supposed to
detect a close or a shutdown from the peer? Once again, I thank in
advance anyone who will lend me a hand by explaining this to me or
by addressing me to more adequate documentation.

Thanks for your kind interest.

Alex Baretta

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2001-03-06 19:39 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2001-03-06 18:14 Inadequate documentation: sockets Alessandro Baretta
2001-03-06 18:34 ` Alan Cox
2001-03-06 17:05   ` Khalid Aziz
2001-03-06 19:26 ` kuznet
2001-03-06 19:30   ` Alessandro Baretta

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox