public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Alessandro Baretta <alex@baretta.com>
To: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Inadequate documentation: sockets
Date: Tue, 06 Mar 2001 19:14:46 +0100	[thread overview]
Message-ID: <3AA52916.5FD87258@baretta.com> (raw)

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

             reply	other threads:[~2001-03-06 18:23 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-03-06 18:14 Alessandro Baretta [this message]
2001-03-06 18:34 ` Inadequate documentation: sockets Alan Cox
2001-03-06 17:05   ` Khalid Aziz
2001-03-06 19:26 ` kuznet
2001-03-06 19:30   ` Alessandro Baretta

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3AA52916.5FD87258@baretta.com \
    --to=alex@baretta.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox