From 29f44c756468eab4f6f23781b949dd788c9c559a Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Wed, 5 Sep 2012 22:57:10 +0200 Subject: [PATCH] bench: let client close connection in tcp_multi_accept{2,4,8} --- test/benchmark-multi-accept.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/test/benchmark-multi-accept.c b/test/benchmark-multi-accept.c index d49da2e8..ce3f353d 100644 --- a/test/benchmark-multi-accept.c +++ b/test/benchmark-multi-accept.c @@ -91,6 +91,8 @@ static uv_buf_t ipc_alloc_cb(uv_handle_t* handle, size_t suggested_size); 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_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 cl_connect_cb(uv_connect_t* req, int status); static void cl_idle_cb(uv_idle_t* handle, int status); @@ -292,11 +294,24 @@ static void sv_connection_cb(uv_stream_t* server_handle, int status) { ASSERT(0); ASSERT(0 == uv_accept(server_handle, (uv_stream_t*) storage)); - uv_close((uv_handle_t*) storage, (uv_close_cb) free); + ASSERT(0 == uv_read_start((uv_stream_t*) storage, sv_alloc_cb, sv_read_cb)); ctx->num_connects++; } +static uv_buf_t sv_alloc_cb(uv_handle_t* handle, size_t suggested_size) { + static char buf[32]; + return uv_buf_init(buf, sizeof(buf)); +} + + +static void sv_read_cb(uv_stream_t* handle, ssize_t nread, uv_buf_t buf) { + ASSERT(nread == -1); + ASSERT(uv_last_error(handle->loop).code == UV_EOF); + uv_close((uv_handle_t*) handle, (uv_close_cb) free); +} + + static void cl_connect_cb(uv_connect_t* req, int status) { struct client_ctx* ctx = container_of(req, struct client_ctx, connect_req); uv_idle_start(&ctx->idle_handle, cl_idle_cb);