mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2025-02-25 15:10:48 +01:00
Add a zero-copy buffer move implementation.
This commit is contained in:
parent
5240d02a11
commit
095e15f8ac
2 changed files with 23 additions and 0 deletions
|
@ -838,6 +838,28 @@ buf_move_to_buf(buf_t *buf_out, buf_t *buf_in, size_t *buf_flushlen)
|
||||||
return (int)cp;
|
return (int)cp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Moves all data from <b>buf_in</b> to <b>buf_out</b>, without copying.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
buf_move_all(buf_t *buf_out, buf_t *buf_in)
|
||||||
|
{
|
||||||
|
tor_assert(buf_out);
|
||||||
|
if (!buf_in)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (buf_out->head == NULL) {
|
||||||
|
buf_out->head = buf_in->head;
|
||||||
|
buf_out->tail = buf_in->tail;
|
||||||
|
} else {
|
||||||
|
buf_out->tail->next = buf_in->head;
|
||||||
|
buf_out->tail = buf_in->tail;
|
||||||
|
}
|
||||||
|
|
||||||
|
buf_out->datalen += buf_in->datalen;
|
||||||
|
buf_in->head = buf_in->tail = NULL;
|
||||||
|
buf_in->datalen = 0;
|
||||||
|
}
|
||||||
|
|
||||||
/** Internal structure: represents a position in a buffer. */
|
/** Internal structure: represents a position in a buffer. */
|
||||||
typedef struct buf_pos_t {
|
typedef struct buf_pos_t {
|
||||||
const chunk_t *chunk; /**< Which chunk are we pointing to? */
|
const chunk_t *chunk; /**< Which chunk are we pointing to? */
|
||||||
|
|
|
@ -51,6 +51,7 @@ void buf_add_vprintf(buf_t *buf, const char *format, va_list args)
|
||||||
int buf_add_compress(buf_t *buf, struct tor_compress_state_t *state,
|
int buf_add_compress(buf_t *buf, struct tor_compress_state_t *state,
|
||||||
const char *data, size_t data_len, int done);
|
const char *data, size_t data_len, int done);
|
||||||
int buf_move_to_buf(buf_t *buf_out, buf_t *buf_in, size_t *buf_flushlen);
|
int buf_move_to_buf(buf_t *buf_out, buf_t *buf_in, size_t *buf_flushlen);
|
||||||
|
void buf_move_all(buf_t *buf_out, buf_t *buf_in);
|
||||||
void buf_peek(const buf_t *buf, char *string, size_t string_len);
|
void buf_peek(const buf_t *buf, char *string, size_t string_len);
|
||||||
void buf_drain(buf_t *buf, size_t n);
|
void buf_drain(buf_t *buf, size_t n);
|
||||||
int buf_get_bytes(buf_t *buf, char *string, size_t string_len);
|
int buf_get_bytes(buf_t *buf, char *string, size_t string_len);
|
||||||
|
|
Loading…
Add table
Reference in a new issue