From cfca30433fe7f66d55cb78a46f102cddf1b15b63 Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Tue, 7 Jun 2011 18:01:00 +0200 Subject: [PATCH] API change: report accept errors to connection_cb --- test/benchmark-pump.c | 3 ++- test/echo-server.c | 22 ++++++++++++++-------- test/test-delayed-accept.c | 4 +++- uv-unix.c | 7 ++----- uv.h | 2 +- 5 files changed, 22 insertions(+), 16 deletions(-) diff --git a/test/benchmark-pump.c b/test/benchmark-pump.c index 6aa7776a..960a6813 100644 --- a/test/benchmark-pump.c +++ b/test/benchmark-pump.c @@ -250,11 +250,12 @@ static void maybe_connect_some() { } -static void connection_cb(uv_tcp_t* s) { +static void connection_cb(uv_tcp_t* s, int status) { uv_tcp_t* tcp; int r; ASSERT(&server == s); + ASSERT(status == 0); tcp = malloc(sizeof(uv_tcp_t)); diff --git a/test/echo-server.c b/test/echo-server.c index 9eab707c..e8fd61f4 100644 --- a/test/echo-server.c +++ b/test/echo-server.c @@ -38,7 +38,7 @@ static uv_tcp_t server; static void after_write(uv_req_t* req, int status); static void after_read(uv_tcp_t*, int nread, uv_buf_t buf); static void on_close(uv_handle_t* peer, int status); -static void on_accept(uv_tcp_t*); +static void on_connection(uv_tcp_t*, int status); static void after_write(uv_req_t* req, int status) { @@ -126,14 +126,20 @@ static uv_buf_t echo_alloc(uv_tcp_t* handle, size_t suggested_size) { } -static void on_accept(uv_tcp_t* server) { - uv_tcp_t* handle = (uv_tcp_t*) malloc(sizeof *handle); +static void on_connection(uv_tcp_t* server, int status) { + uv_tcp_t* handle; + int r; - if (uv_accept(server, handle, on_close, NULL)) { - FATAL("uv_accept failed"); - } + ASSERT(status == 0); - uv_read_start(handle, echo_alloc, after_read); + handle = (uv_tcp_t*) malloc(sizeof *handle); + ASSERT(handle != NULL); + + r = uv_accept(server, handle, on_close, NULL); + ASSERT(r == 0); + + r = uv_read_start(handle, echo_alloc, after_read); + ASSERT(r == 0); } @@ -161,7 +167,7 @@ static int echo_start(int port) { return 1; } - r = uv_listen(&server, 128, on_accept); + r = uv_listen(&server, 128, on_connection); if (r) { /* TODO: Error codes */ fprintf(stderr, "Listen error\n"); diff --git a/test/test-delayed-accept.c b/test/test-delayed-accept.c index 1f5156d2..064fe327 100644 --- a/test/test-delayed-accept.c +++ b/test/test-delayed-accept.c @@ -82,10 +82,12 @@ static void do_accept(uv_handle_t* timer_handle, int status) { } -static void connection_cb(uv_tcp_t* tcp) { +static void connection_cb(uv_tcp_t* tcp, int status) { int r; uv_timer_t* timer_handle; + ASSERT(status == 0); + timer_handle = (uv_timer_t*)malloc(sizeof *timer_handle); ASSERT(timer_handle != NULL); diff --git a/uv-unix.c b/uv-unix.c index e8c687ad..0a8cb24e 100644 --- a/uv-unix.c +++ b/uv-unix.c @@ -347,15 +347,12 @@ void uv__server_io(EV_P_ ev_io* watcher, int revents) { return; } else { uv_err_new((uv_handle_t*)tcp, errno); - /* - * XXX TODO how do we report this error to the user? What errors - * are possible here? - */ + tcp->connection_cb(tcp, -1); } } else { tcp->accepted_fd = fd; - tcp->connection_cb(tcp); + tcp->connection_cb(tcp, 0); if (tcp->accepted_fd >= 0) { /* The user hasn't yet accepted called uv_accept() */ ev_io_stop(EV_DEFAULT_ &tcp->read_watcher); diff --git a/uv.h b/uv.h index cc9cebfe..b28dec38 100644 --- a/uv.h +++ b/uv.h @@ -61,7 +61,7 @@ typedef void (*uv_read_cb)(uv_tcp_t* tcp, int nread, uv_buf_t buf); typedef void (*uv_write_cb)(uv_req_t* req, int status); typedef void (*uv_connect_cb)(uv_req_t* req, int status); typedef void (*uv_shutdown_cb)(uv_req_t* req, int status); -typedef void (*uv_connection_cb)(uv_tcp_t* server); +typedef void (*uv_connection_cb)(uv_tcp_t* server, int status); typedef void (*uv_close_cb)(uv_handle_t* handle, int status); /* TODO: do loop_cb and async_cb really need a status argument? */ typedef void (*uv_loop_cb)(uv_handle_t* handle, int status);