From 111536c9e567a08530516b904c6d7f34d307538a Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Tue, 19 Apr 2011 02:29:36 -0700 Subject: [PATCH] Remove oio_err - use ints --- oio-unix.c | 10 +++++----- oio-unix.h | 2 +- oio-win.c | 4 ++-- oio-win.h | 2 +- oio.h | 10 ++++------ test/benchmark-ping-pongs.c | 4 ++-- test/echo-server.c | 6 +++--- test/test-callback-stack.c | 2 +- test/test-connection-fail.c | 4 ++-- test/test-ping-pong.c | 4 ++-- 10 files changed, 23 insertions(+), 25 deletions(-) diff --git a/oio-unix.c b/oio-unix.c index 20939a1b..196952f5 100644 --- a/oio-unix.c +++ b/oio-unix.c @@ -75,13 +75,13 @@ int oio_flag_is_set(oio_handle* handle, int flag) { } -static oio_err oio_err_new(oio_handle* handle, int e) { +static int oio_err_new(oio_handle* handle, int e) { handle->err = e; return e; } -oio_err oio_err_last(oio_handle *handle) { +int oio_err_last(oio_handle *handle) { return handle->err; } @@ -389,7 +389,7 @@ void oio__read(oio_handle* handle) { assert(ev_is_active(&handle->read_watcher)); ev_io_start(EV_DEFAULT_ &handle->read_watcher); } else { - oio_err err = oio_err_new(handle, errorno); + int err = oio_err_new(handle, errorno); if (cb) { cb(req, 0); } @@ -471,7 +471,7 @@ void oio_tcp_connect(oio_handle* handle) { return; } else { - oio_err err = oio_err_new(handle, error); + int err = oio_err_new(handle, error); oio_connect_cb connect_cb = req->cb; if (connect_cb) { @@ -618,7 +618,7 @@ int oio_read(oio_req *req, oio_buf* bufs, int bufcnt) { if (nread < 0 && errorno != EAGAIN) { /* Real error. */ - oio_err err = oio_err_new(handle, errorno); + int err = oio_err_new(handle, errorno); if (cb) { cb(req, nread); diff --git a/oio-unix.h b/oio-unix.h index e556113c..7f42c246 100644 --- a/oio-unix.h +++ b/oio-unix.h @@ -49,7 +49,7 @@ typedef struct { #define oio_handle_private_fields \ int fd; \ int flags; \ - oio_err err; \ + int err; \ oio_read_cb read_cb; \ oio_accept_cb accept_cb; \ int accepted_fd; \ diff --git a/oio-win.c b/oio-win.c index b82a9060..297c0d61 100644 --- a/oio-win.c +++ b/oio-win.c @@ -394,7 +394,7 @@ int oio_accept(oio_handle* server, oio_handle* client, } -static int oio_close_error(oio_handle* handle, oio_err e) { +static int oio_close_error(oio_handle* handle, int e) { oio_req *req; if (handle->flags & OIO_HANDLE_CLOSING) @@ -670,7 +670,7 @@ int oio_write2(oio_req *req, const char* msg) { } -oio_err oio_last_error() { +int oio_last_error() { return oio_errno_; } diff --git a/oio-win.h b/oio-win.h index fe9d4e67..2f375720 100644 --- a/oio-win.h +++ b/oio-win.h @@ -62,4 +62,4 @@ typedef struct oio_buf { struct oio_accept_req_s* accept_reqs; \ unsigned int flags; \ unsigned int reqs_pending; \ - oio_err error; + int error; diff --git a/oio.h b/oio.h index 3414d09f..21247c3a 100644 --- a/oio.h +++ b/oio.h @@ -29,8 +29,6 @@ #include /* size_t */ -typedef int oio_err; /* FIXME */ - typedef struct oio_req_s oio_req; typedef struct oio_handle_s oio_handle; @@ -38,8 +36,8 @@ typedef struct oio_handle_s oio_handle; typedef void (*oio_read_cb)(oio_req* req, size_t nread); typedef void (*oio_write_cb)(oio_req* req); typedef void (*oio_accept_cb)(oio_handle* handle); -typedef void (*oio_close_cb)(oio_handle* handle, oio_err e); -typedef void (*oio_connect_cb)(oio_req* req, oio_err e); +typedef void (*oio_close_cb)(oio_handle* handle, int e); +typedef void (*oio_connect_cb)(oio_req* req, int e); typedef void (*oio_shutdown_cb)(oio_req* req); typedef void (*oio_timer_cb)(oio_req* req, int64_t skew); @@ -99,8 +97,8 @@ struct oio_req_s { * On error the user should then call oio_last_error() to determine * the error code. */ -oio_err oio_last_error(); -const char* oio_err_str(oio_err err); +int oio_last_error(); +const char* oio_err_str(int err); void oio_init(); diff --git a/test/benchmark-ping-pongs.c b/test/benchmark-ping-pongs.c index 14c442fe..93f287de 100644 --- a/test/benchmark-ping-pongs.c +++ b/test/benchmark-ping-pongs.c @@ -50,7 +50,7 @@ typedef struct { void pinger_try_read(pinger_t* pinger); -void pinger_on_close(oio_handle* handle, oio_err err) { +void pinger_on_close(oio_handle* handle, int err) { pinger_t* pinger = (pinger_t*)handle->data; printf("%d pings\n", pinger->pongs); @@ -117,7 +117,7 @@ void pinger_try_read(pinger_t* pinger) { } -void pinger_on_connect(oio_req *req, oio_err err) { +void pinger_on_connect(oio_req *req, int err) { pinger_t *pinger = (pinger_t*)req->handle->data; ASSERT(!err); diff --git a/test/echo-server.c b/test/echo-server.c index 7a253b73..d69a3b0a 100644 --- a/test/echo-server.c +++ b/test/echo-server.c @@ -39,7 +39,7 @@ oio_handle server; void after_write(oio_req* req); void after_read(oio_req* req, size_t nread); void try_read(peer_t* peer); -void on_close(oio_handle* peer, oio_err err); +void on_close(oio_handle* peer, int err); void on_accept(oio_handle* handle); @@ -75,7 +75,7 @@ void try_read(peer_t* peer) { } -void on_close(oio_handle* peer, oio_err err) { +void on_close(oio_handle* peer, int err) { if (err) { fprintf(stdout, "Socket error\n"); } @@ -95,7 +95,7 @@ void on_accept(oio_handle* server) { } -void on_server_close(oio_handle* handle, oio_err err) { +void on_server_close(oio_handle* handle, int err) { ASSERT(handle == &server); ASSERT(!err); } diff --git a/test/test-callback-stack.c b/test/test-callback-stack.c index e4377ec5..9bca8aa2 100644 --- a/test/test-callback-stack.c +++ b/test/test-callback-stack.c @@ -32,7 +32,7 @@ int nested = 0; int close_cb_called = 0; -void close_cb(oio_handle *handle, oio_err err) { +void close_cb(oio_handle *handle, int err) { ASSERT(!err); ASSERT(nested == 0 && "oio_close_cb must be called from a fresh stack"); close_cb_called++; diff --git a/test/test-connection-fail.c b/test/test-connection-fail.c index 4e3a455f..a29ca97c 100644 --- a/test/test-connection-fail.c +++ b/test/test-connection-fail.c @@ -32,13 +32,13 @@ static int connect_cb_calls; static int close_cb_calls; -static void on_close(oio_handle* handle, oio_err err) { +static void on_close(oio_handle* handle, int err) { ASSERT(!err); close_cb_calls++; } -static void on_connect(oio_req *req, oio_err err) { +static void on_connect(oio_req *req, int err) { ASSERT(err); connect_cb_calls++; } diff --git a/test/test-ping-pong.c b/test/test-ping-pong.c index 0c3e1dfa..a1c93c62 100644 --- a/test/test-ping-pong.c +++ b/test/test-ping-pong.c @@ -48,7 +48,7 @@ typedef struct { void pinger_try_read(pinger_t* pinger); -void pinger_on_close(oio_handle* handle, oio_err err) { +void pinger_on_close(oio_handle* handle, int err) { pinger_t* pinger = (pinger_t*)handle->data; ASSERT(!err); @@ -117,7 +117,7 @@ void pinger_try_read(pinger_t* pinger) { } -void pinger_on_connect(oio_req *req, oio_err err) { +void pinger_on_connect(oio_req *req, int err) { pinger_t *pinger = (pinger_t*)req->handle->data; ASSERT(!err);