This is the mail archive of the
glibc-bugs@sourceware.org
mailing list for the glibc project.
[Bug libc/13660] New: poll wrong revents returned
- From: "teodori.serge at hotmail dot com" <sourceware-bugzilla at sourceware dot org>
- To: glibc-bugs at sources dot redhat dot com
- Date: Fri, 03 Feb 2012 19:13:51 +0000
- Subject: [Bug libc/13660] New: poll wrong revents returned
- Auto-submitted: auto-generated
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.