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-bind6-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-bind6-error.c')
-rw-r--r-- | test/test-tcp-bind6-error.c | 15 |
1 files changed, 4 insertions, 11 deletions
diff --git a/test/test-tcp-bind6-error.c b/test/test-tcp-bind6-error.c index 61afc7f1..46e147b8 100644 --- a/test/test-tcp-bind6-error.c +++ b/test/test-tcp-bind6-error.c @@ -52,9 +52,7 @@ TEST_IMPL(tcp_bind6_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); @@ -76,8 +74,7 @@ TEST_IMPL(tcp_bind6_error_addrnotavail) { r = uv_tcp_init(uv_default_loop(), &server); ASSERT(r == 0); r = uv_tcp_bind6(&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); @@ -101,9 +98,7 @@ TEST_IMPL(tcp_bind6_error_fault) { r = uv_tcp_init(uv_default_loop(), &server); ASSERT(r == 0); r = uv_tcp_bind6(&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); @@ -128,9 +123,7 @@ TEST_IMPL(tcp_bind6_error_inval) { r = uv_tcp_bind6(&server, addr1); ASSERT(r == 0); r = uv_tcp_bind6(&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); |