diff options
author | John Ohl <john@collabriasoftware.com> | 2014-10-26 01:18:10 -0400 |
---|---|---|
committer | John Ohl <john@collabriasoftware.com> | 2014-10-26 01:25:28 -0400 |
commit | 2b9ec4c13c3483c22fdca8e9fccdc017b6135298 (patch) | |
tree | cefe2369b1255dfb90158047438fdffed43ec5bf /http.c | |
parent | 6dba1694c89119c44cef03528945e5a5978ab43a (diff) | |
download | libevent-2b9ec4c13c3483c22fdca8e9fccdc017b6135298.tar.gz |
Implement interface that provides the ability to have an outbound evhttp_connection free itself once all requests have completed
Diffstat (limited to 'http.c')
-rw-r--r-- | http.c | 33 |
1 files changed, 33 insertions, 0 deletions
@@ -769,6 +769,7 @@ evhttp_connection_done(struct evhttp_connection *evcon) { struct evhttp_request *req = TAILQ_FIRST(&evcon->requests); int con_outgoing = evcon->flags & EVHTTP_CON_OUTGOING; + int free_evcon = 0; if (con_outgoing) { /* idle or close the connection */ @@ -801,6 +802,12 @@ evhttp_connection_done(struct evhttp_connection *evcon) * need to detect if the other side closes it. */ evhttp_connection_start_detectclose(evcon); + } else if ((evcon->flags & EVHTTP_CON_AUTOFREE)) { + /* + * If we have no more requests that need completion + * and we're not waiting for the connection to close + */ + free_evcon = 1; } } else { /* @@ -819,6 +826,16 @@ evhttp_connection_done(struct evhttp_connection *evcon) if (con_outgoing && ((req->flags & EVHTTP_USER_OWNED) == 0)) { evhttp_request_free(req); } + + /* If this was the last request of an outgoing connection and we're + * not waiting to receive a connection close event and we want to + * automatically free the connection. We check to ensure our request + * list is empty one last time just in case our callback added a + * new request. + */ + if (free_evcon && TAILQ_FIRST(&evcon->requests) == NULL) { + evhttp_connection_free(evcon); + } } /* @@ -1175,6 +1192,11 @@ evhttp_connection_free(struct evhttp_connection *evcon) } void +evhttp_connection_free_on_completion(struct evhttp_connection *evcon) { + evcon->flags |= EVHTTP_CON_AUTOFREE; +} + +void evhttp_connection_set_local_address(struct evhttp_connection *evcon, const char *address) { @@ -1385,6 +1407,17 @@ evhttp_error_cb(struct bufferevent *bufev, short what, void *arg) */ EVUTIL_ASSERT(evcon->state == EVCON_IDLE); evhttp_connection_reset_(evcon); + + /* + * If we have no more requests that need completion + * and we want to auto-free the connection when all + * requests have been completed. + */ + if (TAILQ_FIRST(&evcon->requests) == NULL + && (evcon->flags & EVHTTP_CON_OUTGOING) + && (evcon->flags & EVHTTP_CON_AUTOFREE)) { + evhttp_connection_free(evcon); + } return; } |