summaryrefslogtreecommitdiff
path: root/src/common/buffers.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/buffers.c')
-rw-r--r--src/common/buffers.c48
1 files changed, 24 insertions, 24 deletions
diff --git a/src/common/buffers.c b/src/common/buffers.c
index 1a9144e14b..683952ddf2 100644
--- a/src/common/buffers.c
+++ b/src/common/buffers.c
@@ -36,7 +36,7 @@
#ifdef PARANOIA
/** Helper: If PARANOIA is defined, assert that the buffer in local variable
* <b>buf</b> is well-formed. */
-#define check() STMT_BEGIN assert_buf_ok(buf); STMT_END
+#define check() STMT_BEGIN buf_assert_ok(buf); STMT_END
#else
#define check() STMT_NIL
#endif
@@ -282,14 +282,14 @@ buf_new_with_data(const char *cp, size_t sz)
/* Allocate a buffer */
buf_t *buf = buf_new_with_capacity(sz);
tor_assert(buf);
- assert_buf_ok(buf);
+ buf_assert_ok(buf);
tor_assert(!buf->head);
/* Allocate a chunk that is sz bytes long */
buf->head = chunk_new_with_alloc_size(CHUNK_ALLOC_SIZE(sz));
buf->tail = buf->head;
tor_assert(buf->head);
- assert_buf_ok(buf);
+ buf_assert_ok(buf);
tor_assert(buf_allocation(buf) >= sz);
/* Copy the data and size the buffers */
@@ -299,7 +299,7 @@ buf_new_with_data(const char *cp, size_t sz)
buf->datalen = sz;
buf->head->datalen = sz;
buf->head->data = &buf->head->mem[0];
- assert_buf_ok(buf);
+ buf_assert_ok(buf);
/* Make sure everything is large enough */
tor_assert(buf_allocation(buf) >= sz);
@@ -315,7 +315,7 @@ buf_new_with_data(const char *cp, size_t sz)
/** Remove the first <b>n</b> bytes from buf. */
void
-buf_remove_from_front(buf_t *buf, size_t n)
+buf_drain(buf_t *buf, size_t n)
{
tor_assert(buf->datalen >= n);
while (n) {
@@ -551,7 +551,7 @@ read_to_chunk(buf_t *buf, chunk_t *chunk, tor_socket_t fd, size_t at_most,
*/
/* XXXX indicate "read blocked" somehow? */
int
-read_to_buf(tor_socket_t s, size_t at_most, buf_t *buf, int *reached_eof,
+buf_read_from_socket(tor_socket_t s, size_t at_most, buf_t *buf, int *reached_eof,
int *socket_error)
{
/* XXXX It's stupid to overload the return values for these functions:
@@ -596,7 +596,7 @@ read_to_buf(tor_socket_t s, size_t at_most, buf_t *buf, int *reached_eof,
return (int)total_read;
}
-/** Helper for flush_buf(): try to write <b>sz</b> bytes from chunk
+/** Helper for buf_flush_to_socket(): try to write <b>sz</b> bytes from chunk
* <b>chunk</b> of buffer <b>buf</b> onto socket <b>s</b>. On success, deduct
* the bytes written from *<b>buf_flushlen</b>. Return the number of bytes
* written on success, 0 on blocking, -1 on failure.
@@ -624,7 +624,7 @@ flush_chunk(tor_socket_t s, buf_t *buf, chunk_t *chunk, size_t sz,
return 0;
} else {
*buf_flushlen -= write_result;
- buf_remove_from_front(buf, write_result);
+ buf_drain(buf, write_result);
tor_assert(write_result < INT_MAX);
return (int)write_result;
}
@@ -637,7 +637,7 @@ flush_chunk(tor_socket_t s, buf_t *buf, chunk_t *chunk, size_t sz,
* -1 on failure. Return 0 if write() would block.
*/
int
-flush_buf(tor_socket_t s, buf_t *buf, size_t sz, size_t *buf_flushlen)
+buf_flush_to_socket(tor_socket_t s, buf_t *buf, size_t sz, size_t *buf_flushlen)
{
/* XXXX It's stupid to overload the return values for these functions:
* "error status" and "number of bytes flushed" are not mutually exclusive.
@@ -677,7 +677,7 @@ flush_buf(tor_socket_t s, buf_t *buf, size_t sz, size_t *buf_flushlen)
* Return the new length of the buffer on success, -1 on failure.
*/
int
-write_to_buf(const char *string, size_t string_len, buf_t *buf)
+buf_add(const char *string, size_t string_len, buf_t *buf)
{
if (!string_len)
return (int)buf->datalen;
@@ -712,14 +712,14 @@ write_to_buf(const char *string, size_t string_len, buf_t *buf)
* onto <b>string</b>.
*/
void
-peek_from_buf(char *string, size_t string_len, const buf_t *buf)
+buf_peek(char *string, size_t string_len, const buf_t *buf)
{
chunk_t *chunk;
tor_assert(string);
/* make sure we don't ask for too much */
tor_assert(string_len <= buf->datalen);
- /* assert_buf_ok(buf); */
+ /* buf_assert_ok(buf); */
chunk = buf->head;
while (string_len) {
@@ -739,7 +739,7 @@ peek_from_buf(char *string, size_t string_len, const buf_t *buf)
* must be \<= the number of bytes on the buffer.
*/
int
-fetch_from_buf(char *string, size_t string_len, buf_t *buf)
+buf_get_bytes(char *string, size_t string_len, buf_t *buf)
{
/* There must be string_len bytes in buf; write them onto string,
* then memmove buf back (that is, remove them from buf).
@@ -747,8 +747,8 @@ fetch_from_buf(char *string, size_t string_len, buf_t *buf)
* Return the number of bytes still on the buffer. */
check();
- peek_from_buf(string, string_len, buf);
- buf_remove_from_front(buf, string_len);
+ buf_peek(string, string_len, buf);
+ buf_drain(buf, string_len);
check();
tor_assert(buf->datalen < INT_MAX);
return (int)buf->datalen;
@@ -759,7 +759,7 @@ fetch_from_buf(char *string, size_t string_len, buf_t *buf)
* Return the number of bytes actually copied.
*/
int
-move_buf_to_buf(buf_t *buf_out, buf_t *buf_in, size_t *buf_flushlen)
+buf_move_to_buf(buf_t *buf_out, buf_t *buf_in, size_t *buf_flushlen)
{
/* We can do way better here, but this doesn't turn up in any profiles. */
char b[4096];
@@ -781,8 +781,8 @@ move_buf_to_buf(buf_t *buf_out, buf_t *buf_in, size_t *buf_flushlen)
* 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);
+ buf_get_bytes(b, n, buf_in);
+ buf_add(b, n, buf_out);
len -= n;
}
*buf_flushlen -= cp;
@@ -901,7 +901,7 @@ buf_find_string_offset(const buf_t *buf, const char *s, size_t n)
/** Return 1 iff <b>buf</b> starts with <b>cmd</b>. <b>cmd</b> must be a null
* terminated string, of no more than PEEK_BUF_STARTSWITH_MAX bytes. */
int
-peek_buf_startswith(const buf_t *buf, const char *cmd)
+buf_peek_startswith(const buf_t *buf, const char *cmd)
{
char tmp[PEEK_BUF_STARTSWITH_MAX];
size_t clen = strlen(cmd);
@@ -909,7 +909,7 @@ peek_buf_startswith(const buf_t *buf, const char *cmd)
return 0;
if (buf->datalen < clen)
return 0;
- peek_from_buf(tmp, clen, buf);
+ buf_peek(tmp, clen, buf);
return fast_memeq(tmp, cmd, clen);
}
@@ -938,7 +938,7 @@ buf_find_offset_of_char(buf_t *buf, char ch)
* length exceeds *<b>data_len</b>.
*/
int
-fetch_from_buf_line(buf_t *buf, char *data_out, size_t *data_len)
+buf_get_line(buf_t *buf, char *data_out, size_t *data_len)
{
size_t sz;
off_t offset;
@@ -954,7 +954,7 @@ fetch_from_buf_line(buf_t *buf, char *data_out, size_t *data_len)
*data_len = sz + 2;
return -1;
}
- fetch_from_buf(data_out, sz+1, buf);
+ buf_get_bytes(data_out, sz+1, buf);
data_out[sz+1] = '\0';
*data_len = sz+1;
return 1;
@@ -965,7 +965,7 @@ fetch_from_buf_line(buf_t *buf, char *data_out, size_t *data_len)
* <b>done</b> is true, flush the data in the state and finish the
* compression/uncompression. Return -1 on failure, 0 on success. */
int
-write_to_buf_compress(buf_t *buf, tor_compress_state_t *state,
+buf_add_compress(buf_t *buf, tor_compress_state_t *state,
const char *data, size_t data_len,
const int done)
{
@@ -1033,7 +1033,7 @@ buf_set_to_copy(buf_t **output,
/** Log an error and exit if <b>buf</b> is corrupted.
*/
void
-assert_buf_ok(buf_t *buf)
+buf_assert_ok(buf_t *buf)
{
tor_assert(buf);
tor_assert(buf->magic == BUFFER_MAGIC);