mirror of
https://github.com/libevent/libevent.git
synced 2025-01-31 09:12:55 +08:00
Merge commit 'niels/http_close_connection'
This commit is contained in:
commit
60753da0e9
@ -2523,6 +2523,7 @@ struct terminate_state {
|
||||
struct evhttp_request *req;
|
||||
struct bufferevent *bev;
|
||||
int fd;
|
||||
int gotclosecb: 1;
|
||||
} terminate_state;
|
||||
|
||||
static void
|
||||
@ -2536,6 +2537,7 @@ terminate_chunked_trickle_cb(evutil_socket_t fd, short events, void *arg)
|
||||
test_ok = 1;
|
||||
evhttp_request_free(state->req);
|
||||
event_loopexit(NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
evbuffer_add_printf(evb, "%p", evb);
|
||||
@ -2547,15 +2549,24 @@ terminate_chunked_trickle_cb(evutil_socket_t fd, short events, void *arg)
|
||||
event_once(-1, EV_TIMEOUT, terminate_chunked_trickle_cb, arg, &tv);
|
||||
}
|
||||
|
||||
static void
|
||||
terminate_chunked_close_cb(struct evhttp_connection *evcon, void *arg)
|
||||
{
|
||||
struct terminate_state *state = arg;
|
||||
state->gotclosecb = 1;
|
||||
}
|
||||
|
||||
static void
|
||||
terminate_chunked_cb(struct evhttp_request *req, void *arg)
|
||||
{
|
||||
struct terminate_state *state = arg;
|
||||
struct timeval tv;
|
||||
|
||||
/* we need to hold on to this */
|
||||
evhttp_request_own(req);
|
||||
|
||||
/* we want to know if this connection closes on us */
|
||||
evhttp_connection_set_closecb(
|
||||
evhttp_request_get_connection(req),
|
||||
terminate_chunked_close_cb, arg);
|
||||
|
||||
state->req = req;
|
||||
|
||||
evhttp_send_reply_start(req, HTTP_OK, "OK");
|
||||
@ -2605,6 +2616,7 @@ http_terminate_chunked_test(void)
|
||||
|
||||
terminate_state.fd = fd;
|
||||
terminate_state.bev = bev;
|
||||
terminate_state.gotclosecb = 0;
|
||||
|
||||
/* first half of the http request */
|
||||
http_request =
|
||||
@ -2619,6 +2631,9 @@ http_terminate_chunked_test(void)
|
||||
|
||||
event_dispatch();
|
||||
|
||||
if (terminate_state.gotclosecb == 0)
|
||||
test_ok = 0;
|
||||
|
||||
end:
|
||||
if (fd >= 0)
|
||||
EVUTIL_CLOSESOCKET(fd);
|
||||
|
Loading…
x
Reference in New Issue
Block a user