Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

triggering kevent by force

I'm using kqueue for socket synchronization in OS X. I can register an event of interest like the following:

struct kevent change;
EV_SET(&change, connected_socket, EVFILT_READ, EV_ADD, 0, NULL, NULL);
kevent(k_queue_, &change, 1, NULL, 0, NULL);

And the question is, is there a way to trigger this event by force so that the waiting kevent call would return?

like image 439
Kay Avatar asked Sep 10 '26 16:09

Kay


1 Answers

Some possibilities aside from natural writing of data to the other side of the socket :)

  • shutdown(2) the read side of that socket - you'll get EV_EOF in flags (silly),
  • Use the timeout argument and call the same handling function,
  • Use the self-pipe trick when you need to break the wait.

My question though: why do you need this?

Edit:

If I understand your comments correctly you are looking for a way to get around edge-triggered behavior (EV_CLEAR) for write events. I believe that the proper way of doing this is to un-register your socket from EVFILT_WRITE when you don't have anything in the outgoing queue, then re-register it again when there's data to send. It's a bit more work, but that's how it works, and you don't need any additional system calls since kevent(2) accepts both changes and results. Take a look into libevent and see how it handles this sort of stuff. And you are using non-blocking sockets, right?

like image 51
Nikolai Fetissov Avatar answered Sep 14 '26 06:09

Nikolai Fetissov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!