Skip to contentSkip to conversation

RFC: poll change

DISCUSSION Tim Hockin 3 participants 3 messages Aug 15, 2001 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

Tim Hockin

author
#1 lore raw
Quoted 9 lines · David S. Miller

From: Tim Hockin <[email protected]>
Date: Tue, 14 Aug 2001 16:53:43 -0700

The standard says negative fd's are ignored. We get that right. What we are left with is an overly paranoid check against max_fds. This check should go away. You should be able to pass in up to your rlimit fds, and let negative ones (holes or tails) be ignored.

Quoted 5 lines

I am saying there is no problem.

In both cases, for a properly written application we ignore the invalid fds. The behavior is identical both before and after your change, so there is no reason to make it.

But for an application that (imho) is poorly written but IS COMPLIANT, it fails.

This program is compliant, if your ulimit -n is maxxed out at 1048576.

I'm not saying it is good design, but it is compliant. The patch hurts nothing and makes poll() that little bit more friendly.

#include <stdio.h>
#include <sys/poll.h>
#include <errno.h>
#include <string.h>

int
main(void)

{
        static struct pollfd ar[1024*1024];
        int size = sizeof(ar)/sizeof(*ar);
        int i;

        for (i = 0; i < size; i++)
                ar[i].fd = -1;
        ar[1000000].fd = 0;
        ar[1000000].events = POLLIN;

        i = poll(ar, size, -1);
        printf("return = %d (%s)\n", i, i?strerror(errno):"success");

        return 0;
}
Signature · 4 lines
Tim Hockin
Systems Software Engineer
Sun Microsystems, Cobalt Server Appliances
[email protected]
#2 lore raw

From: Tim Hockin <[email protected]>
Date: Tue, 14 Aug 2001 17:09:00 -0700

But for an application that (imho) is poorly written but IS COMPLIANT, it fails.

This program is compliant, if your ulimit -n is maxxed out at 1048576.

This program is stupid.

Later,
David S. Miller
[email protected]

#3 lore raw
In reply to a message not in the archive
Quoted 2 lines · David S. Miller

invalid fds. The behavior is identical both before and after your change, so there is no reason to make it.

actually I can see a case where it makes difference: if you sends 1024 entries to poll with the last entry of the array polling for one of the allocated file descriptors (all previous 1023 entries are negative) and the last fd allocated is ID 255.

Andrea