/** We just read num_read onto conn. Decrement buckets appropriately. */
static void connection_read_bucket_decrement(connection_t *conn, int num_read) {
- global_read_bucket -= num_read; tor_assert(global_read_bucket >= 0);
+ global_read_bucket -= num_read; //tor_assert(global_read_bucket >= 0);
if (connection_speaks_cells(conn) && conn->state == OR_CONN_STATE_OPEN) {
- conn->receiver_bucket -= num_read; tor_assert(conn->receiver_bucket >= 0);
+ conn->receiver_bucket -= num_read; //tor_assert(conn->receiver_bucket >= 0);
}
}
static void connection_consider_empty_buckets(connection_t *conn) {
- if (global_read_bucket == 0) {
+ if (global_read_bucket <= 0) {
log_fn(LOG_DEBUG,"global bucket exhausted. Pausing.");
conn->wants_to_read = 1;
connection_stop_reading(conn);
}
if (connection_speaks_cells(conn) &&
conn->state == OR_CONN_STATE_OPEN &&
- conn->receiver_bucket == 0) {
+ conn->receiver_bucket <= 0) {
log_fn(LOG_DEBUG,"receiver bucket exhausted. Pausing.");
conn->wants_to_read = 1;
connection_stop_reading(conn);
or_options_t *options = get_options();
/* refill the global buckets */
- if ((unsigned)global_read_bucket < options->BandwidthBurst) {
+ if (global_read_bucket < (int)options->BandwidthBurst) {
global_read_bucket += (int)options->BandwidthRate;
log_fn(LOG_DEBUG,"global_read_bucket now %d.", global_read_bucket);
}
- if ((unsigned)global_write_bucket < options->BandwidthBurst) {
+ if (global_write_bucket < (int)options->BandwidthBurst) {
global_write_bucket += (int)options->BandwidthRate;
log_fn(LOG_DEBUG,"global_write_bucket now %d.", global_write_bucket);
}
}
if (!conn->marked_for_close &&
connection_is_reading(conn) &&
- !conn->inbuf_reached_eof)
+ !conn->inbuf_reached_eof &&
+ max_to_read > 0)
goto loop_again; /* try reading again, in case more is here now */
}
/* one last try, packaging partial cells and all. */
int r2 = read_to_buf_tls(conn->tls, pending, conn->inbuf);
if (r2<0) {
log_fn(LOG_WARN, "Bug: apparently, reading pending bytes can fail.");
+ return -1;
} else {
result += r2;
}
* gave a bad cert/etc, then we won't have assigned bandwidth,
* yet it will be open. -RD
*/
- tor_assert(conn->receiver_bucket >= 0);
+// tor_assert(conn->receiver_bucket >= 0);
}
tor_assert(conn->addr && conn->port);
tor_assert(conn->address);