diff options
author | Nick Mathewson <nickm@torproject.org> | 2007-04-21 17:26:12 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2007-04-21 17:26:12 +0000 |
commit | 648065fcb4604bcd8abaa86ae1d8c8ef767631df (patch) | |
tree | bc0d6a488ee0bb317cdb7bca18a0113b519462b2 /src/or/buffers.c | |
parent | 227b2e0226445d0c4f39572f51f55451f9fa90f3 (diff) | |
download | tor-648065fcb4604bcd8abaa86ae1d8c8ef767631df.tar.gz tor-648065fcb4604bcd8abaa86ae1d8c8ef767631df.zip |
r12763@Kushana: nickm | 2007-04-20 18:42:58 -0400
Initial version of code to stop using socket pairs for linked connections. Superficially, it seems to work, but it probably needs a lot more testing and attention.
svn:r9995
Diffstat (limited to 'src/or/buffers.c')
-rw-r--r-- | src/or/buffers.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/or/buffers.c b/src/or/buffers.c index 2caec58603..40f8a557ce 100644 --- a/src/or/buffers.c +++ b/src/or/buffers.c @@ -817,6 +817,32 @@ fetch_from_buf(char *string, size_t string_len, buf_t *buf) return buf->datalen; } +/** Move up to <b>buf_flushlen</b> bytes from <b>buf_in</b> to <b>buf_out</b>. + * Return the number of bytes actually copied. + */ +int +move_buf_to_buf(buf_t *buf_out, buf_t *buf_in, size_t *buf_flushlen) +{ + char b[4096]; + size_t cp, len; + len = *buf_flushlen; + if (len > buf_in->datalen) + len = buf_in->datalen; + + cp = len; /* Remember the number of bytes we intend to copy. */ + while (len) { + /* This isn't the most efficient implementation one could imagine, since + * it does two copies instead of 1, but I kinda doubt that this will be + * critical path. */ + size_t n = len > sizeof(b) ? sizeof(b) : len; + fetch_from_buf(b, n, buf_in); + write_to_buf(b, n, buf_out); + len -= n; + } + *buf_flushlen -= cp; + return cp; +} + /** There is a (possibly incomplete) http statement on <b>buf</b>, of the * form "\%s\\r\\n\\r\\n\%s", headers, body. (body may contain nuls.) * If a) the headers include a Content-Length field and all bytes in |