public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libc/13660] New: poll wrong revents returned
@ 2012-02-03 19:14 teodori.serge at hotmail dot com
  2012-02-03 19:47 ` [Bug libc/13660] " drepper.fsp at gmail dot com
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: teodori.serge at hotmail dot com @ 2012-02-03 19:14 UTC (permalink / raw)
  To: glibc-bugs

http://sourceware.org/bugzilla/show_bug.cgi?id=13660

             Bug #: 13660
           Summary: poll wrong revents returned
           Product: glibc
           Version: 2.14
            Status: NEW
          Severity: critical
          Priority: P2
         Component: libc
        AssignedTo: drepper.fsp@gmail.com
        ReportedBy: teodori.serge@hotmail.com
    Classification: Unclassified


Hello,
poll() is not returning the right events. If socket has data to read, POLLIN is
set, but if socket is closed or shutdown it also sets POLLIN? It should
normally be POLLERR POLLHUP or POLLNVAL, at least not POLLIN.

Ex.:

int prc = 0;
struct pollfd pfd;
while(prc != -1){
 pfd.fd = connectedsocket;
 pfd.events = POLLIN;
 prc = poll(&pfd, 1, 1000);
 if(prc == -1){
  perror("poll");
 }else if(prc == 0){
  printf("timeout");
 }else if(prc == 1 && pfd.revents == POLLIN){
  recv(pfd.fd, buff, sizeof(buff), 0);
  printf("data: %s\n", buff);
 }else if(prc == 1 && pfd.revents != POLLIN){
  close(pfd.fd);
  printf("socket closed\n");
  prc = -1;
 }
}

Output:
timeout
timeout
timeout
data: Hello //peer send data
timeout
timeout
timeout
data: // peer closed or shutdown socket -> poll is heating up 100% CPU
data:
data:
data:

This is the case on Ubuntu and on my own linux from scratch (linux-3.2.2 +
glibc-2.14.1 compiled with gcc-4.6.2 and the linux-3.2.2 headers).
I doubt that it could be and build error, because I tried it on i386 and x86
with different.

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


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

end of thread, other threads:[~2014-06-13 14:09 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-02-03 19:14 [Bug libc/13660] New: poll wrong revents returned teodori.serge at hotmail dot com
2012-02-03 19:47 ` [Bug libc/13660] " drepper.fsp at gmail dot com
2012-02-04  0:08 ` bugdal at aerifal dot cx
2012-02-09  0:19 ` teodori.serge at hotmail dot com
2012-02-09  0:42 ` bugdal at aerifal dot cx
2012-02-09 22:42 ` teodori.serge at hotmail dot com
2012-02-10  1:29 ` bugdal at aerifal dot cx
2014-06-13 14:09 ` fweimer at redhat dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).