public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Linux poll() <sigh> again
@ 2006-05-11 14:25 linux-os (Dick Johnson)
  2006-05-11 20:47 ` Nishanth Aravamudan
  2006-05-12  5:26 ` David Schwartz
  0 siblings, 2 replies; 15+ messages in thread
From: linux-os (Dick Johnson) @ 2006-05-11 14:25 UTC (permalink / raw)
  To: Linux kernel



Hello,

I'm trying to fix a long-standing bug which has a
work-around that has been working for a year or
so.

The bug relates to Linux implementation of poll()
on a connected socket. If poll() is set to detect
changes on a connected socket, with an infinite
timeout (-1), and the client disconnects, it returns
with a positive value (correct). The returned
events (revents member), shows only POLLIN bit
set. This, according to all known documentation
including man pages on the web, is supposed to
mean that there are data to be read. In fact,
there are no data and a read will return 0.

I have used the subsequent read() with a returned
value of zero, to indicate that the client disconnected
(as a work around). However, on recent versions of
Linux, this is not reliable and the read() may
wait forever instead of immediately returning.

So, it's time to fix poll. Will somebody please
have poll return POLLHUP when the client disconnects
a connected socket? I don't need to add any more
work arounds (like setting the socket to non-blocking
so a read will return even if poll() erroneously
reports that data are ready.

Here is relevent code:

             for(;;) {
                 mem->pfd.fd = fd;
                 mem->pfd.events = POLLIN|POLLERR|POLLHUP|POLLNVAL;
                 mem->pfd.revents = 0x00;
                 message("Calling poll\n");
                 if(poll(&mem->pfd, 0x01, -1) != 0x01)
                     break;
                 message("Poll returns okay with %08x\n", mem->pfd.revents);
                 if(mem->pfd.revents & (POLLHUP|POLLERR|POLLNVAL)) {
                     message("Poll says client hung up\n");
                     break;
                 }
                 if(mem->pfd.revents & POLLIN) {
                     message("Poll says data ready\n");
                     if((status = read(fd, mem->buf, BUF_LEN)) <=0 ) {
                         message("but read returns %d\n", status);
                         break;
                     }
                 }
             }
             message("Disconnected\n");

Here is what the code reports:

Script started on Thu 11 May 2006 10:18:34 AM EDT
[root@chaos servers]# ./control
Calling poll
Poll returns okay with 00000001
Poll says data ready
but read returns 0
Disconnected
Aborted via ^C
[root@chaos servers]# exit
Script done on Thu 11 May 2006 10:19:15 AM EDT

Cheers,
Dick Johnson
Penguin : Linux version 2.6.16.4 on an i686 machine (5592.89 BogoMips).
New book: http://www.lymanschool.com
_
\x1a\x04

****************************************************************
The information transmitted in this message is confidential and may be privileged.  Any review, retransmission, dissemination, or other use of this information by persons or entities other than the intended recipient is prohibited.  If you are not the intended recipient, please notify Analogic Corporation immediately - by replying to this message or by sending an email to DeliveryErrors@analogic.com - and destroy all copies of this information, including any attachments, without reading or disclosing them.

Thank you.

^ permalink raw reply	[flat|nested] 15+ messages in thread
[parent not found: <6bkl7-56Y-11@gated-at.bofh.it>]

end of thread, other threads:[~2006-05-12 18:50 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-05-11 14:25 Linux poll() <sigh> again linux-os (Dick Johnson)
2006-05-11 20:47 ` Nishanth Aravamudan
2006-05-11 21:04   ` linux-os (Dick Johnson)
2006-05-11 21:16     ` Nishanth Aravamudan
2006-05-12 11:42       ` linux-os (Dick Johnson)
2006-05-12 10:37     ` Jan Engelhardt
2006-05-12  5:26 ` David Schwartz
     [not found] <6bkl7-56Y-11@gated-at.bofh.it>
2006-05-12  0:08 ` Robert Hancock
2006-05-12 11:53   ` linux-os (Dick Johnson)
2006-05-12 14:32     ` Robert Hancock
2006-05-12 14:46       ` jimmy
2006-05-12 14:57         ` linux-os (Dick Johnson)
2006-05-12 15:06           ` Eric Dumazet
2006-05-12 15:12           ` Davide Libenzi
2006-05-12 18:49         ` David Schwartz

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