Hi,
I'm trying to use a kqueue to listen for VNODE events on a worker thread. I want new events to be registered with the kqueue by a separate thread.
I have been referring to this example http://doc.geoffgarside.co.uk/kqueue/file.html
Here are the relevant parts of code as it is at the moment.
In my worker thread:
Other thread
When I run my code the kevent call in the worker code doesn't block at all. Any ideas what I'm missing? or if what I want to do is even possible?
Ben
I'm trying to use a kqueue to listen for VNODE events on a worker thread. I want new events to be registered with the kqueue by a separate thread.
I have been referring to this example http://doc.geoffgarside.co.uk/kqueue/file.html
Here are the relevant parts of code as it is at the moment.
In my worker thread:
Code:
std::cerr << "Started worker" << std::endl;
struct kevent ke;
int i;
while ( !mStopRequested ) {
memset(&ke, 0x00, sizeof(kevent));
i = kevent(kq, NULL, 0, &ke, 1, NULL);
if ( i == -1 ) {
std::cerr << "kqueue produced error: " << strerror(i) << std::endl;
continue; // todo is this the best thing todo?
}
std::cerr << "Beep: " << i << std::endl;
}
std::cerr << "Shutting down worker" << std::endl;
Other thread
Code:
int fd = open(fileName.c_str(), O_RDONLY);
if ( fd == -1 ) {
std::cerr << "Failed to open file: " << fileName << " Error: " << strerror(errno) << std::endl;
// todo throw exception
}
struct kevent ke;
EV_SET(&ke, fd, EVFILT_VNODE, EV_ADD, NOTE_DELETE | NOTE_RENAME | NOTE_EXTEND, 0, NULL);
if (kevent(kq, &ke, 1, NULL, 0, NULL) == -1) {
std::cerr << "kevent produced error: " << strerror(errno) << std::endl;
}
When I run my code the kevent call in the worker code doesn't block at all. Any ideas what I'm missing? or if what I want to do is even possible?
Ben