diff options
-rw-r--r-- | src/or/connection.c | 10 | ||||
-rw-r--r-- | src/or/main.c | 3 | ||||
-rw-r--r-- | src/or/or.h | 3 |
3 files changed, 12 insertions, 4 deletions
diff --git a/src/or/connection.c b/src/or/connection.c index 56643fd97..50903cf36 100644 --- a/src/or/connection.c +++ b/src/or/connection.c @@ -494,7 +494,7 @@ void connection_bucket_decrement(connection_t *conn, int num_read) { /* keep a timeval to know when time has passed enough to refill buckets */ static struct timeval current_time; -void connection_bucket_init() { +void connection_bucket_init(void) { tor_gettimeofday(¤t_time); global_read_bucket = options.BandwidthBurst; /* start it at max traffic */ } @@ -533,6 +533,7 @@ void connection_bucket_refill(struct timeval *now) { conn->state != OR_CONN_STATE_OPEN || conn->receiver_bucket > 0)) { /* and either a non-cell conn or a cell conn with non-empty bucket */ + log_fn(LOG_DEBUG,"waking up conn (fd %d)",conn->s); conn->wants_to_read = 0; connection_start_reading(conn); if(conn->wants_to_write == 1) { @@ -600,8 +601,10 @@ int connection_read_to_buf(connection_t *conn) { at_most = connection_bucket_read_limit(conn); if(connection_speaks_cells(conn) && conn->state != OR_CONN_STATE_CONNECTING) { - if(conn->state == OR_CONN_STATE_HANDSHAKING) + if(conn->state == OR_CONN_STATE_HANDSHAKING) { + /* continue handshaking even if global token bucket is empty */ return connection_tls_continue_handshake(conn); + } /* else open, or closing */ result = read_to_buf_tls(conn->tls, at_most, conn->inbuf); @@ -616,7 +619,8 @@ int connection_read_to_buf(connection_t *conn) { return 0; case TOR_TLS_WANTREAD: /* we're already reading */ case TOR_TLS_DONE: /* no data read, so nothing to process */ - return 0; + result = 0; + break; /* so we call bucket_decrement below */ } } else { result = read_to_buf(conn->s, at_most, conn->inbuf, diff --git a/src/or/main.c b/src/or/main.c index e3c5a5a8c..356dbc094 100644 --- a/src/or/main.c +++ b/src/or/main.c @@ -421,7 +421,8 @@ static int prepare_for_poll(void) { for(i=0;i<nfds;i++) { conn = connection_array[i]; - if(connection_has_pending_tls_data(conn)) { + if(connection_has_pending_tls_data(conn) && + connection_is_reading(conn)) { log_fn(LOG_DEBUG,"sock %d has pending bytes.",conn->s); return 0; /* has pending bytes to read; don't let poll wait. */ } diff --git a/src/or/or.h b/src/or/or.h index e25a0692c..8efbba62f 100644 --- a/src/or/or.h +++ b/src/or/or.h @@ -693,6 +693,9 @@ int connection_create_listener(char *bindaddress, uint16_t bindport, int type); int connection_connect(connection_t *conn, char *address, uint32_t addr, uint16_t port); int retry_all_connections(void); +void connection_bucket_init(void); +void connection_bucket_refill(struct timeval *now); + int connection_handle_read(connection_t *conn); int connection_read_to_buf(connection_t *conn); |