mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jeffrey Butler <jeffreymbutler@yahoo.com>
To: linux-kernel@vger.kernel.org
Subject: poll() behaves differently in Linux 2.4.1 vs. Linux 2.2.14 (POLLHUP)
Date: Tue, 13 Mar 2001 17:59:21 -0800 (PST)	[thread overview]
Message-ID: <20010314015921.19287.qmail@web11808.mail.yahoo.com> (raw)

Hi,
  I've noticed that poll() calls on IPv4 sockets do
not behave the same under linux 2.4 vs. linux 2.2.14. 
Linux 2.4 will return POLLHUP for a socket that is not
connected (and has never been connected) while Linux
2.2 will not.
  The following example program demonstrates the
problem when it's run under linux 2.4:

---
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/poll.h>

int main(
  int argc,
  char **argv) 
{
  int s;
  int rv;
  struct pollfd pfd;
  
  s = socket(PF_INET,SOCK_STREAM,0);
  pfd.fd = s;
  pfd.events = 0;
  rv = poll(&pfd,1,1);
  printf("rv = %d
",rv);
  if(pfd.revents&POLLIN) {printf("pollin
");}
  if(pfd.revents&POLLPRI){printf("pollpri
");}
  if(pfd.revents&POLLOUT){printf("pollout
");}
  if(pfd.revents&POLLERR){printf("pollerr
");}
  if(pfd.revents&POLLHUP){printf("pollhup
");}
  close(s);
}

(copy text to file, run 'gcc -o example example.c', to
compile)

Under Linux 2.4 (specifically 2.4.1) this program will
output:
rv = 0
pollhup

Under Linux 2.2.14 it outputs:
rv = 0

Other operating systems (not that they are necessarily
correct) also output the same as Linux 2.2.14.  I
tried this on FreeBSD 4.4.1, Solaris 5.7 (on a SPARC),
and Windows 2000 with Cygwin 1.1.7.

I'm not sure what POSIX says about this behavior...

This can be traced back to the poll implementation in
the Linux kernel:

In 2.2.14:
net/ipv4/tcp.c[line 580]:
	if (sk->shutdown & RCV_SHUTDOWN)
		mask |= POLLHUP;

vs.
In 2.4.1:
net/ipv4/tcp.c[line 586]:
	 * NOTE. Check for TCP_CLOSE is added. The goal is to
prevent
	 * blocking on fresh not-connected or disconnected
socket. --ANK
	 */
	if (sk->shutdown == SHUTDOWN_MASK || sk->state ==
TCP_CLOSE)
		mask |= POLLHUP;

The behavior observed at user-level matches his
comment as POLLHUP is returned for a fresh
not-connected socket.

What's the reasoning for this change in behavior?  I
know of ways of getting around it, but I wanted to
bring this to everyone's attention.

thanks,
-jeff



__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - Buy the things you want at great prices.
http://auctions.yahoo.com/

             reply	other threads:[~2001-03-14  2:00 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-03-14  1:59 Jeffrey Butler [this message]
2001-03-14  2:06 ` David S. Miller
2001-03-14  8:12   ` Henning P. Schmiedehausen
2001-03-14 16:28   ` Jeffrey Butler
2001-03-14 19:50   ` kuznet
2001-03-15  4:00 Jeffrey Butler
2001-03-15 17:22 ` kuznet

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=20010314015921.19287.qmail@web11808.mail.yahoo.com \
    --to=jeffreymbutler@yahoo.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

all inboxes | Powered by JetHome®