* poll() returns EINVAL
@ 2005-08-26 15:25 Gereon Steffens
0 siblings, 0 replies; only message in thread
From: Gereon Steffens @ 2005-08-26 15:25 UTC (permalink / raw)
To: linux-kernel
Hi,
under what appears to me as weird circumstances, poll() returns EINVAL
where I belive it shouldn't. Here's an example program that
demonstrates the problem both on kernel 2.4 and 2.6 machines:
#include <sys/poll.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#define MAX 1025
#define MOD 250
int main(int argc, char**argv)
{
struct pollfd pfd[MAX] = { { 0 } };
int i, rc;
for (i=0; i<MAX; ++i)
{
int fd;
fd = dup(1);
pfd[i].fd = fd;
pfd[i].events = POLLOUT;
pfd[i].revents = 0;
printf("%d fd: %d\n", i, fd);
if (i % MOD == 0)
{
/* put same fd into set with a check for reading */
++i;
pfd[i].fd = fd;
pfd[i].events = POLLIN;
pfd[i].revents = 0;
printf("%d fd: %d\n", i, fd);
}
}
rc = poll(pfd, MAX, 0);
printf("poll rc %d errno %d %s\n", rc, errno, strerror(errno));
return 0;
}
Run this program after the number for file descriptors per process has
been increased to more than 1024, e.g. using "ulimit -n 2000".
Even more weird is the fact than when MAX is defined as 1024 or less,
the failure never happens. If MOD is changed so that less than 4
"duplicate"
fds are in the set, poll() works fine also.
Am I doing something wrong? Why does poll choke on such duplicate fd
to be checked, and why does it do this only when the fd list is longer
than 1024 entries?
Thanks for any insights,
Gereon
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2005-08-26 15:25 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-08-26 15:25 poll() returns EINVAL Gereon Steffens
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox