diff --git a/src/or/connection.c b/src/or/connection.c index 66a62c549a..c8406fee3f 100644 --- a/src/or/connection.c +++ b/src/or/connection.c @@ -299,25 +299,6 @@ connection_link_connections(connection_t *conn_a, connection_t *conn_b) conn_b->linked_conn = conn_a; } -/** Tell libevent that we don't care about conn any more. */ -void -connection_unregister_events(connection_t *conn) -{ - if (conn->read_event) { - if (event_del(conn->read_event)) - log_warn(LD_BUG, "Error removing read event for %d", conn->s); - tor_free(conn->read_event); - } - if (conn->write_event) { - if (event_del(conn->write_event)) - log_warn(LD_BUG, "Error removing write event for %d", conn->s); - tor_free(conn->write_event); - } - if (conn->dns_server_port) { - dnsserv_close_listener(conn); - } -} - /** 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. diff --git a/src/or/connection_edge.c b/src/or/connection_edge.c index 6207ad3178..944b68e367 100644 --- a/src/or/connection_edge.c +++ b/src/or/connection_edge.c @@ -334,7 +334,7 @@ connection_edge_finished_connecting(edge_connection_t *edge_conn) safe_str(fmt_addr(&conn->addr))); conn->state = EXIT_CONN_STATE_OPEN; - connection_watch_events(conn, EV_READ); /* stop writing, continue reading */ + connection_watch_events(conn, READ_EVENT);/* stop writing, continue reading */ if (connection_wants_to_flush(conn)) /* in case there are any queued relay * cells */ connection_start_writing(conn); @@ -2727,7 +2727,7 @@ connection_exit_connect(edge_connection_t *edge_conn) case 0: conn->state = EXIT_CONN_STATE_CONNECTING; - connection_watch_events(conn, EV_WRITE | EV_READ); + connection_watch_events(conn, READ_EVENT | WRITE_EVENT); /* writable indicates finish; * readable/error indicates broken link in windows-land. */ return; @@ -2740,7 +2740,7 @@ connection_exit_connect(edge_connection_t *edge_conn) log_warn(LD_BUG,"newly connected conn had data waiting!"); // connection_start_writing(conn); } - connection_watch_events(conn, EV_READ); + connection_watch_events(conn, READ_EVENT); /* also, deliver a 'connected' cell back through the circuit. */ if (connection_edge_is_rendezvous_stream(edge_conn)) { diff --git a/src/or/connection_or.c b/src/or/connection_or.c index b4e80926be..54dc1ab2f1 100644 --- a/src/or/connection_or.c +++ b/src/or/connection_or.c @@ -792,7 +792,7 @@ connection_or_connect(const tor_addr_t *_addr, uint16_t port, connection_free(TO_CONN(conn)); return NULL; case 0: - connection_watch_events(TO_CONN(conn), EV_READ | EV_WRITE); + connection_watch_events(TO_CONN(conn), READ_EVENT | WRITE_EVENT); /* writable indicates finish, readable indicates broken link, error indicates broken link on windows */ return conn; diff --git a/src/or/directory.c b/src/or/directory.c index d86495dca5..1b972a345b 100644 --- a/src/or/directory.c +++ b/src/or/directory.c @@ -794,7 +794,7 @@ directory_initiate_command_rend(const char *address, const tor_addr_t *_addr, payload, payload_len, supports_conditional_consensus, if_modified_since); - connection_watch_events(TO_CONN(conn), EV_READ | EV_WRITE); + connection_watch_events(TO_CONN(conn), READ_EVENT | WRITE_EVENT); /* writable indicates finish, readable indicates broken link, error indicates broken link in windowsland. */ } @@ -833,7 +833,7 @@ directory_initiate_command_rend(const char *address, const tor_addr_t *_addr, payload, payload_len, supports_conditional_consensus, if_modified_since); - connection_watch_events(TO_CONN(conn), EV_READ | EV_WRITE); + connection_watch_events(TO_CONN(conn), READ_EVENT|WRITE_EVENT); connection_start_reading(TO_CONN(linked_conn)); } } diff --git a/src/or/dns.c b/src/or/dns.c index ba34b406b9..8d00d23eee 100644 --- a/src/or/dns.c +++ b/src/or/dns.c @@ -14,9 +14,11 @@ #include "or.h" #include "ht.h" #ifdef HAVE_EVENT2_DNS_H +#include #include #include #else +#include #include "eventdns.h" #ifndef HAVE_EVDNS_SET_DEFAULT_OUTGOING_BIND_ADDRESS #define HAVE_EVDNS_SET_DEFAULT_OUTGOING_BIND_ADDRESS diff --git a/src/or/main.c b/src/or/main.c index c808845192..c3dae2ad54 100644 --- a/src/or/main.c +++ b/src/or/main.c @@ -18,6 +18,12 @@ #endif #include "memarea.h" +#ifdef HAVE_EVENT2_EVENT_H +#include +#else +#include +#endif + void evdns_shutdown(int); /********* PROTOTYPES **********/ @@ -140,6 +146,25 @@ connection_add(connection_t *conn) return 0; } +/** Tell libevent that we don't care about conn any more. */ +void +connection_unregister_events(connection_t *conn) +{ + if (conn->read_event) { + if (event_del(conn->read_event)) + log_warn(LD_BUG, "Error removing read event for %d", conn->s); + tor_free(conn->read_event); + } + if (conn->write_event) { + if (event_del(conn->write_event)) + log_warn(LD_BUG, "Error removing write event for %d", conn->s); + tor_free(conn->write_event); + } + if (conn->dns_server_port) { + dnsserv_close_listener(conn); + } +} + /** Remove the connection from the global list, and remove the * corresponding poll entry. Calling this function will shift the last * connection (if any) into the position occupied by conn. @@ -244,17 +269,17 @@ get_connection_array(void) } /** Set the event mask on conn to events. (The event - * mask is a bitmask whose bits are EV_READ and EV_WRITE.) + * mask is a bitmask whose bits are READ_EVENT and WRITE_EVENT) */ void -connection_watch_events(connection_t *conn, short events) +connection_watch_events(connection_t *conn, watchable_events_t events) { - if (events & EV_READ) + if (events & READ_EVENT) connection_start_reading(conn); else connection_stop_reading(conn); - if (events & EV_WRITE) + if (events & WRITE_EVENT) connection_start_writing(conn); else connection_stop_writing(conn); diff --git a/src/or/or.h b/src/or/or.h index e4989fc432..b6ee72d9b5 100644 --- a/src/or/or.h +++ b/src/or/or.h @@ -93,12 +93,6 @@ #include "address.h" #include "compat_libevent.h" -#ifdef HAVE_EVENT2_EVENT_H -#include -#else -#include -#endif - /* These signals are defined to help control_signal_act work. */ #ifndef SIGHUP @@ -2931,7 +2925,6 @@ control_connection_t *control_connection_new(int socket_family); connection_t *connection_new(int type, int socket_family); void connection_link_connections(connection_t *conn_a, connection_t *conn_b); -void connection_unregister_events(connection_t *conn); void connection_free(connection_t *conn); void connection_free_all(void); void connection_about_to_close_connection(connection_t *conn); @@ -3652,13 +3645,18 @@ extern int has_completed_circuit; int connection_add(connection_t *conn); int connection_remove(connection_t *conn); +void connection_unregister_events(connection_t *conn); int connection_in_array(connection_t *conn); void add_connection_to_closeable_list(connection_t *conn); int connection_is_on_closeable_list(connection_t *conn); smartlist_t *get_connection_array(void); -void connection_watch_events(connection_t *conn, short events); +typedef enum watchable_events { + READ_EVENT=0x02, + WRITE_EVENT=0x04 +} watchable_events_t; +void connection_watch_events(connection_t *conn, watchable_events_t events); int connection_is_reading(connection_t *conn); void connection_stop_reading(connection_t *conn); void connection_start_reading(connection_t *conn);