From a7f7696a8d69676fef06c622313649798cff7b5c Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Fri, 17 Aug 2012 15:19:40 +0200 Subject: [PATCH] unix: remove UV_REQ_BUFSML_SIZE --- include/uv-private/uv-unix.h | 6 ++---- src/unix/stream.c | 12 +++++++++--- src/unix/udp.c | 4 +++- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/include/uv-private/uv-unix.h b/include/uv-private/uv-unix.h index fe450647..e7649258 100644 --- a/include/uv-private/uv-unix.h +++ b/include/uv-private/uv-unix.h @@ -140,8 +140,6 @@ struct uv__io_s { uv_signal_t child_watcher; \ UV_LOOP_PRIVATE_PLATFORM_FIELDS -#define UV_REQ_BUFSML_SIZE (4) - #define UV_REQ_PRIVATE_FIELDS /* empty */ #define UV_WRITE_PRIVATE_FIELDS \ @@ -150,7 +148,7 @@ struct uv__io_s { uv_buf_t* bufs; \ int bufcnt; \ int error; \ - uv_buf_t bufsml[UV_REQ_BUFSML_SIZE]; + uv_buf_t bufsml[4]; \ #define UV_SHUTDOWN_PRIVATE_FIELDS /* empty */ @@ -164,7 +162,7 @@ struct uv__io_s { uv_buf_t* bufs; \ ssize_t status; \ uv_udp_send_cb send_cb; \ - uv_buf_t bufsml[UV_REQ_BUFSML_SIZE]; \ + uv_buf_t bufsml[4]; \ #define UV_PRIVATE_REQ_TYPES /* empty */ diff --git a/src/unix/stream.c b/src/unix/stream.c index 70abb0e5..0ab86f3a 100644 --- a/src/unix/stream.c +++ b/src/unix/stream.c @@ -831,10 +831,16 @@ static void uv__stream_connect(uv_stream_t* stream) { } -int uv_write2(uv_write_t* req, uv_stream_t* stream, uv_buf_t bufs[], int bufcnt, - uv_stream_t* send_handle, uv_write_cb cb) { +int uv_write2(uv_write_t* req, + uv_stream_t* stream, + uv_buf_t bufs[], + int bufcnt, + uv_stream_t* send_handle, + uv_write_cb cb) { int empty_queue; + assert(bufcnt > 0); + assert((stream->type == UV_TCP || stream->type == UV_NAMED_PIPE || stream->type == UV_TTY) && "uv_write (unix) does not yet support other types of streams"); @@ -861,7 +867,7 @@ int uv_write2(uv_write_t* req, uv_stream_t* stream, uv_buf_t bufs[], int bufcnt, req->send_handle = send_handle; ngx_queue_init(&req->queue); - if (bufcnt <= UV_REQ_BUFSML_SIZE) + if (bufcnt <= (int) ARRAY_SIZE(req->bufsml)) req->bufs = req->bufsml; else req->bufs = malloc(sizeof(uv_buf_t) * bufcnt); diff --git a/src/unix/udp.c b/src/unix/udp.c index 0d88a7b2..1838bc79 100644 --- a/src/unix/udp.c +++ b/src/unix/udp.c @@ -418,6 +418,8 @@ static int uv__udp_send(uv_udp_send_t* req, struct sockaddr* addr, socklen_t addrlen, uv_udp_send_cb send_cb) { + assert(bufcnt > 0); + if (uv__udp_maybe_deferred_bind(handle, addr->sa_family)) return -1; @@ -429,7 +431,7 @@ static int uv__udp_send(uv_udp_send_t* req, req->handle = handle; req->bufcnt = bufcnt; - if (bufcnt <= UV_REQ_BUFSML_SIZE) { + if (bufcnt <= (int) ARRAY_SIZE(req->bufsml)) { req->bufs = req->bufsml; } else if ((req->bufs = malloc(bufcnt * sizeof(bufs[0]))) == NULL) {