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

[Libevent-users] libevent http long pooling - request stuck



Hi,
I have a strange behaviour using libevent for long pooling.
I'd like to store a list of all the evhttp_request I receive for a specific url, without sending an answer to the client (I'ts long pooling, so I keep the connection open for x seconds).

The problem is that the very first request seems to stuck the others.
Here is a very simple example :

//First we Start the server
int main(int argc, char **argv)
{
  short          http_port = 8081;
  char          *http_addr = "192.168.1.56";
  struct evhttp *http_server = NULL;
  struct event_base *event = event_base_new();
  http_server = evhttp_start(http_addr, http_port);
  evhttp_set_gencb(http_server, generic_request_handler, NULL);
  event_base_dispatch(event);
}

void  generic_request_handler (struct evhttp_request *req) {
   struct evbuffer *buffer = evbuffer_new();
   printf("hello\n");
   evhttp_send_reply_start(req, HTTP_OK, "OK");
   evbuffer_add_printf(buffer, "Hi %s, this is a comet server based on libevent.", req->remote_host);
   evhttp_send_reply_chunk(req, buffer);  
}

First access to the server with firefox print "hello", and send a chunk. OK.
When accessing to the server in another tabs, nothing appen, firefox just wait. When I close the first tab, then "hello" is printed a second time and I get the chunk in the second tab !

If I do the same thing but opening the second connection in a chrome tab (the first one is opened in firefox), I get the second "hello" printed, but nothing more. Very strange ?!

For me, "hello" should be printed for every request executed, even if the evhttp_send_reply(...) isn't call yet.
Is it a bug ?? Am I missing something ?
How can we do long-pooling, considering this limitation ?

Thanks for your help,

--
Quentin