[or-cvs] [tor/master] Isolate Libevent API dependency to just main.c and dns.c in src/or.

Nick Mathewson nickm at seul.org
Fri Jun 12 18:28:07 UTC 2009


Author: Nick Mathewson <nickm at torproject.org>
Date: Thu, 4 Jun 2009 14:49:16 -0400
Subject: Isolate Libevent API dependency to just main.c and dns.c in src/or.
Commit: 1e709c79d12b2366d4e1c1ea517e313cc29ee3cd

The rest of the code was only including event.h so that it could see
EV_READ and EV_WRITE, which we were using as part of the
connection_watch_events interface for no very good reason.
---
 src/or/connection.c      |   19 -------------------
 src/or/connection_edge.c |    6 +++---
 src/or/connection_or.c   |    2 +-
 src/or/directory.c       |    4 ++--
 src/or/dns.c             |    2 ++
 src/or/main.c            |   33 +++++++++++++++++++++++++++++----
 src/or/or.h              |   14 ++++++--------
 7 files changed, 43 insertions(+), 37 deletions(-)

diff --git a/src/or/connection.c b/src/or/connection.c
index 66a62c5..c8406fe 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 <b>conn</b> 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 <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.
diff --git a/src/or/connection_edge.c b/src/or/connection_edge.c
index 6207ad3..944b68e 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 b4e8092..54dc1ab 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 d86495d..1b972a3 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 ba34b40..8d00d23 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 <event2/event.h>
 #include <event2/dns.h>
 #include <event2/dns_compat.h>
 #else
+#include <event.h>
 #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 c808845..c3dae2a 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 <event2/event.h>
+#else
+#include <event.h>
+#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 <b>conn</b> 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 <b>conn</b> to <b>events</b>.  (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 e4989fc..b6ee72d 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 <event2/event.h>
-#else
-#include <event.h>
-#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);
-- 
1.5.6.5



More information about the tor-commits mailing list