summaryrefslogtreecommitdiff
path: root/src/or/buffers.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2005-05-02 23:17:08 +0000
committerNick Mathewson <nickm@torproject.org>2005-05-02 23:17:08 +0000
commita312ce1d3b77522b08e91e1524c91e9dfb05f90a (patch)
tree2d5278d8d300931542417c7272c8eec18bcad4bc /src/or/buffers.c
parent9c683c7613ba5d15477e7f21d74cc465e82ac5bd (diff)
downloadtor-a312ce1d3b77522b08e91e1524c91e9dfb05f90a.tar.gz
tor-a312ce1d3b77522b08e91e1524c91e9dfb05f90a.zip
Change buffer shrinking strategy: only try to shrink once every 3 minutes. Do not try to read over buffer size unless buffer is nearly empty.
svn:r4165
Diffstat (limited to 'src/or/buffers.c')
-rw-r--r--src/or/buffers.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/or/buffers.c b/src/or/buffers.c
index d1ae871c63..8aaa962dec 100644
--- a/src/or/buffers.c
+++ b/src/or/buffers.c
@@ -118,7 +118,7 @@ static INLINE void _split_range(buf_t *buf, char *at, size_t *len,
}
/** Change a buffer's capacity. <b>new_capacity</b> must be \>= buf->datalen. */
-static INLINE void buf_resize(buf_t *buf, size_t new_capacity)
+static void buf_resize(buf_t *buf, size_t new_capacity)
{
off_t offset;
#ifdef CHECK_AFTER_RESIZE
@@ -134,6 +134,9 @@ static INLINE void buf_resize(buf_t *buf, size_t new_capacity)
peek_from_buf(tmp, buf->datalen, buf);
#endif
+ if (buf->len == new_capacity)
+ return;
+
offset = buf->cur - buf->mem;
if (offset + buf->datalen >= new_capacity) {
/* We need to move stuff before we shrink. */
@@ -214,6 +217,7 @@ static INLINE int buf_ensure_capacity(buf_t *buf, size_t capacity)
return 0;
}
+#if 0
/** If the buffer is at least 2*MIN_GREEDY_SHRINK_SIZE bytes in capacity,
* and if the buffer is less than 1/8 full, shrink the buffer until
* one of the above no longer holds. (We shrink the buffer by
@@ -236,6 +240,9 @@ static INLINE void buf_shrink_if_underfull(buf_t *buf) {
(int)buf->len, (int)new_len);
buf_resize(buf, new_len);
}
+#else
+#define buf_shrink_if_underfull(buf) do {} while (0)
+#endif
void
buf_shrink(buf_t *buf)
@@ -278,13 +285,11 @@ static INLINE int buf_nul_terminate(buf_t *buf)
*/
buf_t *buf_new_with_capacity(size_t size) {
buf_t *buf;
- buf = tor_malloc(sizeof(buf_t));
+ buf = tor_malloc_zero(sizeof(buf_t));
buf->magic = BUFFER_MAGIC;
buf->cur = buf->mem = GUARDED_MEM(tor_malloc(ALLOC_LEN(size)));
SET_GUARDS(buf->mem, size);
buf->len = size;
- buf->datalen = 0;
-// memset(buf->mem,0,size);
assert_buf_ok(buf);
return buf;