diff options
author | Nick Mathewson <nickm@torproject.org> | 2011-07-18 15:36:20 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2011-07-18 15:36:20 -0400 |
commit | 34a52534bb43b30e19267968807a540ba33abe3b (patch) | |
tree | add85f5570fa7d6a8cf597c1e497f6880977e917 /src/or/buffers.h | |
parent | 1e441df2d0d06aa66eaf2c0e00a42d7fe9c39c87 (diff) | |
download | tor-34a52534bb43b30e19267968807a540ba33abe3b.tar.gz tor-34a52534bb43b30e19267968807a540ba33abe3b.zip |
Add a generic_buffer_t to use the best buffer type we have on hand
Also add a quick function to copy all the data in a buffer. (This
one could be done much better, but let's see if it matters.)
Diffstat (limited to 'src/or/buffers.h')
-rw-r--r-- | src/or/buffers.h | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/or/buffers.h b/src/or/buffers.h index b0161b9c2c..7b2a2acc3c 100644 --- a/src/or/buffers.h +++ b/src/or/buffers.h @@ -16,6 +16,7 @@ buf_t *buf_new(void); buf_t *buf_new_with_capacity(size_t size); void buf_free(buf_t *buf); void buf_clear(buf_t *buf); +buf_t *buf_copy(const buf_t *buf); void buf_shrink(buf_t *buf); void buf_shrink_freelists(int free_all); void buf_dump_freelist_sizes(int severity); @@ -67,6 +68,24 @@ int write_to_evbuffer_zlib(struct evbuffer *buf, tor_zlib_state_t *state, int done); #endif +#ifdef USE_BUFFEREVENTS +#define generic_buffer_new() evbuffer_new() +#define generic_buffer_len(b) evbuffer_get_length((b)) +#define generic_buffer_add(b,dat,len) evbuffer_add((b),(dat),(len)) +#define generic_buffer_get(b,buf,buflen) evbuffer_remove((b),(buf),(buflen)) +#define generic_buffer_clear(b) evbuffer_drain((b), evbuffer_get_length((b))) +#define generic_buffer_free(b) evbuffer_free((b)) +#else +#define generic_buffer_new() buf_new() +#define generic_buffer_len(b) buf_datalen((b)) +#define generic_buffer_add(b,dat,len) write_to_buf((dat),(len),(b)) +#define generic_buffer_get(b,buf,buflen) fetch_from_buf((buf),(buflen),(b)) +#define generic_buffer_clear(b) buf_clear((b)) +#define generic_buffer_free(b) buf_free((b)) +#endif +int generic_buffer_set_to_copy(generic_buffer_t **output, + const generic_buffer_t *input); + void assert_buf_ok(buf_t *buf); #ifdef BUFFERS_PRIVATE |