Monitor OSX kqueue descriptor for events with ASIO

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Monitor OSX kqueue descriptor for events with ASIO

Boost - Users mailing list
Hi all,

I'm using boost::asio on OS X.  I'd like to watch for changes to a particular regular file - per Apple's documentation, the preferred method for this is with the kevent API.  So I do the following:

1) Wrap a kqueue file descriptor (obtained via a call to kqueue()) in a boost::asio::posix::stream_descriptor with boost::asio::posix::stream_descriptor::assign().
2) Call boost::asio::posix::stream_descriptor::async_wait() to be notified of file events.

The problem appears to be that boost::asio::posix::stream_descriptor::async_wait() uses ioctl() w/ FIONBIO to put the file into non-blocking mode, which fails with "Inappropriate ioctl for device".

A normal blocking call to wait() works just fine.

I realize that my problem is that the kqueue descriptor does not represent a stream of bytes, so it's probably invalid to use stream_descriptor to wrap it.

Does anyone have any ideas on how to work around this?  I looked for a type concept for a non-stream descriptor that I could implement, but I didn't see anything obvious.

Thanks in advance for any advice,

Boost-users mailing list
[hidden email]