Skip to content
This repository has been archived by the owner on May 4, 2018. It is now read-only.

Commit

Permalink
bench: let client close connection in tcp_multi_accept{2,4,8}
Browse files Browse the repository at this point in the history
  • Loading branch information
bnoordhuis committed Sep 5, 2012
1 parent d4e1469 commit 3758f8e
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion test/benchmark-multi-accept.c
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 3758f8e

Please sign in to comment.