From 875814adc57cb9b607c8fd489837826d223707c2 Mon Sep 17 00:00:00 2001 From: Andrius Bentkus Date: Mon, 14 Jul 2014 13:33:53 +0200 Subject: [PATCH] unix: replace some asserts with returning errors --- src/fs-poll.c | 15 +++++++++++---- src/unix/stream.c | 5 ++--- src/unix/udp.c | 2 -- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/fs-poll.c b/src/fs-poll.c index 871228fc..0de15b17 100644 --- a/src/fs-poll.c +++ b/src/fs-poll.c @@ -60,6 +60,7 @@ int uv_fs_poll_start(uv_fs_poll_t* handle, struct poll_ctx* ctx; uv_loop_t* loop; size_t len; + int err; if (uv__is_active(handle)) return 0; @@ -78,19 +79,25 @@ int uv_fs_poll_start(uv_fs_poll_t* handle, ctx->parent_handle = handle; memcpy(ctx->path, path, len + 1); - if (uv_timer_init(loop, &ctx->timer_handle)) - abort(); + err = uv_timer_init(loop, &ctx->timer_handle); + if (err < 0) + goto error; ctx->timer_handle.flags |= UV__HANDLE_INTERNAL; uv__handle_unref(&ctx->timer_handle); - if (uv_fs_stat(loop, &ctx->fs_req, ctx->path, poll_cb)) - abort(); + err = uv_fs_stat(loop, &ctx->fs_req, ctx->path, poll_cb); + if (err < 0) + goto error; handle->poll_ctx = ctx; uv__handle_start(handle); return 0; + +error: + free(ctx); + return err; } diff --git a/src/unix/stream.c b/src/unix/stream.c index ae7880c3..50bd85aa 100644 --- a/src/unix/stream.c +++ b/src/unix/stream.c @@ -537,7 +537,7 @@ int uv_accept(uv_stream_t* server, uv_stream_t* client) { break; default: - assert(0); + return -EINVAL; } done: @@ -573,7 +573,6 @@ done: int uv_listen(uv_stream_t* stream, int backlog, uv_connection_cb cb) { int err; - err = -EINVAL; switch (stream->type) { case UV_TCP: err = uv_tcp_listen((uv_tcp_t*)stream, backlog, cb); @@ -584,7 +583,7 @@ int uv_listen(uv_stream_t* stream, int backlog, uv_connection_cb cb) { break; default: - assert(0); + err = -EINVAL; } if (err == 0) diff --git a/src/unix/udp.c b/src/unix/udp.c index bf91cbdf..7cafea1d 100644 --- a/src/unix/udp.c +++ b/src/unix/udp.c @@ -340,8 +340,6 @@ static int uv__udp_maybe_deferred_bind(uv_udp_t* handle, unsigned char taddr[sizeof(struct sockaddr_in6)]; socklen_t addrlen; - assert(domain == AF_INET || domain == AF_INET6); - if (handle->io_watcher.fd != -1) return 0;