include: uv_alloc_cb now takes uv_buf_t*

Passing or returning structs as values makes life hard for people that
work with libuv through a foreign function interface. Switch to a
pointer-based approach.

Fixes #684.
This commit is contained in:
Ben Noordhuis 2013-08-31 15:48:23 +02:00
parent 8c9f28b4ac
commit 3fb6612233
35 changed files with 179 additions and 138 deletions

View File

@ -338,7 +338,7 @@ UV_EXTERN int uv_backend_timeout(const uv_loop_t*);
/* /*
* Should return a buffer that libuv can use to read data into. * Should prepare a buffer that libuv can use to read data into.
* *
* `suggested_size` is a hint. Returning a buffer that is smaller is perfectly * `suggested_size` is a hint. Returning a buffer that is smaller is perfectly
* okay as long as `buf.len > 0`. * okay as long as `buf.len > 0`.
@ -349,7 +349,9 @@ UV_EXTERN int uv_backend_timeout(const uv_loop_t*);
* Note that returning a zero-length buffer does not stop the handle, call * Note that returning a zero-length buffer does not stop the handle, call
* uv_read_stop() or uv_udp_recv_stop() for that. * uv_read_stop() or uv_udp_recv_stop() for that.
*/ */
typedef uv_buf_t (*uv_alloc_cb)(uv_handle_t* handle, size_t suggested_size); typedef void (*uv_alloc_cb)(uv_handle_t* handle,
size_t suggested_size,
uv_buf_t* buf);
/* /*
* `nread` is > 0 if there is data available, 0 if libuv is done reading for * `nread` is > 0 if there is data available, 0 if libuv is done reading for

View File

@ -979,7 +979,7 @@ static void uv__read(uv_stream_t* stream) {
&& (count-- > 0)) { && (count-- > 0)) {
assert(stream->alloc_cb != NULL); assert(stream->alloc_cb != NULL);
buf = stream->alloc_cb((uv_handle_t*)stream, 64 * 1024); stream->alloc_cb((uv_handle_t*)stream, 64 * 1024, &buf);
if (buf.len == 0) { if (buf.len == 0) {
/* User indicates it can't or won't handle the read. */ /* User indicates it can't or won't handle the read. */
uv__stream_read_cb(stream, UV_ENOBUFS, buf, UV_UNKNOWN_HANDLE); uv__stream_read_cb(stream, UV_ENOBUFS, buf, UV_UNKNOWN_HANDLE);

View File

@ -205,7 +205,7 @@ static void uv__udp_recvmsg(uv_loop_t* loop,
h.msg_name = &peer; h.msg_name = &peer;
do { do {
buf = handle->alloc_cb((uv_handle_t*) handle, 64 * 1024); handle->alloc_cb((uv_handle_t*) handle, 64 * 1024, &buf);
if (buf.len == 0) { if (buf.len == 0) {
handle->recv_cb(handle, UV_ENOBUFS, buf, NULL, 0); handle->recv_cb(handle, UV_ENOBUFS, buf, NULL, 0);
return; return;

View File

@ -1429,7 +1429,7 @@ void uv_process_pipe_read_req(uv_loop_t* loop, uv_pipe_t* handle,
} }
} }
buf = handle->alloc_cb((uv_handle_t*) handle, avail); handle->alloc_cb((uv_handle_t*) handle, avail, &buf);
if (buf.len == 0) { if (buf.len == 0) {
if (handle->read2_cb) { if (handle->read2_cb) {
handle->read2_cb(handle, UV_ENOBUFS, buf, UV_UNKNOWN_HANDLE); handle->read2_cb(handle, UV_ENOBUFS, buf, UV_UNKNOWN_HANDLE);

View File

@ -434,7 +434,7 @@ static void uv_tcp_queue_read(uv_loop_t* loop, uv_tcp_t* handle) {
*/ */
if (loop->active_tcp_streams < uv_active_tcp_streams_threshold) { if (loop->active_tcp_streams < uv_active_tcp_streams_threshold) {
handle->flags &= ~UV_HANDLE_ZERO_READ; handle->flags &= ~UV_HANDLE_ZERO_READ;
handle->read_buffer = handle->alloc_cb((uv_handle_t*) handle, 65536); handle->alloc_cb((uv_handle_t*) handle, 65536, &handle->read_buffer);
if (handle->read_buffer.len == 0) { if (handle->read_buffer.len == 0) {
handle->read_cb((uv_stream_t*) handle, UV_ENOBUFS, handle->read_buffer); handle->read_cb((uv_stream_t*) handle, UV_ENOBUFS, handle->read_buffer);
return; return;
@ -947,7 +947,7 @@ void uv_process_tcp_read_req(uv_loop_t* loop, uv_tcp_t* handle,
/* Do nonblocking reads until the buffer is empty */ /* Do nonblocking reads until the buffer is empty */
while (handle->flags & UV_HANDLE_READING) { while (handle->flags & UV_HANDLE_READING) {
buf = handle->alloc_cb((uv_handle_t*) handle, 65536); handle->alloc_cb((uv_handle_t*) handle, 65536, &buf);
if (buf.len == 0) { if (buf.len == 0) {
handle->read_cb(handle, UV_ENOBUFS, buf); handle->read_cb(handle, UV_ENOBUFS, buf);
break; break;

View File

@ -347,7 +347,7 @@ static void uv_tty_queue_read_line(uv_loop_t* loop, uv_tty_t* handle) {
req = &handle->read_req; req = &handle->read_req;
memset(&req->overlapped, 0, sizeof(req->overlapped)); memset(&req->overlapped, 0, sizeof(req->overlapped));
handle->read_line_buffer = handle->alloc_cb((uv_handle_t*) handle, 8192); handle->alloc_cb((uv_handle_t*) handle, 8192, &handle->read_line_buffer);
if (handle->read_line_buffer.len == 0) { if (handle->read_line_buffer.len == 0) {
handle->read_cb(handle, UV_ENOBUFS, handle->read_line_buffer); handle->read_cb(handle, UV_ENOBUFS, handle->read_line_buffer);
return; return;
@ -684,7 +684,7 @@ void uv_process_tty_read_raw_req(uv_loop_t* loop, uv_tty_t* handle,
if (handle->last_key_offset < handle->last_key_len) { if (handle->last_key_offset < handle->last_key_len) {
/* Allocate a buffer if needed */ /* Allocate a buffer if needed */
if (buf_used == 0) { if (buf_used == 0) {
buf = handle->alloc_cb((uv_handle_t*) handle, 1024); handle->alloc_cb((uv_handle_t*) handle, 1024, &buf);
if (buf.len == 0) { if (buf.len == 0) {
handle->read_cb((uv_stream_t*) handle, UV_ENOBUFS, buf); handle->read_cb((uv_stream_t*) handle, UV_ENOBUFS, buf);
goto out; goto out;

View File

@ -271,7 +271,7 @@ static void uv_udp_queue_recv(uv_loop_t* loop, uv_udp_t* handle) {
if (loop->active_udp_streams < uv_active_udp_streams_threshold) { if (loop->active_udp_streams < uv_active_udp_streams_threshold) {
handle->flags &= ~UV_HANDLE_ZERO_READ; handle->flags &= ~UV_HANDLE_ZERO_READ;
handle->recv_buffer = handle->alloc_cb((uv_handle_t*) handle, 65536); handle->alloc_cb((uv_handle_t*) handle, 65536, &handle->recv_buffer);
if (handle->recv_buffer.len == 0) { if (handle->recv_buffer.len == 0) {
handle->recv_cb(handle, UV_ENOBUFS, handle->recv_buffer, NULL, 0); handle->recv_cb(handle, UV_ENOBUFS, handle->recv_buffer, NULL, 0);
return; return;
@ -518,7 +518,7 @@ void uv_process_udp_recv_req(uv_loop_t* loop, uv_udp_t* handle,
/* Do a nonblocking receive */ /* Do a nonblocking receive */
/* TODO: try to read multiple datagrams at once. FIONREAD maybe? */ /* TODO: try to read multiple datagrams at once. FIONREAD maybe? */
buf = handle->alloc_cb((uv_handle_t*) handle, 65536); handle->alloc_cb((uv_handle_t*) handle, 65536, &buf);
if (buf.len == 0) { if (buf.len == 0) {
handle->recv_cb(handle, UV_ENOBUFS, buf, NULL, 0); handle->recv_cb(handle, UV_ENOBUFS, buf, NULL, 0);
goto done; goto done;

View File

@ -87,12 +87,16 @@ static void ipc_read2_cb(uv_pipe_t* ipc_pipe,
ssize_t nread, ssize_t nread,
uv_buf_t buf, uv_buf_t buf,
uv_handle_type type); uv_handle_type type);
static uv_buf_t ipc_alloc_cb(uv_handle_t* handle, size_t suggested_size); static void ipc_alloc_cb(uv_handle_t* handle,
size_t suggested_size,
uv_buf_t* buf);
static void sv_async_cb(uv_async_t* handle, int status); static void sv_async_cb(uv_async_t* handle, int status);
static void sv_connection_cb(uv_stream_t* server_handle, int status); static void sv_connection_cb(uv_stream_t* server_handle, int status);
static void sv_read_cb(uv_stream_t* handle, ssize_t nread, uv_buf_t buf); static void sv_read_cb(uv_stream_t* handle, ssize_t nread, uv_buf_t buf);
static uv_buf_t sv_alloc_cb(uv_handle_t* handle, size_t suggested_size); static void sv_alloc_cb(uv_handle_t* handle,
size_t suggested_size,
uv_buf_t* buf);
static void cl_connect_cb(uv_connect_t* req, int status); static void cl_connect_cb(uv_connect_t* req, int status);
static void cl_idle_cb(uv_idle_t* handle, int status); static void cl_idle_cb(uv_idle_t* handle, int status);
@ -157,10 +161,13 @@ static void ipc_connect_cb(uv_connect_t* req, int status) {
} }
static uv_buf_t ipc_alloc_cb(uv_handle_t* handle, size_t suggested_size) { static void ipc_alloc_cb(uv_handle_t* handle,
size_t suggested_size,
uv_buf_t* buf) {
struct ipc_client_ctx* ctx; struct ipc_client_ctx* ctx;
ctx = container_of(handle, struct ipc_client_ctx, ipc_pipe); ctx = container_of(handle, struct ipc_client_ctx, ipc_pipe);
return uv_buf_init(ctx->scratch, sizeof(ctx->scratch)); buf->base = ctx->scratch;
buf->len = sizeof(ctx->scratch);
} }
@ -295,9 +302,12 @@ static void sv_connection_cb(uv_stream_t* server_handle, int status) {
} }
static uv_buf_t sv_alloc_cb(uv_handle_t* handle, size_t suggested_size) { static void sv_alloc_cb(uv_handle_t* handle,
static char buf[32]; size_t suggested_size,
return uv_buf_init(buf, sizeof(buf)); uv_buf_t* buf) {
static char slab[32];
buf->base = slab;
buf->len = sizeof(slab);
} }

View File

@ -53,21 +53,19 @@ static int completed_pingers = 0;
static int64_t start_time; static int64_t start_time;
static uv_buf_t buf_alloc(uv_handle_t* tcp, size_t size) { static void buf_alloc(uv_handle_t* tcp, size_t size, uv_buf_t* buf) {
buf_t* ab; buf_t* ab;
ab = buf_freelist; ab = buf_freelist;
if (ab != NULL)
if (ab != NULL) {
buf_freelist = ab->next; buf_freelist = ab->next;
return ab->uv_buf_t; else {
ab = malloc(size + sizeof(*ab));
ab->uv_buf_t.len = size;
ab->uv_buf_t.base = (char*) (ab + 1);
} }
ab = (buf_t*) malloc(size + sizeof *ab); *buf = ab->uv_buf_t;
ab->uv_buf_t.len = size;
ab->uv_buf_t.base = ((char*) ab) + sizeof *ab;
return ab->uv_buf_t;
} }

View File

@ -75,18 +75,18 @@ static uint64_t start; /* in ms */
static int closed_streams; static int closed_streams;
static int conns_failed; static int conns_failed;
static uv_buf_t alloc_cb(uv_handle_t* handle, size_t suggested_size); static void alloc_cb(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf);
static void connect_cb(uv_connect_t* conn_req, int status); static void connect_cb(uv_connect_t* conn_req, int status);
static void read_cb(uv_stream_t* stream, ssize_t nread, uv_buf_t buf); static void read_cb(uv_stream_t* stream, ssize_t nread, uv_buf_t buf);
static void close_cb(uv_handle_t* handle); static void close_cb(uv_handle_t* handle);
static uv_buf_t alloc_cb(uv_handle_t* handle, size_t suggested_size) { static void alloc_cb(uv_handle_t* handle,
size_t suggested_size,
uv_buf_t* buf) {
static char slab[65536]; static char slab[65536];
uv_buf_t buf; buf->base = slab;
buf.base = slab; buf->len = sizeof(slab);
buf.len = sizeof(slab);
return buf;
} }

View File

@ -41,7 +41,7 @@ static void maybe_connect_some();
static uv_req_t* req_alloc(); static uv_req_t* req_alloc();
static void req_free(uv_req_t* uv_req); static void req_free(uv_req_t* uv_req);
static uv_buf_t buf_alloc(uv_handle_t*, size_t size); static void buf_alloc(uv_handle_t* handle, size_t size, uv_buf_t* buf);
static void buf_free(uv_buf_t uv_buf_t); static void buf_free(uv_buf_t uv_buf_t);
static uv_loop_t* loop; static uv_loop_t* loop;
@ -331,20 +331,19 @@ typedef struct buf_list_s {
static buf_list_t* buf_freelist = NULL; static buf_list_t* buf_freelist = NULL;
static uv_buf_t buf_alloc(uv_handle_t* handle, size_t size) { static void buf_alloc(uv_handle_t* handle, size_t size, uv_buf_t* buf) {
buf_list_t* buf; buf_list_t* ab;
buf = buf_freelist; ab = buf_freelist;
if (buf != NULL) { if (ab != NULL)
buf_freelist = buf->next; buf_freelist = ab->next;
return buf->uv_buf_t; else {
ab = malloc(size + sizeof(*ab));
ab->uv_buf_t.len = size;
ab->uv_buf_t.base = (char*) (ab + 1);
} }
buf = (buf_list_t*) malloc(size + sizeof *buf); *buf = ab->uv_buf_t;
buf->uv_buf_t.len = (unsigned int)size;
buf->uv_buf_t.base = ((char*) buf) + sizeof *buf;
return buf->uv_buf_t;
} }

View File

@ -73,11 +73,11 @@ static void exit_cb(uv_process_t* process,
} }
static uv_buf_t on_alloc(uv_handle_t* handle, size_t suggested_size) { static void on_alloc(uv_handle_t* handle,
uv_buf_t buf; size_t suggested_size,
buf.base = output + output_used; uv_buf_t* buf) {
buf.len = OUTPUT_SIZE - output_used; buf->base = output + output_used;
return buf; buf->len = OUTPUT_SIZE - output_used;
} }

View File

@ -59,10 +59,13 @@ static int timed;
static int exiting; static int exiting;
static uv_buf_t alloc_cb(uv_handle_t* handle, size_t suggested_size) { static void alloc_cb(uv_handle_t* handle,
size_t suggested_size,
uv_buf_t* buf) {
static char slab[65536]; static char slab[65536];
ASSERT(suggested_size <= sizeof slab); ASSERT(suggested_size <= sizeof(slab));
return uv_buf_init(slab, sizeof slab); buf->base = slab;
buf->len = sizeof(slab);
} }

View File

@ -33,7 +33,7 @@ typedef struct {
static uv_tcp_t tcp_server; static uv_tcp_t tcp_server;
static void connection_cb(uv_stream_t* stream, int status); static void connection_cb(uv_stream_t* stream, int status);
static uv_buf_t alloc_cb(uv_handle_t* handle, size_t suggested_size); static void alloc_cb(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf);
static void read_cb(uv_stream_t* stream, ssize_t nread, uv_buf_t buf); static void read_cb(uv_stream_t* stream, ssize_t nread, uv_buf_t buf);
static void shutdown_cb(uv_shutdown_t* req, int status); static void shutdown_cb(uv_shutdown_t* req, int status);
static void close_cb(uv_handle_t* handle); static void close_cb(uv_handle_t* handle);
@ -60,9 +60,12 @@ static void connection_cb(uv_stream_t* stream, int status) {
} }
static uv_buf_t alloc_cb(uv_handle_t* handle, size_t suggested_size) { static void alloc_cb(uv_handle_t* handle,
static char buf[65536]; size_t suggested_size,
return uv_buf_init(buf, sizeof buf); uv_buf_t* buf) {
static char slab[65536];
buf->base = slab;
buf->len = sizeof(slab);
} }

View File

@ -255,11 +255,11 @@ static void on_close(uv_handle_t* peer) {
} }
static uv_buf_t buf_alloc(uv_handle_t* handle, size_t suggested_size) { static void buf_alloc(uv_handle_t* handle,
uv_buf_t buf; size_t suggested_size,
buf.base = (char*) malloc(suggested_size); uv_buf_t* buf) {
buf.len = suggested_size; buf->base = malloc(suggested_size);
return buf; buf->len = suggested_size;
} }

View File

@ -130,8 +130,11 @@ static void on_close(uv_handle_t* peer) {
} }
static uv_buf_t echo_alloc(uv_handle_t* handle, size_t suggested_size) { static void echo_alloc(uv_handle_t* handle,
return uv_buf_init(malloc(suggested_size), suggested_size); size_t suggested_size,
uv_buf_t* buf) {
buf->base = malloc(suggested_size);
buf->len = suggested_size;
} }

View File

@ -45,12 +45,10 @@ static int bytes_received = 0;
static int shutdown_cb_called = 0; static int shutdown_cb_called = 0;
static uv_buf_t alloc_cb(uv_handle_t* handle, size_t size) { static void alloc_cb(uv_handle_t* handle, size_t size, uv_buf_t* buf) {
uv_buf_t buf; buf->len = size;
buf.len = size; buf->base = malloc(size);
buf.base = (char*) malloc(size); ASSERT(buf->base != NULL);
ASSERT(buf.base);
return buf;
} }

View File

@ -30,11 +30,9 @@ static int close_cb_called = 0;
static int connect_cb_called = 0; static int connect_cb_called = 0;
static uv_buf_t alloc_cb(uv_handle_t* handle, size_t size) { static void alloc_cb(uv_handle_t* handle, size_t size, uv_buf_t* buf) {
uv_buf_t buf; buf->base = malloc(size);
buf.base = (char*)malloc(size); buf->len = size;
buf.len = size;
return buf;
} }

View File

@ -42,11 +42,9 @@ static uv_udp_t udpServer;
static uv_udp_send_t send_req; static uv_udp_send_t send_req;
static uv_buf_t alloc(uv_handle_t* handle, size_t suggested_size) { static void alloc(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf) {
uv_buf_t buf; buf->base = malloc(suggested_size);
buf.base = (char*) malloc(suggested_size); buf->len = suggested_size;
buf.len = suggested_size;
return buf;
} }

View File

@ -50,10 +50,13 @@ static struct echo_ctx ctx;
static int num_recv_handles; static int num_recv_handles;
static uv_buf_t alloc_cb(uv_handle_t* handle, size_t suggested_size) { static void alloc_cb(uv_handle_t* handle,
size_t suggested_size,
uv_buf_t* buf) {
/* we're not actually reading anything so a small buffer is okay */ /* we're not actually reading anything so a small buffer is okay */
static char buf[8]; static char slab[8];
return uv_buf_init(buf, sizeof(buf)); buf->base = slab;
buf->len = sizeof(slab);
} }

View File

@ -94,8 +94,11 @@ static void exit_cb(uv_process_t* process,
} }
static uv_buf_t on_alloc(uv_handle_t* handle, size_t suggested_size) { static void on_alloc(uv_handle_t* handle,
return uv_buf_init(malloc(suggested_size), suggested_size); size_t suggested_size,
uv_buf_t* buf) {
buf->base = malloc(suggested_size);
buf->len = suggested_size;
} }
@ -238,11 +241,11 @@ static void on_tcp_write(uv_write_t* req, int status) {
} }
static uv_buf_t on_read_alloc(uv_handle_t* handle, size_t suggested_size) { static void on_read_alloc(uv_handle_t* handle,
uv_buf_t buf; size_t suggested_size,
buf.base = (char*)malloc(suggested_size); uv_buf_t* buf) {
buf.len = suggested_size; buf->base = malloc(suggested_size);
return buf; buf->len = suggested_size;
} }

View File

@ -30,10 +30,10 @@
static int read_count; static int read_count;
static uv_buf_t alloc_cb(uv_handle_t* handle, size_t size) { static void alloc_cb(uv_handle_t* handle, size_t size, uv_buf_t* buf) {
static char buf[1024]; static char slab[1024];
buf->base = slab;
return uv_buf_init(buf, ARRAY_SIZE(buf)); buf->len = sizeof(slab);
} }

View File

@ -48,8 +48,9 @@ typedef struct {
} pinger_t; } pinger_t;
static uv_buf_t alloc_cb(uv_handle_t* handle, size_t size) { static void alloc_cb(uv_handle_t* handle, size_t size, uv_buf_t* buf) {
return uv_buf_init(malloc(size), size); buf->base = malloc(size);
buf->len = size;
} }

View File

@ -39,11 +39,9 @@ static int called_timer_close_cb;
static int called_timer_cb; static int called_timer_cb;
static uv_buf_t alloc_cb(uv_handle_t* handle, size_t size) { static void alloc_cb(uv_handle_t* handle, size_t size, uv_buf_t* buf) {
uv_buf_t buf; buf->base = malloc(size);
buf.base = (char*)malloc(size); buf->len = size;
buf.len = size;
return buf;
} }

View File

@ -118,11 +118,11 @@ static void detach_failure_cb(uv_process_t* process, int64_t exit_status, int te
exit_cb_called++; exit_cb_called++;
} }
static uv_buf_t on_alloc(uv_handle_t* handle, size_t suggested_size) { static void on_alloc(uv_handle_t* handle,
uv_buf_t buf; size_t suggested_size,
buf.base = output + output_used; uv_buf_t* buf) {
buf.len = OUTPUT_SIZE - output_used; buf->base = output + output_used;
return buf; buf->len = OUTPUT_SIZE - output_used;
} }

View File

@ -74,8 +74,11 @@ static void init_process_options(char* test, uv_exit_cb exit_cb) {
} }
static uv_buf_t on_alloc(uv_handle_t* handle, size_t suggested_size) { static void on_alloc(uv_handle_t* handle,
return uv_buf_init(output + output_used, OUTPUT_SIZE - output_used); size_t suggested_size,
uv_buf_t* buf) {
buf->base = output + output_used;
buf->len = OUTPUT_SIZE - output_used;
} }
@ -179,8 +182,11 @@ static void after_pipe_write(uv_write_t* req, int status) {
} }
static uv_buf_t on_read_alloc(uv_handle_t* handle, size_t suggested_size) { static void on_read_alloc(uv_handle_t* handle,
return uv_buf_init(malloc(suggested_size), suggested_size); size_t suggested_size,
uv_buf_t* buf) {
buf->base = malloc(suggested_size);
buf->len = suggested_size;
} }

View File

@ -71,10 +71,13 @@ static uv_os_sock_t create_tcp_socket(void) {
} }
static uv_buf_t alloc_cb(uv_handle_t* handle, size_t suggested_size) { static void alloc_cb(uv_handle_t* handle,
size_t suggested_size,
uv_buf_t* buf) {
static char slab[65536]; static char slab[65536];
ASSERT(suggested_size <= sizeof slab); ASSERT(suggested_size <= sizeof(slab));
return uv_buf_init(slab, sizeof slab); buf->base = slab;
buf->len = sizeof(slab);
} }

View File

@ -49,9 +49,12 @@ static void close_cb(uv_handle_t* handle) {
} }
static uv_buf_t alloc_cb(uv_handle_t* handle, size_t suggested_size) { static void alloc_cb(uv_handle_t* handle,
size_t suggested_size,
uv_buf_t* buf) {
static char slab[64]; static char slab[64];
return uv_buf_init(slab, sizeof(slab)); buf->base = slab;
buf->len = sizeof(slab);
} }

View File

@ -47,10 +47,10 @@ static void timer_cb(uv_timer_t* handle, int status) {
} }
static uv_buf_t alloc_cb(uv_handle_t* handle, size_t suggested_size) { static void alloc_cb(uv_handle_t* handle,
size_t suggested_size,
uv_buf_t* buf) {
ASSERT(0 && "alloc_cb should not have been called"); ASSERT(0 && "alloc_cb should not have been called");
/* Satisfy the compiler. */
return uv_buf_init(NULL, 0);
} }

View File

@ -30,7 +30,7 @@ static void connection_cb(uv_stream_t* server, int status);
static void connect_cb(uv_connect_t* req, int status); static void connect_cb(uv_connect_t* req, int status);
static void write_cb(uv_write_t* req, int status); static void write_cb(uv_write_t* req, int status);
static void read_cb(uv_stream_t* stream, ssize_t nread, uv_buf_t buf); static void read_cb(uv_stream_t* stream, ssize_t nread, uv_buf_t buf);
static uv_buf_t alloc_cb(uv_handle_t* handle, size_t suggested_size); static void alloc_cb(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf);
static uv_tcp_t tcp_server; static uv_tcp_t tcp_server;
static uv_tcp_t tcp_client; static uv_tcp_t tcp_client;
@ -65,9 +65,12 @@ static void connection_cb(uv_stream_t* server, int status) {
} }
static uv_buf_t alloc_cb(uv_handle_t* handle, size_t suggested_size) { static void alloc_cb(uv_handle_t* handle,
size_t suggested_size,
uv_buf_t* buf) {
static char slab[1024]; static char slab[1024];
return uv_buf_init(slab, sizeof slab); buf->base = slab;
buf->len = sizeof(slab);
} }

View File

@ -46,8 +46,9 @@ static uv_shutdown_t shutdown_req;
static uv_write_t write_reqs[WRITES]; static uv_write_t write_reqs[WRITES];
static uv_buf_t alloc_cb(uv_handle_t* handle, size_t size) { static void alloc_cb(uv_handle_t* handle, size_t size, uv_buf_t* buf) {
return uv_buf_init(malloc(size), size); buf->base = malloc(size);
buf->len = size;
} }

View File

@ -44,10 +44,13 @@ static int recv_cb_called;
static int close_cb_called; static int close_cb_called;
static uv_buf_t alloc_cb(uv_handle_t* handle, size_t suggested_size) { static void alloc_cb(uv_handle_t* handle,
size_t suggested_size,
uv_buf_t* buf) {
static char slab[65536]; static char slab[65536];
CHECK_HANDLE(handle); CHECK_HANDLE(handle);
return uv_buf_init(slab, sizeof slab); buf->base = slab;
buf->len = sizeof(slab);
} }

View File

@ -38,13 +38,14 @@ static int sv_send_cb_called;
static int close_cb_called; static int close_cb_called;
static uv_buf_t alloc_cb(uv_handle_t* handle, size_t suggested_size) { static void alloc_cb(uv_handle_t* handle,
size_t suggested_size,
uv_buf_t* buf) {
static char slab[65536]; static char slab[65536];
CHECK_HANDLE(handle); CHECK_HANDLE(handle);
ASSERT(suggested_size <= sizeof slab); ASSERT(suggested_size <= sizeof(slab));
buf->base = slab;
return uv_buf_init(slab, sizeof slab); buf->len = sizeof(slab);
} }

View File

@ -67,10 +67,13 @@ static uv_os_sock_t create_udp_socket(void) {
} }
static uv_buf_t alloc_cb(uv_handle_t* handle, size_t suggested_size) { static void alloc_cb(uv_handle_t* handle,
size_t suggested_size,
uv_buf_t* buf) {
static char slab[65536]; static char slab[65536];
ASSERT(suggested_size <= sizeof slab); ASSERT(suggested_size <= sizeof(slab));
return uv_buf_init(slab, sizeof slab); buf->base = slab;
buf->len = sizeof(slab);
} }

View File

@ -41,13 +41,14 @@ static int sv_recv_cb_called;
static int close_cb_called; static int close_cb_called;
static uv_buf_t alloc_cb(uv_handle_t* handle, size_t suggested_size) { static void alloc_cb(uv_handle_t* handle,
size_t suggested_size,
uv_buf_t* buf) {
static char slab[65536]; static char slab[65536];
CHECK_HANDLE(handle); CHECK_HANDLE(handle);
ASSERT(suggested_size <= sizeof slab); ASSERT(suggested_size <= sizeof(slab));
buf->base = slab;
return uv_buf_init(slab, sizeof slab); buf->len = sizeof(slab);
} }