[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[Libevent-users] event_base_dispatch returning -1 - help debugging
- To: libevent-users@xxxxxxxx
- Subject: [Libevent-users] event_base_dispatch returning -1 - help debugging
- From: Julian Bui <julianbui@xxxxxxxxx>
- Date: Thu, 7 Jun 2012 13:59:29 -0700
- Delivered-to: archiver@xxxxxxxx
- Delivered-to: libevent-users-outgoing@xxxxxxxx
- Delivered-to: libevent-users@xxxxxxxx
- Delivery-date: Thu, 07 Jun 2012 17:00:07 -0400
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=qM3NoRx4f2hWlNv/ehMSvZnuKCOrSCuuzyL8EIc9dE0=; b=o5RwwyZqZn+SCUDSAUqRyLN8gVM0YD6qj/kpOg3aBcJPhoE6tmSafT0YtLjmVAUjV6 f1p7amHuEUqUKRtxsZ6vhPohwmYTtMfO/zGFjGqSv3dAflZfmyNsP1+NjaRABBSxFyDC 4/xh2LSmBfimz3QJwkm1kxLeMdGUnE6BbfyYlqI5mUqtb7ZMTjCyr95TcEGGhy60glnX mZc0h0jb8+D7ZUgDp/zRMOlm+VCiRJmwHnZUtQfuF6SICdxvBdxcLp8U3RMVglZOsflZ u/nQGb/tH3efdEy4nku+bqXa6xUiTZqgrernkU1v3nBw/CGbbOu5ZsJHOQtW1leOJwg3 dZUQ==
- Reply-to: libevent-users@xxxxxxxxxxxxx
- Sender: owner-libevent-users@xxxxxxxxxxxxx
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.
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:
- 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.
- 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.
- 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.
- 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