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.

Left-Leaning Red-Black Trees

Red-Black Trees were originally designed by taking a 2-3-4 tree and unrolling the big nodes into a cluster of simpler binary tree nodes. The 2-3-4 node operations are mapped to binary tree operations. Now Robert Sedgewick presented a new tree called Left-Leaning Red-Black Tree.

A Red-Black tree has a lot of cases you have to consider, especially if you delete a node. This makes the code complex. Left-Leaning Red-Black Trees are a simpler variant of Red-Black Trees. They are simpler to implement (less code) while maintaining the nice features of Red-Black Trees. Less code means faster insertion and deletion, but there are no benchmarks yet.

Once Bob released his new book this would be a nice improvement for csync in the future. You can take a look at the slides of his talk.