[or-cvs] Stop trying to flush on broken sockets marked for close.

Nick Mathewson nickm at seul.org
Sat Feb 28 19:14:13 UTC 2004


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

Modified Files:
	buffers.c connection.c main.c or.h 
Log Message:
Stop trying to flush on broken sockets marked for close.

Index: buffers.c
===================================================================
RCS file: /home/or/cvsroot/src/or/buffers.c,v
retrieving revision 1.65
retrieving revision 1.66
diff -u -d -r1.65 -r1.66
--- buffers.c	28 Feb 2004 07:01:22 -0000	1.65
+++ buffers.c	28 Feb 2004 19:14:11 -0000	1.66
@@ -132,6 +132,10 @@
   return buf_new_with_capacity(INITIAL_BUF_SIZE);
 }
 
+void buf_clear(buf_t *buf)
+{
+  buf->datalen = 0;
+}
 
 size_t buf_datalen(const buf_t *buf)
 {

Index: connection.c
===================================================================
RCS file: /home/or/cvsroot/src/or/connection.c,v
retrieving revision 1.163
retrieving revision 1.164
diff -u -d -r1.163 -r1.164
--- connection.c	28 Feb 2004 11:48:22 -0000	1.163
+++ connection.c	28 Feb 2004 19:14:11 -0000	1.164
@@ -141,6 +141,22 @@
     connection_free(carray[i]);
 }
 
+/* Close the underlying socket for conn, so we don't try to flush it.
+ * Must be used in conjunction with connection_mark_for_close
+ */
+void connection_close_immediate(connection_t *conn)
+{
+  assert_connection_ok(conn,0);
+  if (conn->s < 0) {
+    log_fn(LOG_WARN,"Attempt to close already-closed connection.");
+    return;
+  }
+  close(conn->s);
+  conn->s = -1;
+  buf_clear(conn->outbuf);
+  conn->outbuf_flushlen = 0;
+}
+
 int
 _connection_mark_for_close(connection_t *conn, char reason)
 {
@@ -355,8 +371,7 @@
          type == CONN_TYPE_DIR_LISTENER);
   conn = connection_get_by_type(type);
   if (conn) {
-    close(conn->s);
-    conn->s = -1;
+    connection_close_immediate(conn);
     connection_mark_for_close(conn,0);
   }
 }
@@ -414,9 +429,7 @@
        router_mark_as_down(conn->nickname);
     }
     /* There's a read error; kill the connection.*/
-    /* XXX This is the place. We need to somehow indicate to
-     * conn that it should never try to flush, or do anything
-     * with conn->s but close it. */
+    connection_close_immediate(conn); /* Don't flush; connection is dead. */
     connection_mark_for_close(conn, END_STREAM_REASON_MISC);
     return -1;
   }

Index: main.c
===================================================================
RCS file: /home/or/cvsroot/src/or/main.c,v
retrieving revision 1.178
retrieving revision 1.179
diff -u -d -r1.178 -r1.179
--- main.c	28 Feb 2004 11:48:22 -0000	1.178
+++ main.c	28 Feb 2004 19:14:11 -0000	1.179
@@ -221,10 +221,10 @@
   assert_connection_ok(conn, time(NULL));
   if(conn->marked_for_close) {
     log_fn(LOG_INFO,"Cleaning up connection (fd %d).",conn->s);
-    if(conn->s >= 0) { /* -1 means it's an incomplete edge connection */
+    if(conn->s >= 0) {
+      /* -1 means it's an incomplete edge connection, or that the socket
+       * has already been closed as unflushable. */
       /* FIXME there's got to be a better way to check for this -- and make other checks? */
-/* XXX the below two calls to flush_buf should not happen if the
- * conn got hung up on. */
       if(connection_speaks_cells(conn)) {
         if(conn->state == OR_CONN_STATE_OPEN)
           flush_buf_tls(conn->tls, conn->outbuf, &conn->outbuf_flushlen);

Index: or.h
===================================================================
RCS file: /home/or/cvsroot/src/or/or.h,v
retrieving revision 1.234
retrieving revision 1.235
diff -u -d -r1.234 -r1.235
--- or.h	28 Feb 2004 05:09:37 -0000	1.234
+++ or.h	28 Feb 2004 19:14:11 -0000	1.235
@@ -549,6 +549,7 @@
 buf_t *buf_new();
 buf_t *buf_new_with_capacity(size_t size);
 void buf_free(buf_t *buf);
+void buf_clear(buf_t *buf);
 
 size_t buf_datalen(const buf_t *buf);
 size_t buf_capacity(const buf_t *buf);
@@ -637,7 +638,7 @@
 connection_t *connection_new(int type);
 void connection_free(connection_t *conn);
 void connection_free_all(void);
-
+void connection_close_immediate(connection_t *conn);
 int _connection_mark_for_close(connection_t *conn, char reason);
 
 #define connection_mark_for_close(c,r)                                  \



More information about the tor-commits mailing list