From 26e6eb7539616ac51f56a469efd8348719d8376a Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Fri, 25 Feb 2005 05:42:01 +0000 Subject: Check returns from libevent calls better; stop poking at internals of events to see if they are live. svn:r3691 --- src/or/connection.c | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) (limited to 'src/or/connection.c') 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 conn 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 conn. Deallocate its buffers if necessary, * close its socket if necessary, and mark the directory as dirty if conn * 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)) { -- cgit v1.2.3-54-g00ecf