The pain of poll(2)?

If you’re working on a multi-platform project which does network communication you will end up thinking about replacing select(2) with poll(2) sooner or later. The problem with select are well known. poll(2) removes the limitations of select(2) and improves speed and features. The problem is that poll(2) isn’t available on all platforms. This means you need a poll(2)-emulation or create wrappers around other similar poll() functions.

In libssh we use a poll(2)-emulation based on select for platforms which don’t provide a poll(2) function like some Windows versions or UNIX systems.

Windows Vista or newer version provide a poll(2) like function called WSAPoll(). To be able to support this call which is faster the the poll(2)-emulation and allows to use more file descriptors we implemented a runtime detection for WSAPoll(). This means during initialization of the socket, we check if the functions can be found in the relevant library. If Windows doesn’t provide it, we fallback to the poll(2)-emulation.

I took several month to get this working correctly on UNIX and Windows. This feature starts to work correctly with libssh 0.4.6 released today.

You may also like...

2 Responses

  1. Sebastián says:

    Use libevent and problem solved.

  2. I know libevent, but don’t want to add more dependencies. libssh should only require a crypto library.

Leave a Reply

Your email address will not be published. Required fields are marked *