I am trying to use libev for event based programming. But there are some events provided by libev like EV_READ, EV_WRITE, EV_TIMER ..
So, is it possible to have an custom event of my own.
For instance, I have a continuous flow of messages from a socket an I am interested in only a type of message in that stream of messages. So, its basically like
while(true)
{
Msg msg = getMessage();
if(msg != null && msg.id == ourId)
return msg;
}
So, I want to register for events of this sort (only that if condition is satisfied.) . Its a custom event right ? How do I specify this event to libev.
I mean in libev we specify like this ..
ev_io_init (&stdin_watcher, stdin_cb, /*STDIN_FILENO*/ 0, EV_READ);
ev_io_start (loop, &stdin_watcher);
I dint see any stuff where we can check for our own events. Is it possible ?
Unfortunately you cannot have a custom event, because libev doesn't manipulate with your data, just checks if there are some, or if you can send some.
So basically, you will have to:
EV_READev_loop, ideally with EV_ONESHOT and a timeout watcher. Right after that call your message handler, which will check the message queue and process all messages thet are in the queueIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With