bitwiseworks / libcx

kLIBC Extension Library
GNU Lesser General Public License v2.1
11 stars 1 forks source link

Move libpoll code to libcx #8

Closed dmik closed 8 years ago

dmik commented 8 years ago

There is a poll implementation based on select which is available as a separate RPM for OS/2: http://trac.netlabs.org/rpm/browser/spec/trunk/SPECS/libpoll.spec. We should merge it in to get rid of another extra library.

dmik commented 8 years ago

Note that there is also another poll implementation by @komh, https://github.com/komh/os2compat/blob/master/network/poll.c (based on the code taken from the OS/2 bits of VLC). The essential difference (from the VLC code and from the libpoll port mentioned above) is that @komh added support for regular and other non-socket file descriptors. As for regular files, they should be always reported as ready for reading and for writing indeed (see e.g. http://man7.org/linux/man-pages/man2/select.2.html) but @komh code does just that and we should also do it. For other non-socket file descriptors, he returns POLLNVAL but that looks like an abuse to me as http://man7.org/linux/man-pages/man2/poll.2.html says POLLNVAL should be returned if the given fd doesn't represent the open file. Perhaps this was done to avoid the infamous errno 22 (EINVAL) from select but this looks like problem hiding to me since when we get such an error we often need to modify the original code to make it work (e.g. socketpair instead of pipe or such).

So I think that we should take the libpoll code as a base (as it is already tested and has additions necessary for VBox) and enhance it with regular file support, leaving other non-socket cases apart (i.e. let them fail with EINVAL).

dmik commented 8 years ago

The code is moved and I also added support for regular files (similar to what @komh does). However, now I think that we should actually intercept the select call and make it support regular files aw sell (poll will then support them too)...

dmik commented 8 years ago

What makes me think this way is not only the thought "why not" (given that poll and select are just two different interfaces to the same thing) but also the fact that EMX libc docs mention that:

All file handles under DOS; regular files are reported to be ready for reading if the file pointer is not at the end of the file -- this behavior may change in the future: regular files should be reported to be always ready for reading

I.e. original EMX select() would report regular files as ready for reading.

dmik commented 8 years ago

I created #10 for select and closing this one.