diff options
author | Nick Mathewson <nickm@torproject.org> | 2005-02-25 05:42:01 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2005-02-25 05:42:01 +0000 |
commit | 26e6eb7539616ac51f56a469efd8348719d8376a (patch) | |
tree | 8e07965e8edbf392a7ee933b463cfe470678f52d /src/or/connection.c | |
parent | 6329811a8804ff6755727a32e7da4b8ea17593fd (diff) | |
download | tor-26e6eb7539616ac51f56a469efd8348719d8376a.tar.gz tor-26e6eb7539616ac51f56a469efd8348719d8376a.zip |
Check returns from libevent calls better; stop poking at internals of events to see if they are live.
svn:r3691
Diffstat (limited to 'src/or/connection.c')
-rw-r--r-- | src/or/connection.c | 37 |
1 files changed, 21 insertions, 16 deletions
diff --git a/src/or/connection.c b/src/or/connection.c index e0a5b100f7..c6a45eb308 100644 --- a/src/or/connection.c +++ b/src/or/connection.c @@ -136,6 +136,22 @@ connection_t *connection_new(int type) { return conn; } +/** Tell libevent that we don't care about <b>conn</b> any more. */ +void +connection_unregister(connection_t *conn) +{ + if (conn->read_event) { + if (event_del(conn->read_event)) + log_fn(LOG_WARN, "Error removing read event for %d", (int)conn->s); + tor_free(conn->read_event); + } + if (conn->write_event) { + if (event_del(conn->write_event)) + log_fn(LOG_WARN, "Error removing write event for %d", (int)conn->s); + tor_free(conn->write_event); + } +} + /** Deallocate memory used by <b>conn</b>. Deallocate its buffers if necessary, * close its socket if necessary, and mark the directory as dirty if <b>conn</b> * is an OR or OP connection. @@ -163,14 +179,8 @@ _connection_free(connection_t *conn) { tor_free(conn->nickname); tor_free(conn->socks_request); - if (conn->read_event) { - event_del(conn->read_event); - tor_free(conn->read_event); - } - if (conn->write_event) { - event_del(conn->write_event); - tor_free(conn->write_event); - } + connection_unregister(conn); + if (conn->s >= 0) { log_fn(LOG_INFO,"closing fd %d.",conn->s); tor_close_socket(conn->s); @@ -310,14 +320,9 @@ void connection_close_immediate(connection_t *conn) conn->s, CONN_TYPE_TO_STRING(conn->type), conn->state, (int)conn->outbuf_flushlen); } - if (conn->read_event) { - event_del(conn->read_event); - tor_free(conn->read_event); - } - if (conn->write_event) { - event_del(conn->write_event); - tor_free(conn->write_event); - } + + connection_unregister(conn); + tor_close_socket(conn->s); conn->s = -1; if (!connection_is_listener(conn)) { |