From ba31e8d0fa7a0e058805188d4627211d34896f9c Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Sun, 8 May 2011 05:40:09 -0400 Subject: [PATCH] Add _t to typedef structs --- oio-unix.c | 96 +++++++++++++++--------------- oio-unix.h | 4 +- oio-win.c | 114 ++++++++++++++++++------------------ oio-win.h | 8 +-- oio.h | 68 ++++++++++----------- test/benchmark-ping-pongs.c | 22 +++---- test/benchmark-sizes.c | 4 +- test/echo-server.c | 32 +++++----- test/test-bind-error.c | 14 ++--- test/test-callback-stack.c | 18 +++--- test/test-connection-fail.c | 10 ++-- test/test-delayed-accept.c | 26 ++++---- test/test-loop-handles.c | 36 ++++++------ test/test-ping-pong.c | 20 +++---- test/test-tcp-writealot.c | 24 ++++---- test/test-timeout.c | 16 ++--- 16 files changed, 256 insertions(+), 256 deletions(-) diff --git a/oio-unix.c b/oio-unix.c index 9fc4fb7e..e1277d83 100644 --- a/oio-unix.c +++ b/oio-unix.c @@ -40,9 +40,9 @@ static oio_alloc_cb alloc_cb; void oio__tcp_io(EV_P_ ev_io* watcher, int revents); void oio__next(EV_P_ ev_idle* watcher, int revents); -static void oio_tcp_connect(oio_handle* handle); -int oio_tcp_open(oio_handle*, int fd); -void oio_finish_close(oio_handle* handle); +static void oio_tcp_connect(oio_handle_t* handle); +int oio_tcp_open(oio_handle_t*, int fd); +void oio_finish_close(oio_handle_t* handle); /* flags */ @@ -55,7 +55,7 @@ enum { }; -void oio_flag_set(oio_handle* handle, int flag) { +void oio_flag_set(oio_handle_t* handle, int flag) { handle->flags |= flag; } @@ -70,12 +70,12 @@ char* oio_strerror(oio_err err) { } -void oio_flag_unset(oio_handle* handle, int flag) { +void oio_flag_unset(oio_handle_t* handle, int flag) { handle->flags = handle->flags & ~flag; } -int oio_flag_is_set(oio_handle* handle, int flag) { +int oio_flag_is_set(oio_handle_t* handle, int flag) { return (handle->flags & flag) != 0; } @@ -97,7 +97,7 @@ static oio_err_code oio_translate_sys_error(int sys_errno) { } -static oio_err oio_err_new_artificial(oio_handle* handle, int code) { +static oio_err oio_err_new_artificial(oio_handle_t* handle, int code) { oio_err err; err.sys_errno_ = 0; err.code = code; @@ -106,7 +106,7 @@ static oio_err oio_err_new_artificial(oio_handle* handle, int code) { } -static oio_err oio_err_new(oio_handle* handle, int sys_error) { +static oio_err oio_err_new(oio_handle_t* handle, int sys_error) { oio_err err; err.sys_errno_ = sys_error; err.code = oio_translate_sys_error(sys_error); @@ -126,7 +126,7 @@ struct sockaddr_in oio_ip4_addr(char* ip, int port) { } -int oio_close(oio_handle* handle) { +int oio_close(oio_handle_t* handle) { oio_flag_set(handle, OIO_CLOSING); ev_io_stop(EV_DEFAULT_ &handle->write_watcher); @@ -152,7 +152,7 @@ int oio_run() { } -int oio_tcp_init(oio_handle* handle, oio_close_cb close_cb, +int oio_tcp_init(oio_handle_t* handle, oio_close_cb close_cb, void* data) { handle->type = OIO_TCP; handle->close_cb = close_cb; @@ -181,7 +181,7 @@ int oio_tcp_init(oio_handle* handle, oio_close_cb close_cb, } -int oio_bind(oio_handle* handle, struct sockaddr* addr) { +int oio_bind(oio_handle_t* handle, struct sockaddr* addr) { int addrsize; int domain; int r; @@ -230,7 +230,7 @@ int oio_bind(oio_handle* handle, struct sockaddr* addr) { } -int oio_tcp_open(oio_handle* handle, int fd) { +int oio_tcp_open(oio_handle_t* handle, int fd) { assert(fd >= 0); handle->fd = fd; @@ -259,7 +259,7 @@ int oio_tcp_open(oio_handle* handle, int fd) { void oio__server_io(EV_P_ ev_io* watcher, int revents) { - oio_handle* handle = watcher->data; + oio_handle_t* handle = watcher->data; assert(watcher == &handle->read_watcher || watcher == &handle->write_watcher); assert(revents == EV_READ); @@ -303,7 +303,7 @@ void oio__server_io(EV_P_ ev_io* watcher, int revents) { } -int oio_accept(oio_handle* server, oio_handle* client, +int oio_accept(oio_handle_t* server, oio_handle_t* client, oio_close_cb close_cb, void* data) { if (server->accepted_fd < 0) { return -1; @@ -326,7 +326,7 @@ int oio_accept(oio_handle* server, oio_handle* client, } -int oio_listen(oio_handle* handle, int backlog, oio_accept_cb cb) { +int oio_listen(oio_handle_t* handle, int backlog, oio_accept_cb cb) { assert(handle->fd >= 0); if (handle->delayed_error) { @@ -351,7 +351,7 @@ int oio_listen(oio_handle* handle, int backlog, oio_accept_cb cb) { } -void oio_finish_close(oio_handle* handle) { +void oio_finish_close(oio_handle_t* handle) { assert(oio_flag_is_set(handle, OIO_CLOSING)); assert(!oio_flag_is_set(handle, OIO_CLOSED)); oio_flag_set(handle, OIO_CLOSED); @@ -375,7 +375,7 @@ void oio_finish_close(oio_handle* handle) { } -oio_req* oio_write_queue_head(oio_handle* handle) { +oio_req_t* oio_write_queue_head(oio_handle_t* handle) { if (ngx_queue_empty(&handle->write_queue)) { return NULL; } @@ -385,7 +385,7 @@ oio_req* oio_write_queue_head(oio_handle* handle) { return NULL; } - oio_req* req = ngx_queue_data(q, struct oio_req_s, queue); + oio_req_t* req = ngx_queue_data(q, struct oio_req_s, queue); assert(req); return req; @@ -393,7 +393,7 @@ oio_req* oio_write_queue_head(oio_handle* handle) { void oio__next(EV_P_ ev_idle* watcher, int revents) { - oio_handle* handle = watcher->data; + oio_handle_t* handle = watcher->data; assert(watcher == &handle->next_watcher); assert(revents == EV_IDLE); @@ -405,7 +405,7 @@ void oio__next(EV_P_ ev_idle* watcher, int revents) { } -static void oio__drain(oio_handle* handle) { +static void oio__drain(oio_handle_t* handle) { assert(!oio_write_queue_head(handle)); assert(handle->write_queue_size == 0); @@ -417,7 +417,7 @@ static void oio__drain(oio_handle* handle) { !oio_flag_is_set(handle, OIO_SHUT)) { assert(handle->shutdown_req); - oio_req* req = handle->shutdown_req; + oio_req_t* req = handle->shutdown_req; oio_shutdown_cb cb = req->cb; if (shutdown(handle->fd, SHUT_WR)) { @@ -434,13 +434,13 @@ static void oio__drain(oio_handle* handle) { } -void oio__write(oio_handle* handle) { +void oio__write(oio_handle_t* handle) { assert(handle->fd >= 0); /* TODO: should probably while(1) here until EAGAIN */ /* Get the request at the head of the queue. */ - oio_req* req = oio_write_queue_head(handle); + oio_req_t* req = oio_write_queue_head(handle); if (!req) { assert(handle->write_queue_size == 0); oio__drain(handle); @@ -541,7 +541,7 @@ void oio__write(oio_handle* handle) { } -void oio__read(oio_handle* handle) { +void oio__read(oio_handle_t* handle) { /* XXX: Maybe instead of having OIO_READING we just test if * handle->read_cb is NULL or not? */ @@ -591,8 +591,8 @@ void oio__read(oio_handle* handle) { } -int oio_shutdown(oio_req* req) { - oio_handle* handle = req->handle; +int oio_shutdown(oio_req_t* req) { + oio_handle_t* handle = req->handle; assert(handle->fd >= 0); if (oio_flag_is_set(handle, OIO_SHUT) || @@ -613,7 +613,7 @@ int oio_shutdown(oio_req* req) { void oio__tcp_io(EV_P_ ev_io* watcher, int revents) { - oio_handle* handle = watcher->data; + oio_handle_t* handle = watcher->data; assert(watcher == &handle->read_watcher || watcher == &handle->write_watcher); @@ -640,10 +640,10 @@ void oio__tcp_io(EV_P_ ev_io* watcher, int revents) { * In order to determine if we've errored out or succeeded must call * getsockopt. */ -static void oio_tcp_connect(oio_handle* handle) { +static void oio_tcp_connect(oio_handle_t* handle) { assert(handle->fd >= 0); - oio_req* req = handle->connect_req; + oio_req_t* req = handle->connect_req; assert(req); int error; @@ -679,8 +679,8 @@ static void oio_tcp_connect(oio_handle* handle) { } -int oio_connect(oio_req* req, struct sockaddr* addr) { - oio_handle* handle = req->handle; +int oio_connect(oio_req_t* req, struct sockaddr* addr) { + oio_handle_t* handle = req->handle; if (handle->fd <= 0) { int fd = socket(AF_INET, SOCK_STREAM, 0); @@ -740,8 +740,8 @@ static size_t oio__buf_count(oio_buf bufs[], int bufcnt) { /* The buffers to be written must remain valid until the callback is called. * This is not required for the oio_buf array. */ -int oio_write(oio_req* req, oio_buf bufs[], int bufcnt) { - oio_handle* handle = req->handle; +int oio_write(oio_req_t* req, oio_buf bufs[], int bufcnt) { + oio_handle_t* handle = req->handle; assert(handle->fd >= 0); ngx_queue_init(&req->queue); @@ -770,7 +770,7 @@ int oio_write(oio_req* req, oio_buf bufs[], int bufcnt) { void oio__timeout(EV_P_ ev_timer* watcher, int revents) { - oio_req* req = watcher->data; + oio_req_t* req = watcher->data; assert(watcher == &req->timer); assert(EV_TIMER & revents); @@ -796,7 +796,7 @@ int64_t oio_now() { } -int oio_timeout(oio_req* req, int64_t timeout) { +int oio_timeout(oio_req_t* req, int64_t timeout) { ev_timer_init(&req->timer, oio__timeout, timeout / 1000.0, 0.0); ev_timer_start(EV_DEFAULT_UC_ &req->timer); req->timer.data = req; @@ -804,7 +804,7 @@ int oio_timeout(oio_req* req, int64_t timeout) { } -int oio_read_start(oio_handle* handle, oio_read_cb cb) { +int oio_read_start(oio_handle_t* handle, oio_read_cb cb) { /* The OIO_READING flag is irrelevant of the state of the handle - it just * expresses the desired state of the user. */ @@ -826,7 +826,7 @@ int oio_read_start(oio_handle* handle, oio_read_cb cb) { } -int oio_read_stop(oio_handle* handle) { +int oio_read_stop(oio_handle_t* handle) { oio_flag_unset(handle, OIO_READING); ev_io_stop(EV_DEFAULT_UC_ &handle->read_watcher); @@ -835,14 +835,14 @@ int oio_read_stop(oio_handle* handle) { } -void oio_free(oio_handle* handle) { +void oio_free(oio_handle_t* handle) { free(handle); /* lists? */ return; } -void oio_req_init(oio_req* req, oio_handle* handle, void* cb) { +void oio_req_init(oio_req_t* req, oio_handle_t* handle, void* cb) { req->type = OIO_UNKNOWN_REQ; req->cb = cb; req->handle = handle; @@ -850,32 +850,32 @@ void oio_req_init(oio_req* req, oio_handle* handle, void* cb) { } -int oio_prepare_init(oio_handle* handle, oio_close_cb close_cb, void* data) { +int oio_prepare_init(oio_handle_t* handle, oio_close_cb close_cb, void* data) { assert(0 && "implement me"); } -int oio_prepare_start(oio_handle* handle, oio_loop_cb cb) { +int oio_prepare_start(oio_handle_t* handle, oio_loop_cb cb) { assert(0 && "implement me"); } -int oio_prepare_stop(oio_handle* handle) { +int oio_prepare_stop(oio_handle_t* handle) { assert(0 && "implement me"); } -int oio_check_init(oio_handle* handle, oio_close_cb close_cb, void* data) { +int oio_check_init(oio_handle_t* handle, oio_close_cb close_cb, void* data) { assert(0 && "implement me"); } -int oio_check_start(oio_handle* handle, oio_loop_cb cb) { +int oio_check_start(oio_handle_t* handle, oio_loop_cb cb) { assert(0 && "implement me"); } -int oio_check_stop(oio_handle* handle) { +int oio_check_stop(oio_handle_t* handle) { assert(0 && "implement me"); } @@ -890,16 +890,16 @@ void oio_unref() { } -int oio_idle_init(oio_handle* handle, oio_close_cb close_cb, void* data) { +int oio_idle_init(oio_handle_t* handle, oio_close_cb close_cb, void* data) { assert(0 && "implement me"); } -int oio_idle_start(oio_handle* handle, oio_loop_cb cb) { +int oio_idle_start(oio_handle_t* handle, oio_loop_cb cb) { assert(0 && "implement me"); } -int oio_idle_stop(oio_handle* handle) { +int oio_idle_stop(oio_handle_t* handle) { assert(0 && "implement me"); } diff --git a/oio-unix.h b/oio-unix.h index 39bd76bd..5e61b956 100644 --- a/oio-unix.h +++ b/oio-unix.h @@ -53,8 +53,8 @@ typedef struct { oio_read_cb read_cb; \ oio_accept_cb accept_cb; \ int accepted_fd; \ - oio_req *connect_req; \ - oio_req *shutdown_req; \ + oio_req_t *connect_req; \ + oio_req_t *shutdown_req; \ ev_io read_watcher; \ ev_io write_watcher; \ ev_idle next_watcher; \ diff --git a/oio-win.c b/oio-win.c index 23af2a04..e98517c1 100644 --- a/oio-win.c +++ b/oio-win.c @@ -117,7 +117,7 @@ static LPFN_TRANSMITFILE pTransmitFile; /* - * Private oio_handle flags + * Private oio_handle_t flags */ #define OIO_HANDLE_CLOSING 0x0001 #define OIO_HANDLE_CLOSED 0x0002 @@ -134,14 +134,14 @@ static LPFN_TRANSMITFILE pTransmitFile; #define OIO_HANDLE_BIND_ERROR 0x1000 /* - * Private oio_req flags. + * Private oio_req_t flags. */ /* The request is currently queued. */ #define OIO_REQ_PENDING 0x01 /* Binary tree used to keep the list of timers sorted. */ -static int oio_timer_compare(oio_req* t1, oio_req* t2); +static int oio_timer_compare(oio_req_t* t1, oio_req_t* t2); RB_HEAD(oio_timer_s, oio_req_s); RB_PROTOTYPE_STATIC(oio_timer_s, oio_req_s, tree_entry, oio_timer_compare); @@ -150,18 +150,18 @@ static struct oio_timer_s oio_timers_ = RB_INITIALIZER(oio_timers_); /* Lists of active oio_prepare / oio_check / oio_idle watchers */ -static oio_handle* oio_prepare_handles_ = NULL; -static oio_handle* oio_check_handles_ = NULL; -static oio_handle* oio_idle_handles_ = NULL; +static oio_handle_t* oio_prepare_handles_ = NULL; +static oio_handle_t* oio_check_handles_ = NULL; +static oio_handle_t* oio_idle_handles_ = NULL; /* This pointer will refer to the prepare/check/idle handle whose callback */ /* is scheduled to be called next. This is needed to allow safe removal */ /* from one of the lists above while that list being iterated. */ -static oio_handle* oio_next_loop_handle_ = NULL; +static oio_handle_t* oio_next_loop_handle_ = NULL; /* Head of a single-linked list of closed handles */ -static oio_handle* oio_endgame_handles_ = NULL; +static oio_handle_t* oio_endgame_handles_ = NULL; /* The current time according to the event loop. in msecs. */ @@ -379,7 +379,7 @@ void oio_init(oio_alloc_cb alloc_cb) { } -void oio_req_init(oio_req* req, oio_handle* handle, void* cb) { +void oio_req_init(oio_req_t* req, oio_handle_t* handle, void* cb) { req->type = OIO_UNKNOWN_REQ; req->flags = 0; req->handle = handle; @@ -387,12 +387,12 @@ void oio_req_init(oio_req* req, oio_handle* handle, void* cb) { } -static oio_req* oio_overlapped_to_req(OVERLAPPED* overlapped) { - return CONTAINING_RECORD(overlapped, oio_req, overlapped); +static oio_req_t* oio_overlapped_to_req(OVERLAPPED* overlapped) { + return CONTAINING_RECORD(overlapped, oio_req_t, overlapped); } -static int oio_tcp_init_socket(oio_handle* handle, oio_close_cb close_cb, +static int oio_tcp_init_socket(oio_handle_t* handle, oio_close_cb close_cb, void* data, SOCKET socket) { DWORD yes = 1; @@ -418,7 +418,7 @@ static int oio_tcp_init_socket(oio_handle* handle, oio_close_cb close_cb, } /* Associate it with the I/O completion port. */ - /* Use oio_handle pointer as completion key. */ + /* Use oio_handle_t pointer as completion key. */ if (CreateIoCompletionPort((HANDLE)socket, oio_iocp_, (ULONG_PTR)socket, @@ -433,14 +433,14 @@ static int oio_tcp_init_socket(oio_handle* handle, oio_close_cb close_cb, } -static void oio_tcp_init_connection(oio_handle* handle) { +static void oio_tcp_init_connection(oio_handle_t* handle) { handle->flags |= OIO_HANDLE_CONNECTION; handle->write_reqs_pending = 0; oio_req_init(&(handle->read_req), handle, NULL); } -int oio_tcp_init(oio_handle* handle, oio_close_cb close_cb, +int oio_tcp_init(oio_handle_t* handle, oio_close_cb close_cb, void* data) { SOCKET sock; @@ -459,7 +459,7 @@ int oio_tcp_init(oio_handle* handle, oio_close_cb close_cb, } -static void oio_tcp_endgame(oio_handle* handle) { +static void oio_tcp_endgame(oio_handle_t* handle) { oio_err err; int status; @@ -508,7 +508,7 @@ static void oio_tcp_endgame(oio_handle* handle) { } -static void oio_loop_endgame(oio_handle* handle) { +static void oio_loop_endgame(oio_handle_t* handle) { if (handle->flags & OIO_HANDLE_CLOSING) { assert(!(handle->flags & OIO_HANDLE_CLOSED)); handle->flags |= OIO_HANDLE_CLOSED; @@ -523,7 +523,7 @@ static void oio_loop_endgame(oio_handle* handle) { static void oio_call_endgames() { - oio_handle* handle; + oio_handle_t* handle; while (oio_endgame_handles_) { handle = oio_endgame_handles_; @@ -550,7 +550,7 @@ static void oio_call_endgames() { } -static void oio_want_endgame(oio_handle* handle) { +static void oio_want_endgame(oio_handle_t* handle) { if (!(handle->flags & OIO_HANDLE_ENDGAME_QUEUED)) { handle->flags |= OIO_HANDLE_ENDGAME_QUEUED; @@ -560,7 +560,7 @@ static void oio_want_endgame(oio_handle* handle) { } -static int oio_close_error(oio_handle* handle, oio_err e) { +static int oio_close_error(oio_handle_t* handle, oio_err e) { if (handle->flags & OIO_HANDLE_CLOSING) { return 0; } @@ -596,7 +596,7 @@ static int oio_close_error(oio_handle* handle, oio_err e) { } -int oio_close(oio_handle* handle) { +int oio_close(oio_handle_t* handle) { return oio_close_error(handle, oio_ok_); } @@ -612,7 +612,7 @@ struct sockaddr_in oio_ip4_addr(char* ip, int port) { } -int oio_bind(oio_handle* handle, struct sockaddr* addr) { +int oio_bind(oio_handle_t* handle, struct sockaddr* addr) { int addrsize; DWORD err; @@ -643,8 +643,8 @@ int oio_bind(oio_handle* handle, struct sockaddr* addr) { } -static void oio_queue_accept(oio_handle* handle) { - oio_req* req; +static void oio_queue_accept(oio_handle_t* handle) { + oio_req_t* req; BOOL success; DWORD bytes; SOCKET accept_socket; @@ -658,7 +658,7 @@ static void oio_queue_accept(oio_handle* handle) { return; } - /* Prepare the oio_req and OVERLAPPED structures. */ + /* Prepare the oio_req_t and OVERLAPPED structures. */ req = &handle->accept_req; assert(!(req->flags & OIO_REQ_PENDING)); req->type = OIO_ACCEPT; @@ -690,8 +690,8 @@ static void oio_queue_accept(oio_handle* handle) { } -static void oio_queue_read(oio_handle* handle) { - oio_req *req; +static void oio_queue_read(oio_handle_t* handle) { + oio_req_t *req; oio_buf buf; int result; DWORD bytes, flags; @@ -725,7 +725,7 @@ static void oio_queue_read(oio_handle* handle) { } -int oio_listen(oio_handle* handle, int backlog, oio_accept_cb cb) { +int oio_listen(oio_handle_t* handle, int backlog, oio_accept_cb cb) { assert(backlog > 0); if (handle->flags & OIO_HANDLE_BIND_ERROR) { @@ -755,7 +755,7 @@ int oio_listen(oio_handle* handle, int backlog, oio_accept_cb cb) { } -int oio_accept(oio_handle* server, oio_handle* client, +int oio_accept(oio_handle_t* server, oio_handle_t* client, oio_close_cb close_cb, void* data) { int rv = 0; @@ -782,7 +782,7 @@ int oio_accept(oio_handle* server, oio_handle* client, } -int oio_read_start(oio_handle* handle, oio_read_cb cb) { +int oio_read_start(oio_handle_t* handle, oio_read_cb cb) { if (!(handle->flags & OIO_HANDLE_CONNECTION)) { oio_set_sys_error(WSAEINVAL); return -1; @@ -810,18 +810,18 @@ int oio_read_start(oio_handle* handle, oio_read_cb cb) { } -int oio_read_stop(oio_handle* handle) { +int oio_read_stop(oio_handle_t* handle) { handle->flags &= ~OIO_HANDLE_READING; return 0; } -int oio_connect(oio_req* req, struct sockaddr* addr) { +int oio_connect(oio_req_t* req, struct sockaddr* addr) { int addrsize; BOOL success; DWORD bytes; - oio_handle* handle = req->handle; + oio_handle_t* handle = req->handle; assert(!(req->flags & OIO_REQ_PENDING)); @@ -867,10 +867,10 @@ int oio_connect(oio_req* req, struct sockaddr* addr) { } -int oio_write(oio_req* req, oio_buf bufs[], int bufcnt) { +int oio_write(oio_req_t* req, oio_buf bufs[], int bufcnt) { int result; DWORD bytes; - oio_handle* handle = req->handle; + oio_handle_t* handle = req->handle; assert(!(req->flags & OIO_REQ_PENDING)); @@ -907,8 +907,8 @@ int oio_write(oio_req* req, oio_buf bufs[], int bufcnt) { } -int oio_shutdown(oio_req* req) { - oio_handle* handle = req->handle; +int oio_shutdown(oio_req_t* req) { + oio_handle_t* handle = req->handle; int status = 0; if (!(req->handle->flags & OIO_HANDLE_CONNECTION)) { @@ -934,7 +934,7 @@ int oio_shutdown(oio_req* req) { } -static int oio_timer_compare(oio_req* a, oio_req* b) { +static int oio_timer_compare(oio_req_t* a, oio_req_t* b) { if (a->due < b->due) return -1; if (a->due > b->due) @@ -950,7 +950,7 @@ static int oio_timer_compare(oio_req* a, oio_req* b) { RB_GENERATE_STATIC(oio_timer_s, oio_req_s, tree_entry, oio_timer_compare); -int oio_timeout(oio_req* req, int64_t timeout) { +int oio_timeout(oio_req_t* req, int64_t timeout) { assert(!(req->flags & OIO_REQ_PENDING)); req->type = OIO_TIMEOUT; @@ -982,7 +982,7 @@ int64_t oio_now() { } -int oio_loop_init(oio_handle* handle, oio_close_cb close_cb, void* data) { +int oio_loop_init(oio_handle_t* handle, oio_close_cb close_cb, void* data) { handle->close_cb = (void*) close_cb; handle->data = data; handle->flags = 0; @@ -994,9 +994,9 @@ int oio_loop_init(oio_handle* handle, oio_close_cb close_cb, void* data) { } -static int oio_loop_start(oio_handle* handle, oio_loop_cb loop_cb, - oio_handle** list) { - oio_handle* old_head; +static int oio_loop_start(oio_handle_t* handle, oio_loop_cb loop_cb, + oio_handle_t** list) { + oio_handle_t* old_head; if (handle->flags & OIO_HANDLE_ACTIVE) return 0; @@ -1019,7 +1019,7 @@ static int oio_loop_start(oio_handle* handle, oio_loop_cb loop_cb, } -static int oio_loop_stop(oio_handle* handle, oio_handle** list) { +static int oio_loop_stop(oio_handle_t* handle, oio_handle_t** list) { if (!(handle->flags & OIO_HANDLE_ACTIVE)) return 0; @@ -1046,8 +1046,8 @@ static int oio_loop_stop(oio_handle* handle, oio_handle** list) { } -static void oio_loop_invoke(oio_handle* list) { - oio_handle *handle; +static void oio_loop_invoke(oio_handle_t* list) { + oio_handle_t *handle; oio_next_loop_handle_ = list; @@ -1060,55 +1060,55 @@ static void oio_loop_invoke(oio_handle* list) { } -int oio_prepare_init(oio_handle* handle, oio_close_cb close_cb, void* data) { +int oio_prepare_init(oio_handle_t* handle, oio_close_cb close_cb, void* data) { handle->type = OIO_PREPARE; return oio_loop_init(handle, close_cb, data); } -int oio_check_init(oio_handle* handle, oio_close_cb close_cb, void* data) { +int oio_check_init(oio_handle_t* handle, oio_close_cb close_cb, void* data) { handle->type = OIO_CHECK; return oio_loop_init(handle, close_cb, data); } -int oio_idle_init(oio_handle* handle, oio_close_cb close_cb, void* data) { +int oio_idle_init(oio_handle_t* handle, oio_close_cb close_cb, void* data) { handle->type = OIO_IDLE; return oio_loop_init(handle, close_cb, data); } -int oio_prepare_start(oio_handle* handle, oio_loop_cb loop_cb) { +int oio_prepare_start(oio_handle_t* handle, oio_loop_cb loop_cb) { assert(handle->type == OIO_PREPARE); return oio_loop_start(handle, loop_cb, &oio_prepare_handles_); } -int oio_check_start(oio_handle* handle, oio_loop_cb loop_cb) { +int oio_check_start(oio_handle_t* handle, oio_loop_cb loop_cb) { assert(handle->type == OIO_CHECK); return oio_loop_start(handle, loop_cb, &oio_check_handles_); } -int oio_idle_start(oio_handle* handle, oio_loop_cb loop_cb) { +int oio_idle_start(oio_handle_t* handle, oio_loop_cb loop_cb) { assert(handle->type == OIO_IDLE); return oio_loop_start(handle, loop_cb, &oio_idle_handles_); } -int oio_prepare_stop(oio_handle* handle) { +int oio_prepare_stop(oio_handle_t* handle) { assert(handle->type == OIO_PREPARE); return oio_loop_stop(handle, &oio_prepare_handles_); } -int oio_check_stop(oio_handle* handle) { +int oio_check_stop(oio_handle_t* handle) { assert(handle->type == OIO_CHECK); return oio_loop_stop(handle, &oio_check_handles_); } -int oio_idle_stop(oio_handle* handle) { +int oio_idle_stop(oio_handle_t* handle) { assert(handle->type == OIO_IDLE); return oio_loop_stop(handle, &oio_idle_handles_); } @@ -1119,8 +1119,8 @@ static void oio_poll() { DWORD bytes; ULONG_PTR key; OVERLAPPED* overlapped; - oio_req* req; - oio_handle* handle; + oio_req_t* req; + oio_handle_t* handle; oio_buf buf; DWORD timeout; DWORD flags; diff --git a/oio-win.h b/oio-win.h index b44ba45d..07eb29fe 100644 --- a/oio-win.h +++ b/oio-win.h @@ -57,7 +57,7 @@ typedef struct oio_buf { void* read_cb; \ struct oio_req_s read_req; \ unsigned int write_reqs_pending; \ - oio_req* shutdown_req; + oio_req_t* shutdown_req; #define oio_tcp_server_fields \ void *accept_cb; \ @@ -77,12 +77,12 @@ typedef struct oio_buf { }; #define oio_loop_fields \ - oio_handle* loop_prev; \ - oio_handle* loop_next; \ + oio_handle_t* loop_prev; \ + oio_handle_t* loop_next; \ void* loop_cb; #define oio_handle_private_fields \ - oio_handle* endgame_next; \ + oio_handle_t* endgame_next; \ unsigned int flags; \ oio_err error; \ union { \ diff --git a/oio.h b/oio.h index a8264573..6cceb64a 100644 --- a/oio.h +++ b/oio.h @@ -29,8 +29,8 @@ #include /* size_t */ typedef struct oio_err_s oio_err; -typedef struct oio_handle_s oio_handle; -typedef struct oio_req_s oio_req; +typedef struct oio_handle_s oio_handle_t; +typedef struct oio_req_s oio_req_t; #if defined(__unix__) || defined(__POSIX__) || defined(__APPLE__) @@ -48,15 +48,15 @@ typedef struct oio_req_s oio_req; * In the case of oio_read_cb the oio_buf returned should be freed by the * user. */ -typedef oio_buf (*oio_alloc_cb)(oio_handle* handle, size_t suggested_size); -typedef void (*oio_read_cb)(oio_handle *handle, int nread, oio_buf buf); -typedef void (*oio_write_cb)(oio_req* req, int status); -typedef void (*oio_connect_cb)(oio_req* req, int status); -typedef void (*oio_shutdown_cb)(oio_req* req, int status); -typedef void (*oio_accept_cb)(oio_handle* handle); -typedef void (*oio_close_cb)(oio_handle* handle, int status); -typedef void (*oio_timer_cb)(oio_req* req, int64_t skew, int status); -typedef void (*oio_loop_cb)(oio_handle* handle, int status); +typedef oio_buf (*oio_alloc_cb)(oio_handle_t* handle, size_t suggested_size); +typedef void (*oio_read_cb)(oio_handle_t *handle, int nread, oio_buf buf); +typedef void (*oio_write_cb)(oio_req_t* req, int status); +typedef void (*oio_connect_cb)(oio_req_t* req, int status); +typedef void (*oio_shutdown_cb)(oio_req_t* req, int status); +typedef void (*oio_accept_cb)(oio_handle_t* handle); +typedef void (*oio_close_cb)(oio_handle_t* handle, int status); +typedef void (*oio_timer_cb)(oio_req_t* req, int64_t skew, int status); +typedef void (*oio_loop_cb)(oio_handle_t* handle, int status); /* Expand this list if necessary. */ @@ -132,7 +132,7 @@ struct oio_req_s { /* read-only */ oio_req_type type; /* public */ - oio_handle* handle; + oio_handle_t* handle; void* cb; void* data; /* private */ @@ -171,30 +171,30 @@ void oio_unref(); void oio_update_time(); int64_t oio_now(); -void oio_req_init(oio_req* req, oio_handle* handle, void* cb); +void oio_req_init(oio_req_t* req, oio_handle_t* handle, void* cb); /* * TODO: * - oio_(pipe|pipe_tty)_handle_init * - oio_bind_pipe(char* name) - * - oio_continuous_read(oio_handle* handle, oio_continuous_read_cb* cb) + * - oio_continuous_read(oio_handle_t* handle, oio_continuous_read_cb* cb) * - A way to list cancelled oio_reqs after before/on oio_close_cb */ /* TCP socket methods. * Handle and callback bust be set by calling oio_req_init. */ -int oio_tcp_init(oio_handle* handle, oio_close_cb close_cb, void* data); -int oio_bind(oio_handle* handle, struct sockaddr* addr); +int oio_tcp_init(oio_handle_t* handle, oio_close_cb close_cb, void* data); +int oio_bind(oio_handle_t* handle, struct sockaddr* addr); -int oio_connect(oio_req* req, struct sockaddr* addr); -int oio_shutdown(oio_req* req); +int oio_connect(oio_req_t* req, struct sockaddr* addr); +int oio_shutdown(oio_req_t* req); /* TCP server methods. */ -int oio_listen(oio_handle* handle, int backlog, oio_accept_cb cb); +int oio_listen(oio_handle_t* handle, int backlog, oio_accept_cb cb); /* Call this after accept_cb. client does not need to be initialized. */ -int oio_accept(oio_handle* server, oio_handle* client, +int oio_accept(oio_handle_t* server, oio_handle_t* client, oio_close_cb close_cb, void* data); @@ -206,38 +206,38 @@ int oio_accept(oio_handle* server, oio_handle* client, /* Note that nread might also be 0, which does *not* indicate an error or */ /* eof; it happens when liboio requested a buffer through the alloc callback */ /* but then decided that it didn't need that buffer. */ -int oio_read_start(oio_handle* handle, oio_read_cb cb); -int oio_read_stop(oio_handle* handle); +int oio_read_start(oio_handle_t* handle, oio_read_cb cb); +int oio_read_stop(oio_handle_t* handle); -int oio_write(oio_req* req, oio_buf bufs[], int bufcnt); +int oio_write(oio_req_t* req, oio_buf bufs[], int bufcnt); /* Timer methods */ -int oio_timeout(oio_req* req, int64_t timeout); +int oio_timeout(oio_req_t* req, int64_t timeout); /* Every active prepare handle gets its callback called exactly once per loop */ /* iteration, just before the system blocks to wait for completed i/o. */ -int oio_prepare_init(oio_handle* handle, oio_close_cb close_cb, void* data); -int oio_prepare_start(oio_handle* handle, oio_loop_cb cb); -int oio_prepare_stop(oio_handle* handle); +int oio_prepare_init(oio_handle_t* handle, oio_close_cb close_cb, void* data); +int oio_prepare_start(oio_handle_t* handle, oio_loop_cb cb); +int oio_prepare_stop(oio_handle_t* handle); /* Every active check handle gets its callback called exactly once per loop */ /* iteration, just after the system returns from blocking. */ -int oio_check_init(oio_handle* handle, oio_close_cb close_cb, void* data); -int oio_check_start(oio_handle* handle, oio_loop_cb cb); -int oio_check_stop(oio_handle* handle); +int oio_check_init(oio_handle_t* handle, oio_close_cb close_cb, void* data); +int oio_check_start(oio_handle_t* handle, oio_loop_cb cb); +int oio_check_stop(oio_handle_t* handle); /* Every active idle handle gets its callback called repeatedly until it is */ /* stopped. This happens after all other types of callbacks are processed. */ /* When there are multiple "idle" handles active, their callbacks are called */ /* in turn. */ -int oio_idle_init(oio_handle* handle, oio_close_cb close_cb, void* data); -int oio_idle_start(oio_handle* handle, oio_loop_cb cb); -int oio_idle_stop(oio_handle* handle); +int oio_idle_init(oio_handle_t* handle, oio_close_cb close_cb, void* data); +int oio_idle_start(oio_handle_t* handle, oio_loop_cb cb); +int oio_idle_stop(oio_handle_t* handle); /* Request handle to be closed. close_cb will be called * asynchronously after this call. */ -int oio_close(oio_handle* handle); +int oio_close(oio_handle_t* handle); /* Utility */ diff --git a/test/benchmark-ping-pongs.c b/test/benchmark-ping-pongs.c index 368380ea..6886b50b 100644 --- a/test/benchmark-ping-pongs.c +++ b/test/benchmark-ping-pongs.c @@ -33,9 +33,9 @@ typedef struct { int pongs; int state; - oio_handle handle; - oio_req connect_req; - oio_req shutdown_req; + oio_handle_t handle; + oio_req_t connect_req; + oio_req_t shutdown_req; } pinger_t; typedef struct buf_s { @@ -52,7 +52,7 @@ static int completed_pingers = 0; static int64_t start_time; -static oio_buf buf_alloc(oio_handle* handle, size_t size) { +static oio_buf buf_alloc(oio_handle_t* handle, size_t size) { buf_t* ab; ab = buf_freelist; @@ -78,7 +78,7 @@ static void buf_free(oio_buf oio_buf) { } -static void pinger_close_cb(oio_handle* handle, int status) { +static void pinger_close_cb(oio_handle_t* handle, int status) { pinger_t* pinger; ASSERT(status == 0); @@ -92,7 +92,7 @@ static void pinger_close_cb(oio_handle* handle, int status) { } -static void pinger_write_cb(oio_req *req, int status) { +static void pinger_write_cb(oio_req_t *req, int status) { ASSERT(status == 0); free(req); @@ -100,13 +100,13 @@ static void pinger_write_cb(oio_req *req, int status) { static void pinger_write_ping(pinger_t* pinger) { - oio_req *req; + oio_req_t *req; oio_buf buf; buf.base = (char*)&PING; buf.len = strlen(PING); - req = (oio_req*)malloc(sizeof(*req)); + req = (oio_req_t*)malloc(sizeof(*req)); oio_req_init(req, &pinger->handle, pinger_write_cb); if (oio_write(req, &buf, 1)) { @@ -115,12 +115,12 @@ static void pinger_write_ping(pinger_t* pinger) { } -static void pinger_shutdown_cb(oio_handle* handle, int status) { +static void pinger_shutdown_cb(oio_handle_t* handle, int status) { ASSERT(status == 0); } -static void pinger_read_cb(oio_handle* handle, int nread, oio_buf buf) { +static void pinger_read_cb(oio_handle_t* handle, int nread, oio_buf buf) { unsigned int i; pinger_t* pinger; @@ -157,7 +157,7 @@ static void pinger_read_cb(oio_handle* handle, int nread, oio_buf buf) { } -static void pinger_connect_cb(oio_req *req, int status) { +static void pinger_connect_cb(oio_req_t *req, int status) { pinger_t *pinger = (pinger_t*)req->handle->data; ASSERT(status == 0); diff --git a/test/benchmark-sizes.c b/test/benchmark-sizes.c index 5710a7ff..b97912bb 100644 --- a/test/benchmark-sizes.c +++ b/test/benchmark-sizes.c @@ -23,12 +23,12 @@ #include "../oio.h" BENCHMARK_IMPL(size_handle) { - LOGF("%lu oio_handle\n", sizeof(oio_handle)); + LOGF("%lu oio_handle_t\n", sizeof(oio_handle_t)); return 0; } BENCHMARK_IMPL(size_req) { - LOGF("%lu oio_req\n", sizeof(oio_req)); + LOGF("%lu oio_req_t\n", sizeof(oio_req_t)); return 0; } diff --git a/test/echo-server.c b/test/echo-server.c index ee3c925c..bc8d5781 100644 --- a/test/echo-server.c +++ b/test/echo-server.c @@ -26,21 +26,21 @@ typedef struct { - oio_req req; + oio_req_t req; oio_buf buf; } write_req_t; -static oio_handle server; +static oio_handle_t server; -static void after_write(oio_req* req, int status); -static void after_read(oio_handle* handle, int nread, oio_buf buf); -static void on_close(oio_handle* peer, int status); -static void on_accept(oio_handle* handle); +static void after_write(oio_req_t* req, int status); +static void after_read(oio_handle_t* handle, int nread, oio_buf buf); +static void on_close(oio_handle_t* peer, int status); +static void on_accept(oio_handle_t* handle); -static void after_write(oio_req* req, int status) { +static void after_write(oio_req_t* req, int status) { write_req_t* wr; if (status) { @@ -57,14 +57,14 @@ static void after_write(oio_req* req, int status) { } -static void after_shutdown(oio_req* req, int status) { +static void after_shutdown(oio_req_t* req, int status) { free(req); } -static void after_read(oio_handle* handle, int nread, oio_buf buf) { +static void after_read(oio_handle_t* handle, int nread, oio_buf buf) { write_req_t *wr; - oio_req* req; + oio_req_t* req; if (nread < 0) { /* Error or EOF */ @@ -74,7 +74,7 @@ static void after_read(oio_handle* handle, int nread, oio_buf buf) { free(buf.base); } - req = (oio_req*) malloc(sizeof *req); + req = (oio_req_t*) malloc(sizeof *req); oio_req_init(req, handle, after_shutdown); oio_shutdown(req); @@ -98,15 +98,15 @@ static void after_read(oio_handle* handle, int nread, oio_buf buf) { } -static void on_close(oio_handle* peer, int status) { +static void on_close(oio_handle_t* peer, int status) { if (status != 0) { fprintf(stdout, "Socket error\n"); } } -static void on_accept(oio_handle* server) { - oio_handle* handle = (oio_handle*) malloc(sizeof *handle); +static void on_accept(oio_handle_t* server) { + oio_handle_t* handle = (oio_handle_t*) malloc(sizeof *handle); if (oio_accept(server, handle, on_close, NULL)) { FATAL("oio_accept failed"); @@ -116,7 +116,7 @@ static void on_accept(oio_handle* server) { } -static void on_server_close(oio_handle* handle, int status) { +static void on_server_close(oio_handle_t* handle, int status) { ASSERT(handle == &server); ASSERT(status == 0); } @@ -156,7 +156,7 @@ static int echo_stop() { } -static oio_buf echo_alloc(oio_handle* handle, size_t suggested_size) { +static oio_buf echo_alloc(oio_handle_t* handle, size_t suggested_size) { oio_buf buf; buf.base = (char*) malloc(suggested_size); buf.len = suggested_size; diff --git a/test/test-bind-error.c b/test/test-bind-error.c index a156acad..da0f1d09 100644 --- a/test/test-bind-error.c +++ b/test/test-bind-error.c @@ -28,7 +28,7 @@ static int close_cb_called = 0; -static void close_cb(oio_handle* handle, int status) { +static void close_cb(oio_handle_t* handle, int status) { ASSERT(handle != NULL); ASSERT(status == 0); @@ -36,7 +36,7 @@ static void close_cb(oio_handle* handle, int status) { } -static oio_buf alloc_cb(oio_handle* handle, size_t size) { +static oio_buf alloc_cb(oio_handle_t* handle, size_t size) { oio_buf buf = {0, 0}; FATAL("alloc should not be called"); return buf; @@ -45,7 +45,7 @@ static oio_buf alloc_cb(oio_handle* handle, size_t size) { TEST_IMPL(bind_error_addrinuse) { struct sockaddr_in addr = oio_ip4_addr("0.0.0.0", TEST_PORT); - oio_handle server1, server2; + oio_handle_t server1, server2; int r; oio_init(alloc_cb); @@ -80,7 +80,7 @@ TEST_IMPL(bind_error_addrinuse) { TEST_IMPL(bind_error_addrnotavail_1) { struct sockaddr_in addr = oio_ip4_addr("127.255.255.255", TEST_PORT); - oio_handle server; + oio_handle_t server; int r; oio_init(alloc_cb); @@ -106,7 +106,7 @@ TEST_IMPL(bind_error_addrnotavail_1) { TEST_IMPL(bind_error_addrnotavail_2) { struct sockaddr_in addr = oio_ip4_addr("4.4.4.4", TEST_PORT); - oio_handle server; + oio_handle_t server; int r; oio_init(alloc_cb); @@ -129,7 +129,7 @@ TEST_IMPL(bind_error_addrnotavail_2) { TEST_IMPL(bind_error_fault) { char garbage[] = "blah blah blah blah blah blah blah blah blah blah blah blah"; - oio_handle server; + oio_handle_t server; int r; oio_init(alloc_cb); @@ -155,7 +155,7 @@ TEST_IMPL(bind_error_fault) { TEST_IMPL(bind_error_inval) { struct sockaddr_in addr1 = oio_ip4_addr("0.0.0.0", TEST_PORT); struct sockaddr_in addr2 = oio_ip4_addr("0.0.0.0", TEST_PORT_2); - oio_handle server; + oio_handle_t server; int r; oio_init(alloc_cb); diff --git a/test/test-callback-stack.c b/test/test-callback-stack.c index edf42d9d..2c5df068 100644 --- a/test/test-callback-stack.c +++ b/test/test-callback-stack.c @@ -30,8 +30,8 @@ static const char MESSAGE[] = "Failure is for the weak. Everyone dies alone."; -static oio_handle client; -static oio_req connect_req, write_req, timeout_req, shutdown_req; +static oio_handle_t client; +static oio_req_t connect_req, write_req, timeout_req, shutdown_req; static int nested = 0; static int close_cb_called = 0; @@ -42,7 +42,7 @@ static int bytes_received = 0; static int shutdown_cb_called = 0; -static void close_cb(oio_handle* handle, int status) { +static void close_cb(oio_handle_t* handle, int status) { ASSERT(status == 0); ASSERT(nested == 0 && "close_cb must be called from a fresh stack"); @@ -50,7 +50,7 @@ static void close_cb(oio_handle* handle, int status) { } -static void shutdown_cb(oio_req* req, int status) { +static void shutdown_cb(oio_req_t* req, int status) { ASSERT(status == 0); ASSERT(nested == 0 && "shutdown_cb must be called from a fresh stack"); @@ -58,7 +58,7 @@ static void shutdown_cb(oio_req* req, int status) { } -static void read_cb(oio_handle* handle, int nread, oio_buf buf) { +static void read_cb(oio_handle_t* handle, int nread, oio_buf buf) { ASSERT(nested == 0 && "read_cb must be called from a fresh stack"); printf("Read. nread == %d\n", nread); @@ -100,7 +100,7 @@ static void read_cb(oio_handle* handle, int nread, oio_buf buf) { } -static void timeout_cb(oio_req* req, int64_t skew, int status) { +static void timeout_cb(oio_req_t* req, int64_t skew, int status) { ASSERT(status == 0); ASSERT(nested == 0 && "timeout_cb must be called from a fresh stack"); @@ -116,7 +116,7 @@ static void timeout_cb(oio_req* req, int64_t skew, int status) { } -static void write_cb(oio_req* req, int status) { +static void write_cb(oio_req_t* req, int status) { ASSERT(status == 0); ASSERT(nested == 0 && "write_cb must be called from a fresh stack"); @@ -137,7 +137,7 @@ static void write_cb(oio_req* req, int status) { } -static void connect_cb(oio_req* req, int status) { +static void connect_cb(oio_req_t* req, int status) { oio_buf buf; puts("Connected. Write some data to echo server..."); @@ -162,7 +162,7 @@ static void connect_cb(oio_req* req, int status) { } -static oio_buf alloc_cb(oio_handle* handle, size_t size) { +static oio_buf alloc_cb(oio_handle_t* handle, size_t size) { oio_buf buf; buf.len = size; buf.base = (char*) malloc(size); diff --git a/test/test-connection-fail.c b/test/test-connection-fail.c index 05cb68d4..50c1de06 100644 --- a/test/test-connection-fail.c +++ b/test/test-connection-fail.c @@ -26,19 +26,19 @@ #include -static oio_handle handle; -static oio_req req; +static oio_handle_t handle; +static oio_req_t req; static int connect_cb_calls; static int close_cb_calls; -static void on_close(oio_handle* handle, int status) { +static void on_close(oio_handle_t* handle, int status) { ASSERT(status == 0); close_cb_calls++; } -static void on_connect(oio_req *req, int status) { +static void on_connect(oio_req_t *req, int status) { ASSERT(status == -1); ASSERT(oio_last_error().code == OIO_ECONNREFUSED); connect_cb_calls++; @@ -46,7 +46,7 @@ static void on_connect(oio_req *req, int status) { } -static oio_buf alloc_cb(oio_handle* handle, size_t size) { +static oio_buf alloc_cb(oio_handle_t* handle, size_t size) { oio_buf buf = {0, 0}; FATAL("alloc should not be called"); return buf; diff --git a/test/test-delayed-accept.c b/test/test-delayed-accept.c index af5945f4..adaaeceb 100644 --- a/test/test-delayed-accept.c +++ b/test/test-delayed-accept.c @@ -33,7 +33,7 @@ static int close_cb_called = 0; static int connect_cb_called = 0; -static void close_cb(oio_handle* handle, int status) { +static void close_cb(oio_handle_t* handle, int status) { ASSERT(handle != NULL); ASSERT(status == 0); @@ -43,16 +43,16 @@ static void close_cb(oio_handle* handle, int status) { } -static void do_accept(oio_req* req, int64_t skew, int status) { - oio_handle* server; - oio_handle* accepted_handle = (oio_handle*)malloc(sizeof *accepted_handle); +static void do_accept(oio_req_t* req, int64_t skew, int status) { + oio_handle_t* server; + oio_handle_t* accepted_handle = (oio_handle_t*)malloc(sizeof *accepted_handle); int r; ASSERT(req != NULL); ASSERT(status == 0); ASSERT(accepted_handle != NULL); - server = (oio_handle*)req->data; + server = (oio_handle_t*)req->data; r = oio_accept(server, accepted_handle, close_cb, NULL); ASSERT(r == 0); @@ -70,8 +70,8 @@ static void do_accept(oio_req* req, int64_t skew, int status) { } -static void accept_cb(oio_handle* handle) { - oio_req* timeout_req = (oio_req*)malloc(sizeof *timeout_req); +static void accept_cb(oio_handle_t* handle) { + oio_req_t* timeout_req = (oio_req_t*)malloc(sizeof *timeout_req); ASSERT(timeout_req != NULL); @@ -86,7 +86,7 @@ static void accept_cb(oio_handle* handle) { static void start_server() { struct sockaddr_in addr = oio_ip4_addr("0.0.0.0", TEST_PORT); - oio_handle* server = (oio_handle*)malloc(sizeof *server); + oio_handle_t* server = (oio_handle_t*)malloc(sizeof *server); int r; ASSERT(server != NULL); @@ -102,7 +102,7 @@ static void start_server() { } -static void read_cb(oio_handle* handle, int nread, oio_buf buf) { +static void read_cb(oio_handle_t* handle, int nread, oio_buf buf) { /* The server will not send anything, it should close gracefully. */ ASSERT(handle != NULL); ASSERT(nread == -1); @@ -116,7 +116,7 @@ static void read_cb(oio_handle* handle, int nread, oio_buf buf) { } -static void connect_cb(oio_req* req, int status) { +static void connect_cb(oio_req_t* req, int status) { int r; ASSERT(req != NULL); @@ -135,8 +135,8 @@ static void connect_cb(oio_req* req, int status) { static void client_connect() { struct sockaddr_in addr = oio_ip4_addr("127.0.0.1", TEST_PORT); - oio_handle* client = (oio_handle*)malloc(sizeof *client); - oio_req* connect_req = (oio_req*)malloc(sizeof *connect_req); + oio_handle_t* client = (oio_handle_t*)malloc(sizeof *client); + oio_req_t* connect_req = (oio_req_t*)malloc(sizeof *connect_req); int r; ASSERT(client != NULL); @@ -151,7 +151,7 @@ static void client_connect() { } -static oio_buf alloc_cb(oio_handle* handle, size_t size) { +static oio_buf alloc_cb(oio_handle_t* handle, size_t size) { oio_buf buf; buf.base = (char*)malloc(size); buf.len = size; diff --git a/test/test-loop-handles.c b/test/test-loop-handles.c index d53c459d..81271fed 100644 --- a/test/test-loop-handles.c +++ b/test/test-loop-handles.c @@ -72,15 +72,15 @@ #define TIMEOUT 100 -static oio_handle prepare_1_handle; -static oio_handle prepare_2_handle; +static oio_handle_t prepare_1_handle; +static oio_handle_t prepare_2_handle; -static oio_handle check_handle; +static oio_handle_t check_handle; -static oio_handle idle_1_handles[IDLE_COUNT]; -static oio_handle idle_2_handle; +static oio_handle_t idle_1_handles[IDLE_COUNT]; +static oio_handle_t idle_2_handle; -static oio_req timeout_req; +static oio_req_t timeout_req; static int loop_iteration = 0; @@ -106,7 +106,7 @@ static int idle_2_is_active = 0; static int timeout_cb_called = 0; -static void timeout_cb(oio_req *req, int64_t skew, int status) { +static void timeout_cb(oio_req_t *req, int64_t skew, int status) { ASSERT(req == &timeout_req); ASSERT(status == 0); @@ -116,7 +116,7 @@ static void timeout_cb(oio_req *req, int64_t skew, int status) { } -static void idle_2_cb(oio_handle* handle, int status) { +static void idle_2_cb(oio_handle_t* handle, int status) { ASSERT(handle == &idle_2_handle); ASSERT(status == 0); @@ -126,7 +126,7 @@ static void idle_2_cb(oio_handle* handle, int status) { } -static void idle_2_close_cb(oio_handle* handle, int status){ +static void idle_2_close_cb(oio_handle_t* handle, int status){ ASSERT(handle == &idle_2_handle); ASSERT(status == 0); @@ -137,7 +137,7 @@ static void idle_2_close_cb(oio_handle* handle, int status){ } -static void idle_1_cb(oio_handle* handle, int status) { +static void idle_1_cb(oio_handle_t* handle, int status) { ASSERT(handle != NULL); ASSERT(status == 0); @@ -160,7 +160,7 @@ static void idle_1_cb(oio_handle* handle, int status) { } -static void idle_1_close_cb(oio_handle* handle, int status){ +static void idle_1_close_cb(oio_handle_t* handle, int status){ ASSERT(handle != NULL); ASSERT(status == 0); @@ -168,7 +168,7 @@ static void idle_1_close_cb(oio_handle* handle, int status){ } -static void check_cb(oio_handle* handle, int status) { +static void check_cb(oio_handle_t* handle, int status) { int i; ASSERT(handle == &check_handle); @@ -205,7 +205,7 @@ static void check_cb(oio_handle* handle, int status) { } -static void check_close_cb(oio_handle* handle, int status){ +static void check_close_cb(oio_handle_t* handle, int status){ ASSERT(handle == &check_handle); ASSERT(status == 0); @@ -213,7 +213,7 @@ static void check_close_cb(oio_handle* handle, int status){ } -static void prepare_2_cb(oio_handle* handle, int status) { +static void prepare_2_cb(oio_handle_t* handle, int status) { ASSERT(handle == &prepare_2_handle); ASSERT(status == 0); @@ -232,7 +232,7 @@ static void prepare_2_cb(oio_handle* handle, int status) { } -static void prepare_2_close_cb(oio_handle* handle, int status){ +static void prepare_2_close_cb(oio_handle_t* handle, int status){ ASSERT(handle == &prepare_2_handle); ASSERT(status == 0); @@ -240,7 +240,7 @@ static void prepare_2_close_cb(oio_handle* handle, int status){ } -static void prepare_1_cb(oio_handle* handle, int status) { +static void prepare_1_cb(oio_handle_t* handle, int status) { ASSERT(handle == &prepare_1_handle); ASSERT(status == 0); @@ -258,7 +258,7 @@ static void prepare_1_cb(oio_handle* handle, int status) { } -static void prepare_1_close_cb(oio_handle* handle, int status){ +static void prepare_1_close_cb(oio_handle_t* handle, int status){ ASSERT(handle == &prepare_1_handle); ASSERT(status == 0); @@ -266,7 +266,7 @@ static void prepare_1_close_cb(oio_handle* handle, int status){ } -static oio_buf alloc_cb(oio_handle* handle, size_t size) { +static oio_buf alloc_cb(oio_handle_t* handle, size_t size) { oio_buf rv = { 0, 0 }; FATAL("alloc_cb should never be called in this test"); return rv; diff --git a/test/test-ping-pong.c b/test/test-ping-pong.c index afba7579..01da3bc4 100644 --- a/test/test-ping-pong.c +++ b/test/test-ping-pong.c @@ -39,16 +39,16 @@ static char PING[] = "PING\n"; typedef struct { int pongs; int state; - oio_handle handle; - oio_req connect_req; - oio_req read_req; + oio_handle_t handle; + oio_req_t connect_req; + oio_req_t read_req; char read_buffer[BUFSIZE]; } pinger_t; void pinger_try_read(pinger_t* pinger); -static void pinger_on_close(oio_handle* handle, int status) { +static void pinger_on_close(oio_handle_t* handle, int status) { pinger_t* pinger = (pinger_t*)handle->data; ASSERT(status == 0); @@ -60,7 +60,7 @@ static void pinger_on_close(oio_handle* handle, int status) { } -static void pinger_after_write(oio_req *req, int status) { +static void pinger_after_write(oio_req_t *req, int status) { ASSERT(status == 0); free(req); @@ -68,13 +68,13 @@ static void pinger_after_write(oio_req *req, int status) { static void pinger_write_ping(pinger_t* pinger) { - oio_req *req; + oio_req_t *req; oio_buf buf; buf.base = (char*)&PING; buf.len = strlen(PING); - req = (oio_req*)malloc(sizeof(*req)); + req = (oio_req_t*)malloc(sizeof(*req)); oio_req_init(req, &pinger->handle, pinger_after_write); if (oio_write(req, &buf, 1)) { @@ -85,7 +85,7 @@ static void pinger_write_ping(pinger_t* pinger) { } -static void pinger_read_cb(oio_handle* handle, int nread, oio_buf buf) { +static void pinger_read_cb(oio_handle_t* handle, int nread, oio_buf buf) { unsigned int i; pinger_t* pinger; @@ -123,7 +123,7 @@ static void pinger_read_cb(oio_handle* handle, int nread, oio_buf buf) { } -static void pinger_on_connect(oio_req *req, int status) { +static void pinger_on_connect(oio_req_t *req, int status) { pinger_t *pinger = (pinger_t*)req->handle->data; ASSERT(status == 0); @@ -156,7 +156,7 @@ static void pinger_new() { } -static oio_buf alloc_cb(oio_handle* handle, size_t size) { +static oio_buf alloc_cb(oio_handle_t* handle, size_t size) { oio_buf buf; buf.base = (char*)malloc(size); buf.len = size; diff --git a/test/test-tcp-writealot.c b/test/test-tcp-writealot.c index 14f2a35b..c5ad8045 100644 --- a/test/test-tcp-writealot.c +++ b/test/test-tcp-writealot.c @@ -45,7 +45,7 @@ static int bytes_received = 0; static int bytes_received_done = 0; -static void close_cb(oio_handle* handle, int status) { +static void close_cb(oio_handle_t* handle, int status) { ASSERT(handle != NULL); ASSERT(status == 0); @@ -55,7 +55,7 @@ static void close_cb(oio_handle* handle, int status) { } -static void shutdown_cb(oio_req* req, int status) { +static void shutdown_cb(oio_req_t* req, int status) { ASSERT(req); ASSERT(status == 0); @@ -69,7 +69,7 @@ static void shutdown_cb(oio_req* req, int status) { } -static void read_cb(oio_handle* handle, int nread, oio_buf buf) { +static void read_cb(oio_handle_t* handle, int nread, oio_buf buf) { ASSERT(handle != NULL); if (nread < 0) { @@ -90,7 +90,7 @@ static void read_cb(oio_handle* handle, int nread, oio_buf buf) { } -static void write_cb(oio_req* req, int status) { +static void write_cb(oio_req_t* req, int status) { ASSERT(req != NULL); if (status) { @@ -106,9 +106,9 @@ static void write_cb(oio_req* req, int status) { } -static void connect_cb(oio_req* req, int status) { +static void connect_cb(oio_req_t* req, int status) { oio_buf send_bufs[CHUNKS_PER_WRITE]; - oio_handle* handle; + oio_handle_t* handle; int i, j, r; ASSERT(req != NULL); @@ -127,7 +127,7 @@ static void connect_cb(oio_req* req, int status) { bytes_sent += CHUNK_SIZE; } - req = (oio_req*)malloc(sizeof *req); + req = (oio_req_t*)malloc(sizeof *req); ASSERT(req != NULL); oio_req_init(req, handle, write_cb); @@ -136,14 +136,14 @@ static void connect_cb(oio_req* req, int status) { } /* Shutdown on drain. FIXME: dealloc req? */ - req = (oio_req*) malloc(sizeof(oio_req)); + req = (oio_req_t*) malloc(sizeof(oio_req_t)); ASSERT(req != NULL); oio_req_init(req, handle, shutdown_cb); r = oio_shutdown(req); ASSERT(r == 0); /* Start reading */ - req = (oio_req*)malloc(sizeof *req); + req = (oio_req_t*)malloc(sizeof *req); ASSERT(req != NULL); oio_req_init(req, handle, read_cb); @@ -152,7 +152,7 @@ static void connect_cb(oio_req* req, int status) { } -static oio_buf alloc_cb(oio_handle* handle, size_t size) { +static oio_buf alloc_cb(oio_handle_t* handle, size_t size) { oio_buf buf; buf.base = (char*)malloc(size); buf.len = size; @@ -162,8 +162,8 @@ static oio_buf alloc_cb(oio_handle* handle, size_t size) { TEST_IMPL(tcp_writealot) { struct sockaddr_in addr = oio_ip4_addr("127.0.0.1", TEST_PORT); - oio_handle* client = (oio_handle*)malloc(sizeof *client); - oio_req* connect_req = (oio_req*)malloc(sizeof *connect_req); + oio_handle_t* client = (oio_handle_t*)malloc(sizeof *client); + oio_req_t* connect_req = (oio_req_t*)malloc(sizeof *connect_req); int r; ASSERT(client != NULL); diff --git a/test/test-timeout.c b/test/test-timeout.c index 03eac71b..dbfaff4d 100644 --- a/test/test-timeout.c +++ b/test/test-timeout.c @@ -28,7 +28,7 @@ static int timeouts = 0; static int64_t start_time; -static void timeout_cb(oio_req *req, int64_t skew, int status) { +static void timeout_cb(oio_req_t *req, int64_t skew, int status) { ASSERT(req != NULL); ASSERT(status == 0); @@ -39,7 +39,7 @@ static void timeout_cb(oio_req *req, int64_t skew, int status) { oio_update_time(); } -static void exit_timeout_cb(oio_req *req, int64_t skew, int status) { +static void exit_timeout_cb(oio_req_t *req, int64_t skew, int status) { int64_t now = oio_now(); ASSERT(req != NULL); ASSERT(status == 0); @@ -48,13 +48,13 @@ static void exit_timeout_cb(oio_req *req, int64_t skew, int status) { exit(0); } -static void dummy_timeout_cb(oio_req *req, int64_t skew, int status) { +static void dummy_timeout_cb(oio_req_t *req, int64_t skew, int status) { /* Should never be called */ FATAL("dummy_timer_cb should never be called"); } -static oio_buf alloc_cb(oio_handle* handle, size_t size) { +static oio_buf alloc_cb(oio_handle_t* handle, size_t size) { oio_buf buf = {0, 0}; FATAL("alloc should not be called"); return buf; @@ -62,9 +62,9 @@ static oio_buf alloc_cb(oio_handle* handle, size_t size) { TEST_IMPL(timeout) { - oio_req *req; - oio_req exit_req; - oio_req dummy_req; + oio_req_t *req; + oio_req_t exit_req; + oio_req_t dummy_req; int i; oio_init(alloc_cb); @@ -74,7 +74,7 @@ TEST_IMPL(timeout) { /* Let 10 timers time out in 500 ms total. */ for (i = 0; i < 10; i++) { - req = (oio_req*)malloc(sizeof(*req)); + req = (oio_req_t*)malloc(sizeof(*req)); ASSERT(req != NULL); oio_req_init(req, NULL, timeout_cb);