[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[Libevent-users] responses delayed while using evhttp



Hi all,

I am having trouble sending HTTP replies/responses in a timely manner using evhttp.  

PROBLEM:
If I call evhttp_send_reply in the gencb (callback that handles all requests), then my requests are sent out in a timely manner and everything is fine.  However, I do some processing that will take a while so I don't want do the processing in this callback because it will hold up the dispatch loop and I think I won't be able to accept any connections while I'm doing this slow processing.  Instead, when I get a request, I store the evhttp_request* off, and then hand it to a thread, and then return from the gencb.  Later, when the processing is done, the original request's evhttp_request* is retrieved and used to send the response.  However, the browser doesn't receive the response until exactly 10.0s later after the evhttp_send_reply was invoked, everytime...unless I call evhttp_send_reply from the gencb in the dispatch loop thread, in which case the browser gets the response immediately.

PSEUDOCODE:

*Dispatch loop thread*
::onGeneralRequest { 1. Store the evhttp_request, 2. Hand off the request to a worker thread, 3. return }

*Worker thread*
      // do work that might take a few seconds
      cout << "about to send reply" << endl;
      evbuffer* resp_buf = evbuffer_new();
      evbuffer_add_printf(resp_buf, "This is the body");
      evhttp_send_reply(response.conn, 200, "bogus reason", resp_buf); // use the original evhttp_request* (response.conn), send a success message
      cout << "sent reply" << endl; // at this point the browser still doesn't get the response, 10s in the future it will get it

QUESTIONS:
Any feedback would be greatly appreciated.

Thanks,
-Julian