uv_close returns void

This commit is contained in:
Ryan Dahl 2011-07-20 18:03:08 -07:00
parent f0c20aa913
commit b931c9313f
8 changed files with 19 additions and 43 deletions

View File

@ -229,7 +229,7 @@ int uv_is_active(uv_handle_t* handle);
* Request handle to be closed. close_cb will be called asynchronously after * Request handle to be closed. close_cb will be called asynchronously after
* this call. This MUST be called on each handle before memory is released. * this call. This MUST be called on each handle before memory is released.
*/ */
int uv_close(uv_handle_t* handle, uv_close_cb close_cb); void uv_close(uv_handle_t* handle, uv_close_cb close_cb);
#define UV_STREAM_FIELDS \ #define UV_STREAM_FIELDS \

View File

@ -186,7 +186,7 @@ static uv_err_t uv_err_new(uv_handle_t* handle, int sys_error) {
} }
int uv_close(uv_handle_t* handle, uv_close_cb close_cb) { void uv_close(uv_handle_t* handle, uv_close_cb close_cb) {
uv_tcp_t* tcp; uv_tcp_t* tcp;
uv_pipe_t* pipe; uv_pipe_t* pipe;
uv_async_t* async; uv_async_t* async;
@ -245,7 +245,6 @@ int uv_close(uv_handle_t* handle, uv_close_cb close_cb) {
default: default:
assert(0); assert(0);
return -1;
} }
uv_flag_set(handle, UV_CLOSING); uv_flag_set(handle, UV_CLOSING);
@ -254,8 +253,6 @@ int uv_close(uv_handle_t* handle, uv_close_cb close_cb) {
ev_idle_start(EV_DEFAULT_ &handle->next_watcher); ev_idle_start(EV_DEFAULT_ &handle->next_watcher);
ev_feed_event(EV_DEFAULT_ &handle->next_watcher, EV_IDLE); ev_feed_event(EV_DEFAULT_ &handle->next_watcher, EV_IDLE);
assert(ev_is_pending(&handle->next_watcher)); assert(ev_is_pending(&handle->next_watcher));
return 0;
} }

View File

@ -111,9 +111,9 @@ static int uv_close_error(uv_handle_t* handle, uv_err_t e) {
} }
int uv_close(uv_handle_t* handle, uv_close_cb close_cb) { void uv_close(uv_handle_t* handle, uv_close_cb close_cb) {
handle->close_cb = close_cb; handle->close_cb = close_cb;
return uv_close_error(handle, uv_ok_); uv_close_error(handle, uv_ok_);
} }

View File

@ -170,8 +170,7 @@ static void prepare_cb(uv_prepare_t* handle, int status) {
#endif #endif
case 1: case 1:
r = uv_close((uv_handle_t*)handle, close_cb); uv_close((uv_handle_t*)handle, close_cb);
ASSERT(r == 0);
break; break;
default: default:

View File

@ -83,9 +83,7 @@ static void read_cb(uv_stream_t* tcp, ssize_t nread, uv_buf_t buf) {
ASSERT(uv_last_error().code == UV_EOF); ASSERT(uv_last_error().code == UV_EOF);
nested++; nested++;
if (uv_close((uv_handle_t*)tcp, close_cb)) { uv_close((uv_handle_t*)tcp, close_cb);
FATAL("uv_close failed");
}
nested--; nested--;
return; return;
@ -111,8 +109,6 @@ static void read_cb(uv_stream_t* tcp, ssize_t nread, uv_buf_t buf) {
static void timer_cb(uv_timer_t* handle, int status) { static void timer_cb(uv_timer_t* handle, int status) {
int r;
ASSERT(handle == &timer); ASSERT(handle == &timer);
ASSERT(status == 0); ASSERT(status == 0);
ASSERT(nested == 0 && "timer_cb must be called from a fresh stack"); ASSERT(nested == 0 && "timer_cb must be called from a fresh stack");
@ -127,8 +123,7 @@ static void timer_cb(uv_timer_t* handle, int status) {
timer_cb_called++; timer_cb_called++;
r = uv_close((uv_handle_t*)handle, close_cb); uv_close((uv_handle_t*)handle, close_cb);
ASSERT(r == 0);
} }

View File

@ -71,18 +71,15 @@ static void do_accept(uv_timer_t* timer_handle, int status) {
do_accept_called++; do_accept_called++;
/* Immediately close the accepted handle. */ /* Immediately close the accepted handle. */
r = uv_close((uv_handle_t*)accepted_handle, close_cb); uv_close((uv_handle_t*)accepted_handle, close_cb);
ASSERT(r == 0);
/* After accepting the two clients close the server handle */ /* After accepting the two clients close the server handle */
if (do_accept_called == 2) { if (do_accept_called == 2) {
r = uv_close((uv_handle_t*)server, close_cb); uv_close((uv_handle_t*)server, close_cb);
ASSERT(r == 0);
} }
/* Dispose the timer. */ /* Dispose the timer. */
r = uv_close((uv_handle_t*)timer_handle, close_cb); uv_close((uv_handle_t*)timer_handle, close_cb);
ASSERT(r == 0);
} }

View File

@ -37,15 +37,11 @@ static void close_cb(uv_handle_t* handle) {
static void timer_cb(uv_timer_t* handle, int status) { static void timer_cb(uv_timer_t* handle, int status) {
int r;
ASSERT(handle == &timer_handle); ASSERT(handle == &timer_handle);
ASSERT(status == 0); ASSERT(status == 0);
r = uv_close((uv_handle_t*) &idle_handle, close_cb); uv_close((uv_handle_t*) &idle_handle, close_cb);
ASSERT(r == 0); uv_close((uv_handle_t*) &idle_handle, close_cb);
r = uv_close((uv_handle_t*) &idle_handle, close_cb);
ASSERT(r == 0);
timer_cb_called++; timer_cb_called++;
} }
@ -83,4 +79,4 @@ TEST_IMPL(idle_starvation) {
ASSERT(close_cb_called == 2); ASSERT(close_cb_called == 2);
return 0; return 0;
} }

View File

@ -130,8 +130,6 @@ static void idle_2_close_cb(uv_handle_t* handle) {
static void idle_2_cb(uv_idle_t* handle, int status) { static void idle_2_cb(uv_idle_t* handle, int status) {
int r;
LOG("IDLE_2_CB\n"); LOG("IDLE_2_CB\n");
ASSERT(handle == &idle_2_handle); ASSERT(handle == &idle_2_handle);
@ -139,8 +137,7 @@ static void idle_2_cb(uv_idle_t* handle, int status) {
idle_2_cb_called++; idle_2_cb_called++;
r = uv_close((uv_handle_t*)handle, idle_2_close_cb); uv_close((uv_handle_t*)handle, idle_2_close_cb);
ASSERT(r == 0);
} }
@ -230,23 +227,18 @@ static void check_cb(uv_check_t* handle, int status) {
} else { } else {
/* End of the test - close all handles */ /* End of the test - close all handles */
r = uv_close((uv_handle_t*)&prepare_1_handle, prepare_1_close_cb); uv_close((uv_handle_t*)&prepare_1_handle, prepare_1_close_cb);
ASSERT(r == 0); uv_close((uv_handle_t*)&check_handle, check_close_cb);
r = uv_close((uv_handle_t*)&check_handle, check_close_cb); uv_close((uv_handle_t*)&prepare_2_handle, prepare_2_close_cb);
ASSERT(r == 0);
r = uv_close((uv_handle_t*)&prepare_2_handle, prepare_2_close_cb);
ASSERT(r == 0);
for (i = 0; i < IDLE_COUNT; i++) { for (i = 0; i < IDLE_COUNT; i++) {
r = uv_close((uv_handle_t*)&idle_1_handles[i], idle_1_close_cb); uv_close((uv_handle_t*)&idle_1_handles[i], idle_1_close_cb);
ASSERT(r == 0);
} }
/* This handle is closed/recreated every time, close it only if it is */ /* This handle is closed/recreated every time, close it only if it is */
/* active.*/ /* active.*/
if (idle_2_is_active) { if (idle_2_is_active) {
r = uv_close((uv_handle_t*)&idle_2_handle, idle_2_close_cb); uv_close((uv_handle_t*)&idle_2_handle, idle_2_close_cb);
ASSERT(r == 0);
} }
} }