From 6bf1a56e9d60737ef26509d9e304c03e008972d4 Mon Sep 17 00:00:00 2001 From: Andrius Bentkus Date: Fri, 15 Feb 2013 10:12:44 +0100 Subject: [PATCH] Return the errorcode provided by uv_set_artificial_error. This reduces the line count. --- src/uv-common.c | 70 +++++++++++++++++++++---------------------------- 1 file changed, 30 insertions(+), 40 deletions(-) diff --git a/src/uv-common.c b/src/uv-common.c index 0b0533494..ae2ca7147 100644 --- a/src/uv-common.c +++ b/src/uv-common.c @@ -197,44 +197,38 @@ int uv_ip6_name(struct sockaddr_in6* src, char* dst, size_t size) { int uv_tcp_bind(uv_tcp_t* handle, struct sockaddr_in addr) { - if (handle->type != UV_TCP || addr.sin_family != AF_INET) { - uv__set_artificial_error(handle->loop, UV_EINVAL); - return -1; - } - - return uv__tcp_bind(handle, addr); + if (handle->type != UV_TCP || addr.sin_family != AF_INET) + return uv__set_artificial_error(handle->loop, UV_EINVAL); + else + return uv__tcp_bind(handle, addr); } int uv_tcp_bind6(uv_tcp_t* handle, struct sockaddr_in6 addr) { - if (handle->type != UV_TCP || addr.sin6_family != AF_INET6) { - uv__set_artificial_error(handle->loop, UV_EINVAL); - return -1; - } - - return uv__tcp_bind6(handle, addr); + if (handle->type != UV_TCP || addr.sin6_family != AF_INET6) + return uv__set_artificial_error(handle->loop, UV_EINVAL); + else + return uv__tcp_bind6(handle, addr); } -int uv_udp_bind(uv_udp_t* handle, struct sockaddr_in addr, - unsigned int flags) { - if (handle->type != UV_UDP || addr.sin_family != AF_INET) { - uv__set_artificial_error(handle->loop, UV_EINVAL); - return -1; - } - - return uv__udp_bind(handle, addr, flags); +int uv_udp_bind(uv_udp_t* handle, + struct sockaddr_in addr, + unsigned int flags) { + if (handle->type != UV_UDP || addr.sin_family != AF_INET) + return uv__set_artificial_error(handle->loop, UV_EINVAL); + else + return uv__udp_bind(handle, addr, flags); } -int uv_udp_bind6(uv_udp_t* handle, struct sockaddr_in6 addr, - unsigned int flags) { - if (handle->type != UV_UDP || addr.sin6_family != AF_INET6) { - uv__set_artificial_error(handle->loop, UV_EINVAL); - return -1; - } - - return uv__udp_bind6(handle, addr, flags); +int uv_udp_bind6(uv_udp_t* handle, + struct sockaddr_in6 addr, + unsigned int flags) { + if (handle->type != UV_UDP || addr.sin6_family != AF_INET6) + return uv__set_artificial_error(handle->loop, UV_EINVAL); + else + return uv__udp_bind6(handle, addr, flags); } @@ -242,12 +236,10 @@ int uv_tcp_connect(uv_connect_t* req, uv_tcp_t* handle, struct sockaddr_in address, uv_connect_cb cb) { - if (handle->type != UV_TCP || address.sin_family != AF_INET) { - uv__set_artificial_error(handle->loop, UV_EINVAL); - return -1; - } - - return uv__tcp_connect(req, handle, address, cb); + if (handle->type != UV_TCP || address.sin_family != AF_INET) + return uv__set_artificial_error(handle->loop, UV_EINVAL); + else + return uv__tcp_connect(req, handle, address, cb); } @@ -255,12 +247,10 @@ int uv_tcp_connect6(uv_connect_t* req, uv_tcp_t* handle, struct sockaddr_in6 address, uv_connect_cb cb) { - if (handle->type != UV_TCP || address.sin6_family != AF_INET6) { - uv__set_artificial_error(handle->loop, UV_EINVAL); - return -1; - } - - return uv__tcp_connect6(req, handle, address, cb); + if (handle->type != UV_TCP || address.sin6_family != AF_INET6) + return uv__set_artificial_error(handle->loop, UV_EINVAL); + else + return uv__tcp_connect6(req, handle, address, cb); }