소스 검색

Isolate Libevent API dependency to just main.c and dns.c in src/or.

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.
Nick Mathewson 16 년 전
부모
커밋
1e709c79d1
7개의 변경된 파일43개의 추가작업 그리고 37개의 파일을 삭제
  1. 0 19
      src/or/connection.c
  2. 3 3
      src/or/connection_edge.c
  3. 1 1
      src/or/connection_or.c
  4. 2 2
      src/or/directory.c
  5. 2 0
      src/or/dns.c
  6. 29 4
      src/or/main.c
  7. 6 8
      src/or/or.h

+ 0 - 19
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.

+ 3 - 3
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)) {

+ 1 - 1
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;

+ 2 - 2
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));
   }
 }

+ 2 - 0
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

+ 29 - 4
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);

+ 6 - 8
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);