mirror of
https://github.com/cuberite/libevent.git
synced 2025-09-10 13:04:23 -04:00
do close-detection via a separate event
svn:r301
This commit is contained in:
parent
04bdb2488c
commit
a91d2b2b8c
@ -41,6 +41,7 @@ struct evhttp_connection {
|
|||||||
|
|
||||||
int fd;
|
int fd;
|
||||||
struct event ev;
|
struct event ev;
|
||||||
|
struct event close_ev;
|
||||||
struct evbuffer *input_buffer;
|
struct evbuffer *input_buffer;
|
||||||
struct evbuffer *output_buffer;
|
struct evbuffer *output_buffer;
|
||||||
|
|
||||||
|
23
http.c
23
http.c
@ -658,6 +658,9 @@ evhttp_connection_free(struct evhttp_connection *evcon)
|
|||||||
TAILQ_REMOVE(&http->connections, evcon, next);
|
TAILQ_REMOVE(&http->connections, evcon, next);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (event_initialized(&evcon->close_ev))
|
||||||
|
event_del(&evcon->close_ev);
|
||||||
|
|
||||||
if (event_initialized(&evcon->ev))
|
if (event_initialized(&evcon->ev))
|
||||||
event_del(&evcon->ev);
|
event_del(&evcon->ev);
|
||||||
|
|
||||||
@ -729,18 +732,19 @@ static void
|
|||||||
evhttp_connection_start_detectclose(struct evhttp_connection *evcon)
|
evhttp_connection_start_detectclose(struct evhttp_connection *evcon)
|
||||||
{
|
{
|
||||||
evcon->flags |= EVHTTP_CON_CLOSEDETECT;
|
evcon->flags |= EVHTTP_CON_CLOSEDETECT;
|
||||||
|
|
||||||
event_del(&evcon->ev);
|
if (event_initialized(&evcon->close_ev))
|
||||||
event_set(&evcon->ev, evcon->fd, EV_READ,
|
event_del(&evcon->close_ev);
|
||||||
|
event_set(&evcon->close_ev, evcon->fd, EV_READ,
|
||||||
evhttp_detect_close_cb, evcon);
|
evhttp_detect_close_cb, evcon);
|
||||||
event_add(&evcon->ev, NULL);
|
event_add(&evcon->close_ev, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
evhttp_connection_stop_detectclose(struct evhttp_connection *evcon)
|
evhttp_connection_stop_detectclose(struct evhttp_connection *evcon)
|
||||||
{
|
{
|
||||||
evcon->flags &= ~EVHTTP_CON_CLOSEDETECT;
|
evcon->flags &= ~EVHTTP_CON_CLOSEDETECT;
|
||||||
event_del(&evcon->ev);
|
event_del(&evcon->close_ev);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -1264,13 +1268,6 @@ evhttp_connection_set_closecb(struct evhttp_connection *evcon,
|
|||||||
{
|
{
|
||||||
evcon->closecb = cb;
|
evcon->closecb = cb;
|
||||||
evcon->closecb_arg = cbarg;
|
evcon->closecb_arg = cbarg;
|
||||||
/*
|
|
||||||
* applications that stream to clients forever might want to
|
|
||||||
* detect when a browser or client has stopped receiving the
|
|
||||||
* stream. this would be detected on the next write in any case,
|
|
||||||
* however, we can release resources earlier using this.
|
|
||||||
*/
|
|
||||||
evhttp_connection_start_detectclose(evcon);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -1457,6 +1454,8 @@ void
|
|||||||
evhttp_send_reply_start(struct evhttp_request *req, int code,
|
evhttp_send_reply_start(struct evhttp_request *req, int code,
|
||||||
const char *reason)
|
const char *reason)
|
||||||
{
|
{
|
||||||
|
/* set up to watch for client close */
|
||||||
|
evhttp_connection_start_detectclose(req->evcon);
|
||||||
evhttp_response_code(req, code, reason);
|
evhttp_response_code(req, code, reason);
|
||||||
evhttp_make_header(req->evcon, req);
|
evhttp_make_header(req->evcon, req);
|
||||||
evhttp_write_buffer(req->evcon, NULL, NULL);
|
evhttp_write_buffer(req->evcon, NULL, NULL);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user