diff --git a/oio-unix.c b/oio-unix.c index 0c035090..15761c6b 100644 --- a/oio-unix.c +++ b/oio-unix.c @@ -236,11 +236,16 @@ void oio__server_io(EV_P_ ev_io* watcher, int revents) { } -int oio_tcp_handle_accept(oio_handle* server, oio_handle* client) { +int oio_tcp_handle_accept(oio_handle* server, oio_handle* client, + oio_close_cb close_cb, void* data) { if (server->accepted_fd < 0) { return -1; } + if (oio_tcp_handle_init(client, close_cb, data)) { + return -1; + } + if (oio_tcp_open(client, server->accepted_fd)) { /* Ignore error for now */ server->accepted_fd = -1; diff --git a/oio.h b/oio.h index a3a1b4c2..f127de40 100644 --- a/oio.h +++ b/oio.h @@ -107,7 +107,10 @@ int oio_shutdown(oio_req* req); /* TCP server methods. */ int oio_listen(oio_handle* handle, int backlog, oio_accept_cb cb); -int oio_tcp_handle_accept(oio_handle* server, oio_handle* client); + +/* Call this after accept_cb. client does not need to be initialized. */ +int oio_tcp_handle_accept(oio_handle* server, oio_handle* client, + oio_close_cb close_cb, void* data); /* Generic handle methods */ int oio_read(oio_req* req, oio_buf* bufs, int bufcnt); diff --git a/test/echo-server.c b/test/echo-server.c index 524bbf29..82be627e 100644 --- a/test/echo-server.c +++ b/test/echo-server.c @@ -64,10 +64,7 @@ void on_close(oio_handle* peer, oio_err err) { void on_accept(oio_handle* server) { peer_t* p = (peer_t*)calloc(sizeof(peer_t), 1); - int r = oio_tcp_handle_init(&p->handle, on_close, (void*)p); - ASSERT(!r); - - if (oio_tcp_handle_accept(server, &p->handle)) { + if (oio_tcp_handle_accept(server, &p->handle, on_close, (void*)p)) { FATAL("oio_tcp_handle_accept failed"); }