From 27220fb395c2e5384c018ffb1f2854fe1cfd6208 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Wed, 26 Dec 2007 19:02:15 +0000 Subject: [PATCH] r15719@tombo: nickm | 2007-12-26 14:02:12 -0500 More tweaks on 0-byte TLS writes. svn:r12989 --- src/or/buffers.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/or/buffers.c b/src/or/buffers.c index bf57a7a87c..7cc32061e9 100644 --- a/src/or/buffers.c +++ b/src/or/buffers.c @@ -231,8 +231,9 @@ buf_shrink_freelists(int free_all) int n_to_skip = freelists[i].cur_length - n_to_free; chunk_t **chp = &freelists[i].head; chunk_t *chunk; - log_notice(LD_MM, "FL for %d: keep %d, drop %d.", - (int)freelists[i].alloc_size, n_to_skip, n_to_free); + log_info(LD_MM, "Cleaning freelist for %d-byte chunks: keeping %d, " + "dropping %d.", + (int)freelists[i].alloc_size, n_to_skip, n_to_free); while (n_to_skip) { tor_assert((*chp)->next); chp = &(*chp)->next; @@ -666,16 +667,23 @@ flush_chunk(int s, buf_t *buf, chunk_t *chunk, size_t sz, static INLINE int flush_chunk_tls(tor_tls_t *tls, buf_t *buf, chunk_t *chunk, - size_t sz, size_t *buf_flushlen) + size_t sz, size_t *buf_flushlen) { int r; size_t forced; + char *data; forced = tor_tls_get_forced_write_size(tls); if (forced > sz) sz = forced; - tor_assert(sz <= chunk->datalen); - r = tor_tls_write(tls, chunk->data, sz); + if (chunk) { + data = chunk->data; + tor_assert(sz <= chunk->datalen); + } else { + data = NULL; + tor_assert(sz == 0); + } + r = tor_tls_write(tls, data, sz); if (r < 0) return r; if (*buf_flushlen > (size_t)r) @@ -742,7 +750,7 @@ flush_buf_tls(tor_tls_t *tls, buf_t *buf, size_t flushlen, size_t *buf_flushlen) check_no_tls_errors(); check(); - while (sz >= 0) { + do { size_t flushlen0; if (buf->head) { if ((ssize_t)buf->head->datalen >= sz) @@ -759,7 +767,7 @@ flush_buf_tls(tor_tls_t *tls, buf_t *buf, size_t flushlen, size_t *buf_flushlen) return r; flushed += r; sz -= r; - } + } while (sz > 0); return flushed; }