feeley/gambit — pull request #7 by vyzo (2013-04-06 19:24:28+00:00)
Title: Poll support for I/O

Poll Support for I/O
====================

Adds a new compile-time configurable option to use poll/ppoll as the select
mechanism.
This allows the system to use more than 1024 file descriptors.

Implementation Notes
--------------------
The poll state is maintained in __device_select_state_struct, which has
been augmented to include a pollfd array and count for the i/o selection.
The size of the array is configurable with MAX_POLLFDS, which matches
MAX_CONDVARS unless explicitly defined.

The state also has 2 bitmaps for read and write ready fds, which behave
similar to fd_set used in select -- but their size is not hard-limited
to 1024 fds as in select. Instead, it matches the configured size of the
pollfd array.

The actual poll is implemented in __device_select.
On entry, the ready sets and fd count are cleared in the state.
File descriptors are added in ___device_select_add_fd, which for poll
pushes the file descriptor to the poll set and increments the count.
When the poll completes, the poll set is scanned updating the bitmaps for
the ready file descriptors.

Using a bitmap for marking the ready sets allows the existing device_select
code to work with minimal modifications, without incurring performance
penalty in the rediness checks.
The checks are implemented using __FD_ISSET, which has the same
interface for both select and poll.
When select is used, the macro is defined to FD_ISSET.
When poll is usde, the macro is defined to operate on a poll bitmap.

Configuration Options
---------------------
A new configure option has been added to enable poll as the select mechanism:
--enable-poll
If the system has ppoll available (glibc), then ppoll will be used instead
of plain poll, allowing high resolution timeouts.

Using poll
----------
1. regenerate configure by running autoconf.
2. Run configure with --enable-poll
3. make && make check && make install as usual.