Actually call channel_flush_some_cells() from the scheduler

This commit is contained in:
Andrea Shepard 2013-10-31 19:37:57 -07:00
parent 2efbab2aaf
commit b09f41424c
2 changed files with 11 additions and 34 deletions

View File

@ -581,9 +581,7 @@ connection_or_process_inbuf(or_connection_t *conn)
int int
connection_or_flushed_some(or_connection_t *conn) connection_or_flushed_some(or_connection_t *conn)
{ {
size_t datalen, temp; size_t datalen;
ssize_t n, flushed;
size_t cell_network_size = get_cell_network_size(conn->wide_circ_ids);
/* If we're under the low water mark, add cells until we're just over the /* If we're under the low water mark, add cells until we're just over the
* high water mark. */ * high water mark. */
@ -591,31 +589,6 @@ connection_or_flushed_some(or_connection_t *conn)
if (datalen < OR_CONN_LOWWATER) { if (datalen < OR_CONN_LOWWATER) {
/* Let the scheduler know */ /* Let the scheduler know */
scheduler_channel_wants_writes(TLS_CHAN_TO_BASE(conn->chan)); scheduler_channel_wants_writes(TLS_CHAN_TO_BASE(conn->chan));
/*
* TODO this will be done from the scheduler, so it will
* need a generic way to ask how many cells a channel can
* accept and if it still wants writes or not to know how
* to account for it in the case that it runs out of cells
* to send first.
*/
while ((conn->chan) && channel_tls_more_to_flush(conn->chan)) {
/* Compute how many more cells we want at most */
n = CEIL_DIV(OR_CONN_HIGHWATER - datalen, cell_network_size);
/* Bail out if we don't want any more */
if (n <= 0) break;
/* We're still here; try to flush some more cells */
flushed = channel_tls_flush_some_cells(conn->chan, n);
/* Bail out if it says it didn't flush anything */
if (flushed <= 0) break;
/* How much in the outbuf now? */
temp = connection_get_outbuf_len(TO_CONN(conn));
/* Bail out if we didn't actually increase the outbuf size */
if (temp <= datalen) break;
/* Update datalen for the next iteration */
datalen = temp;
}
} }
return 0; return 0;

View File

@ -325,18 +325,15 @@ scheduler_run(void)
{ {
smartlist_t *tmp = NULL; smartlist_t *tmp = NULL;
int n_cells; int n_cells;
ssize_t flushed, flushed_this_time;
log_debug(LD_SCHED, "We have a chance to run the scheduler"); log_debug(LD_SCHED, "We have a chance to run the scheduler");
/*
* TODO make this work properly
*
* For now, just empty the pending list and log that we saw stuff in it
*/
tmp = channels_pending; tmp = channels_pending;
channels_pending = smartlist_new(); channels_pending = smartlist_new();
/* For now, just run the old scheduler on all the chans in the list */
SMARTLIST_FOREACH_BEGIN(tmp, channel_t *, chan) { SMARTLIST_FOREACH_BEGIN(tmp, channel_t *, chan) {
n_cells = channel_num_cells_writeable(chan); n_cells = channel_num_cells_writeable(chan);
if (n_cells > 0) { if (n_cells > 0) {
@ -344,6 +341,13 @@ scheduler_run(void)
"Scheduler saw pending channel " U64_FORMAT " at %p with " "Scheduler saw pending channel " U64_FORMAT " at %p with "
"%d cells writeable", "%d cells writeable",
U64_PRINTF_ARG(chan->global_identifier), chan, n_cells); U64_PRINTF_ARG(chan->global_identifier), chan, n_cells);
flushed = 0;
while (flushed < n_cells) {
flushed_this_time = channel_flush_some_cells(chan, n_cells - flushed);
if (flushed_this_time <= 0) break;
flushed += flushed_this_time;
}
} else { } else {
log_info(LD_SCHED, log_info(LD_SCHED,
"Scheduler saw pending channel " U64_FORMAT " at %p with " "Scheduler saw pending channel " U64_FORMAT " at %p with "