Hi everyone, I am having trouble with my libevent 2.0.18 server. The dispatch loop keeps returning -1 and I cannot determine the cause.
I have not tried searching the mailing list as there does not seem to be a search option (http://archives.seul.org/libevent/users/) PROBLEM: My server works most of the time but every once in a while when there are pending requests going into it and I restart the server, it claims it has successfully written to socket. As soon as the callback from the EV_WRITE event returns, then the dispatch loop exits with -1. As I understand it, this means there was an error. OVERVIEW/CONTEXT: At a high level, I add an event with EV_READ | EV_PERSIST that listens to my server socket to my base and start the dispatch loop and calls onAccept when triggered. onAccept will create a client socket and then I add an event with EV_READ | EV_PERSIST that listens to my client socket to my base and calls onRead when triggered. onRead will call recv and then call event_del on the read event. It then adds an event with EV_WRITE | EV_PERSIST that listens to my client socket to my base and calls onWrite when triggered. onWrite always removes all events (read/write) associated with this client socket and then closes the socket. As far as I can tell, before the dispatch loop exits, there was no socket error on write/close. MY STEPS FOR DEBUGGING: 1. tried adding logging, but it never seems to print anything. I create a onLogEvent(int severity, const char* msg) method and pass it to event_set_log_callback(...). I also create an onFatalError method and pass it to event_fatal_callback(...) then enable debug mode. In these callback methods, I just print out the msg and/or error code to stdout. 2. After I break out of the dispatch loop and see -1 returned, I attempt to determine if the loop was broken or exited. I call if(!event_base_got_break(s_event_base)) and if(!event_base_got_exit(s_event_base)), and both evaluate to true, meaning the dispatch loop was not broken or exited. 3. After every windows networking call, I get the error code and if it is equal to SOCKET_ERROR, I get the WSAGetLastError(). However, when my dispatch loop exits, I can see that there was no error returned from the previous networking call. 4. I test event_pending(my_event, EV_READ | EV_PERSIST, NULL) on the persistent event I set up to listen for incoming connections. This event should be persistent and I never event_del() it. However, event_pending keeps returning 0 at all times (even before exiting the dispatch loop). I am suspecting that this method is broken or, more likely, I am not using it correctly. QUESTIONS: I am stumped here. I am also frustrated that my debugging/logging attempts are failing. I am looking for suggestions and possible explanations. Maybe there are still things I need to do after the socket is closed? Please help me out. Thanks in advance, -Julian