diff options
author | Ben Noordhuis <info@bnoordhuis.nl> | 2013-06-06 23:10:50 +0200 |
---|---|---|
committer | Ben Noordhuis <info@bnoordhuis.nl> | 2013-07-07 09:51:00 +0200 |
commit | 3ee4d3f183331a123ce35edd0d32268a2bb22aa5 (patch) | |
tree | e743fb6cee7f3a0d99d94cc0ad6e6e09dd270dd6 /test/test-tcp-bind-error.c | |
parent | 13f73fadff2388b5471f1dacbe72414b45baa48b (diff) | |
download | libuv-3ee4d3f183331a123ce35edd0d32268a2bb22aa5.tar.gz libuv-3ee4d3f183331a123ce35edd0d32268a2bb22aa5.zip |
unix, windows: return error codes directly
This commit changes the libuv API to return error codes directly rather
than storing them in a loop-global field.
A code snippet like this one:
if (uv_foo(loop) < 0) {
uv_err_t err = uv_last_error(loop);
fprintf(stderr, "%s\n", uv_strerror(err));
}
Should be rewritten like this:
int err = uv_foo(loop);
if (err < 0)
fprintf(stderr, "%s\n", uv_strerror(err));
The rationale for this change is that it should make creating bindings
for other languages a lot easier: dealing with struct return values is
painful with most FFIs and often downright buggy.
Diffstat (limited to 'test/test-tcp-bind-error.c')
-rw-r--r-- | test/test-tcp-bind-error.c | 21 |
1 files changed, 6 insertions, 15 deletions
diff --git a/test/test-tcp-bind-error.c b/test/test-tcp-bind-error.c index 42495356..2b2106ed 100644 --- a/test/test-tcp-bind-error.c +++ b/test/test-tcp-bind-error.c @@ -52,9 +52,7 @@ TEST_IMPL(tcp_bind_error_addrinuse) { r = uv_listen((uv_stream_t*)&server1, 128, NULL); ASSERT(r == 0); r = uv_listen((uv_stream_t*)&server2, 128, NULL); - ASSERT(r == -1); - - ASSERT(uv_last_error(uv_default_loop()).code == UV_EADDRINUSE); + ASSERT(r == UV_EADDRINUSE); uv_close((uv_handle_t*)&server1, close_cb); uv_close((uv_handle_t*)&server2, close_cb); @@ -75,12 +73,10 @@ TEST_IMPL(tcp_bind_error_addrnotavail_1) { r = uv_tcp_init(uv_default_loop(), &server); ASSERT(r == 0); - r = uv_tcp_bind(&server, addr); /* It seems that Linux is broken here - bind succeeds. */ - if (r == -1) { - ASSERT(uv_last_error(uv_default_loop()).code == UV_EADDRNOTAVAIL); - } + r = uv_tcp_bind(&server, addr); + ASSERT(r == 0 || r == UV_EADDRNOTAVAIL); uv_close((uv_handle_t*)&server, close_cb); @@ -101,8 +97,7 @@ TEST_IMPL(tcp_bind_error_addrnotavail_2) { r = uv_tcp_init(uv_default_loop(), &server); ASSERT(r == 0); r = uv_tcp_bind(&server, addr); - ASSERT(r == -1); - ASSERT(uv_last_error(uv_default_loop()).code == UV_EADDRNOTAVAIL); + ASSERT(r == UV_EADDRNOTAVAIL); uv_close((uv_handle_t*)&server, close_cb); @@ -126,9 +121,7 @@ TEST_IMPL(tcp_bind_error_fault) { r = uv_tcp_init(uv_default_loop(), &server); ASSERT(r == 0); r = uv_tcp_bind(&server, *garbage_addr); - ASSERT(r == -1); - - ASSERT(uv_last_error(uv_default_loop()).code == UV_EINVAL); + ASSERT(r == UV_EINVAL); uv_close((uv_handle_t*)&server, close_cb); @@ -153,9 +146,7 @@ TEST_IMPL(tcp_bind_error_inval) { r = uv_tcp_bind(&server, addr1); ASSERT(r == 0); r = uv_tcp_bind(&server, addr2); - ASSERT(r == -1); - - ASSERT(uv_last_error(uv_default_loop()).code == UV_EINVAL); + ASSERT(r == UV_EINVAL); uv_close((uv_handle_t*)&server, close_cb); |