[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] expand the scheduler to address SSL_read()"s pending bytes



Update of /home/or/cvsroot/src/or
In directory moria.mit.edu:/home2/arma/work/onion/cvs/src/or

Modified Files:
	connection.c main.c routers.c 
Log Message:
expand the scheduler to address SSL_read()'s pending bytes


Index: connection.c
===================================================================
RCS file: /home/or/cvsroot/src/or/connection.c,v
retrieving revision 1.107
retrieving revision 1.108
diff -u -d -r1.107 -r1.108
--- connection.c	27 Sep 2003 21:30:10 -0000	1.107
+++ connection.c	28 Sep 2003 06:48:20 -0000	1.108
@@ -25,7 +25,7 @@
   "CPU worker",  /* 11 */
 };
 
-char *conn_state_to_string[][15] = {
+char *conn_state_to_string[][_CONN_TYPE_MAX+1] = {
 	{ NULL },         /* no type associated with 0 */
   { "ready" }, /* op listener, 0 */
   { "awaiting keys", /* op, 0 */
@@ -509,9 +509,6 @@
       return 0;
     }
   }
-  if(connection_speaks_cells(conn) && conn->state != OR_CONN_STATE_CONNECTING)
-    if(result == at_most)
-      return connection_read_to_buf(conn);
   return 0;
 }
 

Index: main.c
===================================================================
RCS file: /home/or/cvsroot/src/or/main.c,v
retrieving revision 1.108
retrieving revision 1.109
diff -u -d -r1.108 -r1.109
--- main.c	27 Sep 2003 21:30:10 -0000	1.108
+++ main.c	28 Sep 2003 06:48:20 -0000	1.109
@@ -261,14 +261,17 @@
 }
 
 static void conn_read(int i) {
-  connection_t *conn;
+  connection_t *conn = connection_array[i];
 
+  /* see http://www.greenend.org.uk/rjk/2001/06/poll.html for
+   * discussion of POLLIN vs POLLHUP */
   if(!(poll_array[i].revents & (POLLIN|POLLHUP|POLLERR)))
-    return; /* this conn doesn't want to read */
-    /* see http://www.greenend.org.uk/rjk/2001/06/poll.html for
-     * discussion of POLLIN vs POLLHUP */
+    if(!connection_speaks_cells(conn) ||
+       conn->state != OR_CONN_STATE_OPEN ||
+       !connection_is_reading(conn) ||
+       !tor_tls_get_pending_bytes(conn->tls)) 
+      return; /* this conn should not read */
 
-  conn = connection_array[i];
   log_fn(LOG_DEBUG,"socket %d wants to read.",conn->s);
  
   assert_connection_ok(conn, time(NULL));
@@ -340,8 +343,9 @@
 
 static int prepare_for_poll(void) {
   int i;
+  int timeout;
   connection_t *conn;
-  struct timeval now; //soonest;
+  struct timeval now;
   static long current_second = 0; /* from previous calls to gettimeofday */
   static long time_to_fetch_directory = 0;
   static long time_to_new_circuit = 0;
@@ -350,6 +354,7 @@
   circuit_t *circ;
 
   my_gettimeofday(&now);
+  timeout = (1000 - (now.tv_usec / 1000)); /* how many milliseconds til the next second? */
 
   if(now.tv_sec > current_second) { /* the second has rolled over. check more stuff. */
 
@@ -404,6 +409,8 @@
       /* check connections to see whether we should send a keepalive, expire, or wait */
       if(!connection_speaks_cells(conn))
         continue; /* this conn type doesn't send cells */
+      if(connection_state_is_open(conn) && tor_tls_get_pending_bytes(conn->tls))
+        timeout = 0; /* has pending bytes to read; don't let poll wait. */
       if(now.tv_sec >= conn->timestamp_lastwritten + options.KeepalivePeriod) {
         if((!options.OnionRouter && !circuit_get_by_conn(conn)) ||
            (!connection_state_is_open(conn))) {
@@ -423,7 +430,8 @@
       }
     }
     /* blow away any connections that need to die. can't do this later
-     * because we might open up a circuit and not realize it we're about to cull it.
+     * because we might open up a circuit and not realize we're about to cull
+     * the connection it's running over.
      */
     for(i=0;i<nfds;i++)
       check_conn_marked(i); 
@@ -431,7 +439,7 @@
     current_second = now.tv_sec; /* remember which second it is, for next time */
   }
 
-  return (1000 - (now.tv_usec / 1000)); /* how many milliseconds til the next second? */
+  return timeout;
 }
 
 static crypto_pk_env_t *init_key_from_file(const char *fname)
@@ -828,6 +836,7 @@
     length += strlen(nickname_lst[i]);
   }
   *nicknames_out = tor_malloc(length);
+  log_fn(LOG_DEBUG,"total length %d malloced.",length);
   cp = *nicknames_out;
   for (i = 0; i<n; ++i) {
     if (i)
@@ -835,6 +844,8 @@
     strcat(cp, nickname_lst[i]);
     while (*cp) 
       ++cp;
+    log_fn(LOG_DEBUG,"end of loop %d, now %d written (nick %s)",
+           i,1+(int)(cp-*nicknames_out),nickname_lst[i]);
   }
   return 0;
 }

Index: routers.c
===================================================================
RCS file: /home/or/cvsroot/src/or/routers.c,v
retrieving revision 1.55
retrieving revision 1.56
diff -u -d -r1.55 -r1.56
--- routers.c	27 Sep 2003 21:30:10 -0000	1.55
+++ routers.c	28 Sep 2003 06:48:20 -0000	1.56
@@ -260,42 +260,14 @@
 /* load the router list */
 int router_get_list_from_file(char *routerfile)
 {
-  int fd; /* router file */
-  struct stat statbuf;
   char *string;
 
-  assert(routerfile);
-  
-  if (strcspn(routerfile,CONFIG_LEGAL_FILENAME_CHARACTERS) != 0) {
-    log_fn(LOG_WARNING,"Filename %s contains illegal characters.",routerfile);
-    return -1;
-  }
-  
-  if(stat(routerfile, &statbuf) < 0) {
-    log_fn(LOG_WARNING,"Could not stat %s.",routerfile);
-    return -1;
-  }
-
-  /* open the router list */
-  fd = open(routerfile,O_RDONLY,0);
-  if (fd<0) {
-    log_fn(LOG_WARNING,"Could not open %s.",routerfile);
-    return -1;
-  }
-
-  string = tor_malloc(statbuf.st_size+1);
-
-  if(read(fd,string,statbuf.st_size) != statbuf.st_size) {
-    log_fn(LOG_WARNING,"Couldn't read all %ld bytes of file '%s'.",
-           (long)statbuf.st_size,routerfile);
-    free(string);
-    close(fd);
+  string = read_file_to_str(routerfile);
+  if(!string) {
+    log_fn(LOG_WARNING,"Failed to load routerfile %s.",routerfile);
     return -1;
   }
-  close(fd);
   
-  string[statbuf.st_size] = 0; /* null terminate it */
-
   if(router_get_list_from_string(string) < 0) {
     log_fn(LOG_WARNING,"The routerfile itself was corrupt.");
     free(string);