Skip to content
This repository has been archived by the owner on May 4, 2018. It is now read-only.

Commit

Permalink
unix, windows: make uv_*_bind() error codes consistent
Browse files Browse the repository at this point in the history
Just like uv_tcp_connect() it should return an EINVAL when the handle
is of an invalid type or when the network address is faulty.
  • Loading branch information
txdv authored and bnoordhuis committed Jan 18, 2013
1 parent 372ac34 commit 017e2d5
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/uv-common.c
Expand Up @@ -198,7 +198,7 @@ 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) { int uv_tcp_bind(uv_tcp_t* handle, struct sockaddr_in addr) {
if (handle->type != UV_TCP || addr.sin_family != AF_INET) { if (handle->type != UV_TCP || addr.sin_family != AF_INET) {
uv__set_artificial_error(handle->loop, UV_EFAULT); uv__set_artificial_error(handle->loop, UV_EINVAL);
return -1; return -1;
} }


Expand All @@ -208,7 +208,7 @@ int uv_tcp_bind(uv_tcp_t* handle, struct sockaddr_in addr) {


int uv_tcp_bind6(uv_tcp_t* handle, struct sockaddr_in6 addr) { int uv_tcp_bind6(uv_tcp_t* handle, struct sockaddr_in6 addr) {
if (handle->type != UV_TCP || addr.sin6_family != AF_INET6) { if (handle->type != UV_TCP || addr.sin6_family != AF_INET6) {
uv__set_artificial_error(handle->loop, UV_EFAULT); uv__set_artificial_error(handle->loop, UV_EINVAL);
return -1; return -1;
} }


Expand All @@ -219,7 +219,7 @@ int uv_tcp_bind6(uv_tcp_t* handle, struct sockaddr_in6 addr) {
int uv_udp_bind(uv_udp_t* handle, struct sockaddr_in addr, int uv_udp_bind(uv_udp_t* handle, struct sockaddr_in addr,
unsigned int flags) { unsigned int flags) {
if (handle->type != UV_UDP || addr.sin_family != AF_INET) { if (handle->type != UV_UDP || addr.sin_family != AF_INET) {
uv__set_artificial_error(handle->loop, UV_EFAULT); uv__set_artificial_error(handle->loop, UV_EINVAL);
return -1; return -1;
} }


Expand All @@ -230,7 +230,7 @@ int uv_udp_bind(uv_udp_t* handle, struct sockaddr_in addr,
int uv_udp_bind6(uv_udp_t* handle, struct sockaddr_in6 addr, int uv_udp_bind6(uv_udp_t* handle, struct sockaddr_in6 addr,
unsigned int flags) { unsigned int flags) {
if (handle->type != UV_UDP || addr.sin6_family != AF_INET6) { if (handle->type != UV_UDP || addr.sin6_family != AF_INET6) {
uv__set_artificial_error(handle->loop, UV_EFAULT); uv__set_artificial_error(handle->loop, UV_EINVAL);
return -1; return -1;
} }


Expand Down
2 changes: 1 addition & 1 deletion test/test-tcp-bind-error.c
Expand Up @@ -128,7 +128,7 @@ TEST_IMPL(tcp_bind_error_fault) {
r = uv_tcp_bind(&server, *garbage_addr); r = uv_tcp_bind(&server, *garbage_addr);
ASSERT(r == -1); ASSERT(r == -1);


ASSERT(uv_last_error(uv_default_loop()).code == UV_EFAULT); ASSERT(uv_last_error(uv_default_loop()).code == UV_EINVAL);


uv_close((uv_handle_t*)&server, close_cb); uv_close((uv_handle_t*)&server, close_cb);


Expand Down
2 changes: 1 addition & 1 deletion test/test-tcp-bind6-error.c
Expand Up @@ -103,7 +103,7 @@ TEST_IMPL(tcp_bind6_error_fault) {
r = uv_tcp_bind6(&server, *garbage_addr); r = uv_tcp_bind6(&server, *garbage_addr);
ASSERT(r == -1); ASSERT(r == -1);


ASSERT(uv_last_error(uv_default_loop()).code == UV_EFAULT); ASSERT(uv_last_error(uv_default_loop()).code == UV_EINVAL);


uv_close((uv_handle_t*)&server, close_cb); uv_close((uv_handle_t*)&server, close_cb);


Expand Down

0 comments on commit 017e2d5

Please sign in to comment.