oio_tcp_handle_accept() does not require initialization of client
closes #13.
This commit is contained in:
parent
fa439e7bbc
commit
c3eda7a4da
@ -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) {
|
if (server->accepted_fd < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (oio_tcp_handle_init(client, close_cb, data)) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
if (oio_tcp_open(client, server->accepted_fd)) {
|
if (oio_tcp_open(client, server->accepted_fd)) {
|
||||||
/* Ignore error for now */
|
/* Ignore error for now */
|
||||||
server->accepted_fd = -1;
|
server->accepted_fd = -1;
|
||||||
|
|||||||
5
oio.h
5
oio.h
@ -107,7 +107,10 @@ int oio_shutdown(oio_req* req);
|
|||||||
|
|
||||||
/* TCP server methods. */
|
/* TCP server methods. */
|
||||||
int oio_listen(oio_handle* handle, int backlog, oio_accept_cb cb);
|
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 */
|
/* Generic handle methods */
|
||||||
int oio_read(oio_req* req, oio_buf* bufs, int bufcnt);
|
int oio_read(oio_req* req, oio_buf* bufs, int bufcnt);
|
||||||
|
|||||||
@ -64,10 +64,7 @@ void on_close(oio_handle* peer, oio_err err) {
|
|||||||
void on_accept(oio_handle* server) {
|
void on_accept(oio_handle* server) {
|
||||||
peer_t* p = (peer_t*)calloc(sizeof(peer_t), 1);
|
peer_t* p = (peer_t*)calloc(sizeof(peer_t), 1);
|
||||||
|
|
||||||
int r = oio_tcp_handle_init(&p->handle, on_close, (void*)p);
|
if (oio_tcp_handle_accept(server, &p->handle, on_close, (void*)p)) {
|
||||||
ASSERT(!r);
|
|
||||||
|
|
||||||
if (oio_tcp_handle_accept(server, &p->handle)) {
|
|
||||||
FATAL("oio_tcp_handle_accept failed");
|
FATAL("oio_tcp_handle_accept failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user