[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[Libevent-users] evhttp request connection close
I'm working on a program which needs to make a few http-post requests.
The following sample code demonstrates that libevent only closes
outgoing connections (and exits the event-loop) if Connection close
is specified.
event_init();
evcon = evhttp_connection_new("google.com", 80);
req = evhttp_request_new(http_reply, NULL);
evhttp_add_header(req->output_headers, "Host", "google.com");
//evhttp_add_header(req->output_headers, "Connection", "close");
evhttp_make_request(evcon, req, EVHTTP_REQ_POST, "/bla");
event_dispatch();
evhttp_connection_free(evcon);
Is inserting a Connection close header in the last request the best way
to complete the event-loop? Wouldn't it be better to reset _outgoing_
connections in evhttp_connection_done when all requests are handled?
Something like the following diff:
--- http.c.orig 2010-04-27 08:57:13.000000000 +0200
+++ http.c 2010-04-27 09:02:31.000000000 +0200
@@ -743,20 +743,23 @@ evhttp_connection_done(struct evhttp_con
if (!evhttp_connected(evcon))
evhttp_connection_connect(evcon);
else
evhttp_request_dispatch(evcon);
} else if (!need_close) {
/*
* The connection is going to be persistent, but we
* need to detect if the other side closes it.
*/
evhttp_connection_start_detectclose(evcon);
+ /* no more requests on this connection */
+ } else {
+ evhttp_connection_reset(evcon);
}
} else {
/*
* incoming connection - we need to leave the request on the
* connection so that we can reply to it.
*/
evcon->state = EVCON_WRITING;
}
/* notify the user of the request */
--
Sten Spans
"There is a crack in everything, that's how the light gets in."
Leonard Cohen - Anthem
***********************************************************************
To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
unsubscribe libevent-users in the body.