Skip to content

Commit

Permalink
Changed EvHttpClient destructor to cancel pending callbacks and act a…
Browse files Browse the repository at this point in the history
…s if pending requests had timed out.
  • Loading branch information
Jonathan Potter committed Jul 1, 2013
1 parent c88fd65 commit d3673df
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
23 changes: 18 additions & 5 deletions evhttpclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ EvHttpClient::~EvHttpClient()
{
HttpConn *conn = connections.front();
connections.pop();
delete conn;
destroyConnAndRequest(conn);
}
}

Expand Down Expand Up @@ -387,10 +387,25 @@ void EvHttpClient::destroyConn(HttpConn *conn)

ev_io_stop(loop, &conn->writeWatcher);
ev_io_stop(loop, &conn->readWatcher);

http_parser_pause(&conn->parser, 1);

delete conn;
}

/*
* Disconnects and frees connection object.
*
* ALSO invokes finalizeTimeout on request if
* a request is attached.
*/
void EvHttpClient::destroyConnAndRequest(HttpConn *conn)
{
if (conn->request != NULL)
finalizeTimeout(conn->request);

destroyConn(conn);
}

/*
* Retrieves a connection from the connection pool,
* or creates a new one if the pool is empty.
Expand Down Expand Up @@ -426,6 +441,7 @@ void EvHttpClient::returnConn(HttpConn *conn)
{
ev_io_stop(loop, &conn->writeWatcher);
ev_io_stop(loop, &conn->readWatcher);
http_parser_pause(&conn->parser, 1);

connections.push(conn);
}
Expand Down Expand Up @@ -558,9 +574,6 @@ void EvHttpClient::timeoutCb(struct ev_loop *loop, struct ev_timer *timer, int r
//ev_timer_stop(loop, timer); //handled in finalizeTimeout
if(conn != NULL)
{
ev_io_stop(loop, &conn->writeWatcher);
ev_io_stop(loop, &conn->readWatcher);
http_parser_pause(&conn->parser, 1);
destroyConn(conn);
request->conn = NULL;
}
Expand Down
1 change: 1 addition & 0 deletions evhttpclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ class EvHttpClient
void retryRequest(RequestInfo *request);
HttpConn *createConn();
void destroyConn(HttpConn *conn);
void destroyConnAndRequest(HttpConn *conn);
HttpConn *getConn();
void returnConn(HttpConn *conn);
void finalizeTimeout(RequestInfo *request);
Expand Down

0 comments on commit d3673df

Please sign in to comment.