diff options
Diffstat (limited to 'src/uv_link_t.c')
-rw-r--r-- | src/uv_link_t.c | 35 |
1 files changed, 30 insertions, 5 deletions
diff --git a/src/uv_link_t.c b/src/uv_link_t.c index 0e2111e..548d638 100644 --- a/src/uv_link_t.c +++ b/src/uv_link_t.c @@ -1,9 +1,33 @@ +#include <stdlib.h> #include <string.h> #include "common.h" +static void uv_link_def_alloc_cb(uv_link_t* link, + size_t suggested_size, + uv_buf_t* buf) { + static const size_t kBufferSize = 16 * 1024; + + buf->base = malloc(kBufferSize); + buf->len = kBufferSize; + + CHECK_NE(buf->base, NULL, "uv_link_t: alloc_cb failure"); +} + + +static void uv_link_def_read_cb(uv_link_t* link, + ssize_t nread, + const uv_buf_t* buf) { + free(buf->base); +} + + int uv_link_init(uv_loop_t* loop, uv_link_t* link) { memset(link, 0, sizeof(*link)); + + link->alloc_cb = uv_link_def_alloc_cb; + link->read_cb = uv_link_def_read_cb; + return 0; } @@ -19,12 +43,11 @@ int uv_link_chain(uv_link_t* from, if (from->child != NULL || to->parent != NULL) return UV_EINVAL; - if (from->alloc_cb != NULL || from->read_cb != NULL) - return UV_EINVAL; - from->child = to; to->parent = from; + from->saved_alloc_cb = from->alloc_cb; + from->saved_read_cb = from->read_cb; from->alloc_cb = alloc_cb; from->read_cb = read_cb; @@ -39,8 +62,10 @@ int uv_link_unchain(uv_link_t* from, uv_link_t* to) { from->child = NULL; to->parent = NULL; - from->alloc_cb = NULL; - from->read_cb = NULL; + from->alloc_cb = from->saved_alloc_cb; + from->read_cb = from->saved_read_cb; + from->saved_alloc_cb = NULL; + from->saved_read_cb = NULL; return from->read_stop(from); } |