All of lore.kernel.org
 help / color / mirror / Atom feed
* poll() behaves differently in Linux 2.4.1 vs. Linux 2.2.14 (POLLHUP)
@ 2001-03-14  1:59 Jeffrey Butler
  2001-03-14  2:06 ` David S. Miller
  0 siblings, 1 reply; 7+ messages in thread
From: Jeffrey Butler @ 2001-03-14  1:59 UTC (permalink / raw)
  To: linux-kernel

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/

^ permalink raw reply	[flat|nested] 7+ messages in thread
* Re: poll() behaves differently in Linux 2.4.1 vs. Linux 2.2.14 (POLLHUP)
@ 2001-03-15  4:00 Jeffrey Butler
  2001-03-15 17:22 ` kuznet
  0 siblings, 1 reply; 7+ messages in thread
From: Jeffrey Butler @ 2001-03-15  4:00 UTC (permalink / raw)
  To: linux-kernel; +Cc: kuznet, davem

Alexy wrote:
>> Damn, we did not test behaviour on absolutely new
>> clean never connected socket... Solaris really may
>> return 0 on it.
>>
>> However, looking from other hand the issue looks as
>> absolutely academic and not related to practice in
>> any way.

Hi,
  I'm not sure this issue is really that academic.  In
fact, it's one of those nitty-gritty, annoying details
that academics tend to ignore :).  Anyway, I'm looking
at this from a very pragmatic standpoint.  I'd like to
minimize the complexity and the number of special
cases when trying to support an application on several
different platforms.  If other popular Unix OS's
behave this way I definely understand the reasoning,
but it seems that at least Solaris 7 does not... 
Sure, workarounds exist, but they just complicates
things.

-jeff

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

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

end of thread, other threads:[~2001-03-15 17:23 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2001-03-14  1:59 poll() behaves differently in Linux 2.4.1 vs. Linux 2.2.14 (POLLHUP) Jeffrey Butler
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
  -- strict thread matches above, loose matches on Subject: below --
2001-03-15  4:00 Jeffrey Butler
2001-03-15 17:22 ` kuznet

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.