[or-cvs] Add kludgy function to force controllers to flush EVENT_ERR...

Nick Mathewson nickm at seul.org
Fri Apr 8 03:36:42 UTC 2005


Update of /home/or/cvsroot/tor/src/or
In directory moria.mit.edu:/tmp/cvs-serv12771/src/or

Modified Files:
	connection.c control.c or.h 
Log Message:
Add kludgy function to force controllers to flush EVENT_ERR_MSG events.

Index: connection.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/connection.c,v
retrieving revision 1.362
retrieving revision 1.363
diff -u -d -r1.362 -r1.363
--- connection.c	8 Apr 2005 03:26:44 -0000	1.362
+++ connection.c	8 Apr 2005 03:36:39 -0000	1.363
@@ -1265,6 +1265,40 @@
   return 0;
 }
 
+/* DOCDOC */
+void _connection_controller_force_write(connection_t *conn)
+{
+  /* XXX This is hideous code duplication, but raising it seems a little
+   * tricky for now.  Think more about this one.   We only call it for
+   * EVENT_ERR_MSG, so messing with buckets a little isn't such a big problem.
+   */
+  int result;
+  tor_assert(conn);
+  tor_assert(!conn->tls);
+  tor_assert(conn->type == CONN_TYPE_CONTROL);
+  if (conn->marked_for_close || conn->s < 0)
+    return;
+
+  result = flush_buf(conn->s, conn->outbuf, &conn->outbuf_flushlen);
+  if (result < 0) {
+    connection_close_immediate(conn); /* Don't flush; connection is dead. */
+    connection_mark_for_close(conn);
+    return;
+  }
+
+  if (result > 0 && !is_local_IP(conn->addr)) { /* remember it */
+    rep_hist_note_bytes_written(result, time(NULL));
+    global_write_bucket -= result;
+  }
+
+  if (!connection_wants_to_flush(conn)) { /* it's done flushing */
+    if (connection_finished_flushing(conn) < 0) {
+      /* already marked */
+      return;
+    }
+  }
+}
+
 /** Append <b>len</b> bytes of <b>string</b> onto <b>conn</b>'s
  * outbuf, and ask it to start writing.
  */

Index: control.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/control.c,v
retrieving revision 1.75
retrieving revision 1.76
diff -u -d -r1.75 -r1.76
--- control.c	5 Apr 2005 22:56:16 -0000	1.75
+++ control.c	8 Apr 2005 03:36:39 -0000	1.76
@@ -330,6 +330,9 @@
         conns[i]->state == CONTROL_CONN_STATE_OPEN &&
         conns[i]->event_mask & (1<<event)) {
       send_control_message(conns[i], CONTROL_CMD_EVENT, buflen, buf);
+      if (event == EVENT_ERR_MSG) {
+        _connection_controller_force_write(conns[i]);
+      }
     }
   }
 

Index: or.h
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/or.h,v
retrieving revision 1.592
retrieving revision 1.593
diff -u -d -r1.592 -r1.593
--- or.h	7 Apr 2005 22:13:16 -0000	1.592
+++ or.h	8 Apr 2005 03:36:39 -0000	1.593
@@ -1283,6 +1283,7 @@
 int connection_wants_to_flush(connection_t *conn);
 int connection_outbuf_too_full(connection_t *conn);
 int connection_handle_write(connection_t *conn);
+void _connection_controller_force_write(connection_t *conn);
 void connection_write_to_buf(const char *string, size_t len, connection_t *conn);
 
 connection_t *connection_or_exact_get_by_addr_port(uint32_t addr, uint16_t port);



More information about the tor-commits mailing list