unix, windows: make uv_*_bind() error codes consistent

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.
This commit is contained in:
Andrius Bentkus 2013-01-18 01:38:06 +01:00 committed by Ben Noordhuis
parent 372ac34d5f
commit 017e2d5fde
3 changed files with 6 additions and 6 deletions

View File

@ -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) {
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;
}
@ -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) {
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;
}
@ -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,
unsigned int flags) {
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;
}
@ -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,
unsigned int flags) {
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;
}

View File

@ -128,7 +128,7 @@ TEST_IMPL(tcp_bind_error_fault) {
r = uv_tcp_bind(&server, *garbage_addr);
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);

View File

@ -103,7 +103,7 @@ TEST_IMPL(tcp_bind6_error_fault) {
r = uv_tcp_bind6(&server, *garbage_addr);
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);