[Ffmpeg-devel] poll() emulation for ffserver
François Revol
revol
Wed Feb 14 22:43:16 CET 2007
> matthieu castet wrote:
> > Hi,
> >
> > Fran?ois Revol wrote:
> >
> >> +
> >> + FD_ZERO(&read_set);
> >> + FD_ZERO(&write_set);
> >> + FD_ZERO(&exception_set);
> >> +
> >> + n = -1;
> >> + for(i = 0; i < numfds; i++) {
> >> + if (fds[i].fd < 0)
> >> + continue;
> >> +
> >> + if (fds[i].events & POLLIN) FD_SET(fds[i].fd, &
> > > read_set);
> >> + if (fds[i].events & POLLOUT) FD_SET(fds[i].fd, &
> > > write_set);
> >> + if (fds[i].events & POLLERR) FD_SET(fds[i].fd, &
> > > exception_set);
> > You you check if numfds >= FD_SETSIZE :
> in fact it is fds[i].fd >= FD_SETSIZE
Right, FD_SETSIZE is the size of the bitmap.
As I said it was a quick workaround.
Now, seems the one in glibc doesn't do any more checking...
glibc/sysdeps/unix/bsd/poll.c simply takes any fd >= 0.
It does allocate the fd_set with the max fd size, but not checking each
fd to be in that bound.
At least the version I have here, which is quite old.
http://www.opengroup.org/onlinepubs/007908799/xsh/poll.html
doesn't say anything of fds[].fd >= OPEN_MAX ...
though it being >= OPEN_MAX makes it invalid anyway.
> >
> > man select
> > [...]
> > An fd_set is a fixed size buffer. Executing FD_CLR() or FD_SET()
> > with
> > a value of fd that is negative or is equal to or larger than
> > FD_SETSIZE
> > will result in undefined behavior. Moreover, POSIX requires fd to
> > be a
> > valid file descriptor.
I guess we can drop the valid fd part here.
How about this one ?
Fran?ois.
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20070214/351b5148/attachment.asc>
More information about the ffmpeg-devel
mailing list