Notify libevent HTTP server on client close

Views: 14404 | Add Comments

Although we can set a close callback on HTTP connection, but the HTTP server is not notified if client close unexpetedly, such as CTRL+C.

 evhttp_connection_set_closecb(req->evcon, on_close, NULL);

Because libevent called bufferevent_disable(evon, EV_READ) to stop read on the connection, so the server would not know the client close by read() returns 0, or send() causes SIGPIPE.

All you need to is to re-enable EV_READ on that connection:

struct bufferevent *bev = evhttp_connection_get_bufferevent(req->evcon);
bufferevent_enable(bev, EV_READ);
Posted by ideawu at 2013-09-17 13:45:33 Tags:

Leave a Comment