From 5279036148ca158f7c60f793f401604060b1c1ba Mon Sep 17 00:00:00 2001
From: Nick Mathewson <nickm@torproject.org>
Date: Sun, 9 Aug 2009 10:53:06 -0700
Subject: Be a little more abstract about which connection type use
 bufferevents

---
 src/or/connection.c | 28 +++++++++++++++++++++++-----
 1 file changed, 23 insertions(+), 5 deletions(-)

(limited to 'src/or/connection.c')

diff --git a/src/or/connection.c b/src/or/connection.c
index 3788348cd..54b991139 100644
--- a/src/or/connection.c
+++ b/src/or/connection.c
@@ -183,6 +183,21 @@ conn_state_to_string(int type, int state)
   return buf;
 }
 
+#ifdef USE_BUFFEREVENTS
+/** Return true iff the connection's type is one that can use a
+    bufferevent-based implementation. */
+int
+connection_type_uses_bufferevent(connection_t *conn)
+{
+  switch (conn->type) {
+    case CONN_TYPE_AP:
+      return 1;
+    default:
+      return 0;
+  }
+}
+#endif
+
 /** Allocate and return a new dir_connection_t, initialized as by
  * connection_init(). */
 dir_connection_t *
@@ -308,7 +323,10 @@ connection_init(time_t now, connection_t *conn, int type, int socket_family)
 
   conn->type = type;
   conn->socket_family = socket_family;
-  if (!connection_is_listener(conn)) { /* listeners never use their buf */
+  if (!connection_is_listener(conn)) {
+    /* listeners never use their buf */
+    /* XXX and bufferevents don't either, but for now we leave this here
+     * so that linked connections can still work. */
     conn->inbuf = buf_new();
     conn->outbuf = buf_new();
   }
@@ -3566,8 +3584,8 @@ assert_connection_ok(connection_t *conn, time_t now)
   if (conn->bufev) {
     tor_assert(conn->read_event == NULL);
     tor_assert(conn->write_event == NULL);
-    /* XXX reinstate tor_assert(conn->inbuf == NULL);
-       tor_assert(conn->outbuf == NULL);*/
+    tor_assert(conn->inbuf == NULL);
+    tor_assert(conn->outbuf == NULL);
   }
 #endif
 
@@ -3609,10 +3627,10 @@ assert_connection_ok(connection_t *conn, time_t now)
    * marked_for_close. */
 
   /* buffers */
-  if (!connection_is_listener(conn)) {
+  if (conn->inbuf)
     assert_buf_ok(conn->inbuf);
+  if (conn->outbuf)
     assert_buf_ok(conn->outbuf);
-  }
 
   if (conn->type == CONN_TYPE_OR) {
     or_connection_t *or_conn = TO_OR_CONN(conn);
-- 
cgit v1.2.3