From: Roger Dingledine Date: Sun, 28 Sep 2003 06:48:20 +0000 (+0000) Subject: expand the scheduler to address SSL_read()'s pending bytes X-Git-Tag: tor-0.0.2pre13~126 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c4c66e2c7f1184336d5a9997d049ba4e28137c39;p=thirdparty%2Ftor.git expand the scheduler to address SSL_read()'s pending bytes svn:r505 --- diff --git a/src/or/connection.c b/src/or/connection.c index 20522b848e..5c97142e4c 100644 --- a/src/or/connection.c +++ b/src/or/connection.c @@ -25,7 +25,7 @@ char *conn_type_to_string[] = { "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 @@ int connection_read_to_buf(connection_t *conn) { 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; } diff --git a/src/or/main.c b/src/or/main.c index 5421c96ea8..9f861b96cc 100644 --- a/src/or/main.c +++ b/src/or/main.c @@ -261,14 +261,17 @@ void connection_start_writing(connection_t *conn) { } 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 void check_conn_marked(int i) { 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 @@ static int prepare_for_poll(void) { 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 @@ static int prepare_for_poll(void) { /* 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 @@ static int prepare_for_poll(void) { } } /* 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