0

I'm working with libevent for the first time and have been having an issue trying to get my application to not run until the read callback is called. I am using bufferevents as well. Essentially I am doing is trying to avoid the sleep in my main application loop and instead have the OS wake up the process (via libevent) when there is data to be read off the socket. Anyone know how to do this? I found in an alpha build of libevent that you can set a base event loop to be EVLOOP_NO_EXIT_ON_EMPTY, but from looking at the libevent code that will just use up my whole proc I believe. I also read on this question that it is a bad idea to set a socket to blocking on windows which is why I haven't done that as a solution either. I will mark this with libuv and libev too since they are similar and might contribute to my solution.

Community
  • 1
  • 1
SSB
  • 349
  • 3
  • 18
  • after looking into this more I think the answer may be in using libevent's iocp functions instead of using bufferevents. I can't be completely sure since I have nothing to base this off of except looking at the source code though. – SSB Mar 12 '14 at 15:24

1 Answers1

0

you have to use the following api, some of the API may be oudated you can search google for new one.

 struct event_base *base ;  
 struct event g_eve
 base = event_init(); 
 //after binding the socket register your socket for read event using below api  
 event_set(&g_eve, SockFd, EV_READ | EV_PERSIST, CallbackFunctin, &g_eve);  
 event_add(&g_eve, NULL);
 event_base_dispatch(base);
devesh
  • 76
  • 9