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

Commit

Permalink
Add uv_is_closing()
Browse files Browse the repository at this point in the history
Closes #367.
  • Loading branch information
dvv authored and piscisaureus committed Apr 1, 2012
1 parent 685b36b commit b309f2e
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 0 deletions.
10 changes: 10 additions & 0 deletions include/uv.h
Expand Up @@ -522,6 +522,16 @@ UV_EXTERN int uv_is_readable(uv_stream_t* handle);
UV_EXTERN int uv_is_writable(uv_stream_t* handle);


/*
* Used to determine whether a stream is closing or closed.
*
* N.B. is only valid between the initialization of the handle
* and the arrival of the close callback, and cannot be used
* to validate the handle.
*/
UV_EXTERN int uv_is_closing(uv_handle_t* handle);


/*
* uv_tcp_t is a subclass of uv_stream_t
*
Expand Down
5 changes: 5 additions & 0 deletions src/unix/core.c
Expand Up @@ -142,6 +142,11 @@ void uv_close(uv_handle_t* handle, uv_close_cb close_cb) {
}


int uv_is_closing(uv_handle_t* handle) {
return handle->flags & (UV_CLOSING | UV_CLOSED);
}


static int uv__loop_init(uv_loop_t* loop,
struct ev_loop *(ev_loop_new)(unsigned int flags)) {
memset(loop, 0, sizeof(*loop));
Expand Down
5 changes: 5 additions & 0 deletions src/win/handle.c
Expand Up @@ -154,6 +154,11 @@ void uv_close(uv_handle_t* handle, uv_close_cb cb) {
}


int uv_is_closing(uv_handle_t* handle) {
return handle->flags & (UV_HANDLE_CLOSING | UV_HANDLE_CLOSED);
}


void uv_want_endgame(uv_loop_t* loop, uv_handle_t* handle) {
if (!(handle->flags & UV_HANDLE_ENDGAME_QUEUED)) {
handle->flags |= UV_HANDLE_ENDGAME_QUEUED;
Expand Down
1 change: 1 addition & 0 deletions test/test-ipc-send-recv.c
Expand Up @@ -197,6 +197,7 @@ int ipc_send_recv_helper(void) {
uv_pipe_open(&ctx.channel, 0);
ASSERT(uv_is_readable((uv_stream_t*)&ctx.channel));
ASSERT(uv_is_writable((uv_stream_t*)&ctx.channel));
ASSERT(!uv_is_closing((uv_handle_t*)&ctx.channel));

r = uv_read2_start((uv_stream_t*)&ctx.channel, alloc_cb, read2_cb);
ASSERT(r == 0);
Expand Down
2 changes: 2 additions & 0 deletions test/test-ipc.c
Expand Up @@ -535,6 +535,7 @@ int ipc_helper(int listen_after_write) {

ASSERT(uv_is_readable((uv_stream_t*) &channel));
ASSERT(uv_is_writable((uv_stream_t*) &channel));
ASSERT(!uv_is_closing((uv_handle_t*) &channel));

r = uv_tcp_init(uv_default_loop(), &tcp_server);
ASSERT(r == 0);
Expand Down Expand Up @@ -583,6 +584,7 @@ int ipc_helper_tcp_connection() {

ASSERT(uv_is_readable((uv_stream_t*)&channel));
ASSERT(uv_is_writable((uv_stream_t*)&channel));
ASSERT(!uv_is_closing((uv_handle_t*)&channel));

r = uv_tcp_init(uv_default_loop(), &tcp_server);
ASSERT(r == 0);
Expand Down
1 change: 1 addition & 0 deletions test/test-ping-pong.c
Expand Up @@ -140,6 +140,7 @@ static void pinger_on_connect(uv_connect_t *req, int status) {

ASSERT(uv_is_readable(req->handle));
ASSERT(uv_is_writable(req->handle));
ASSERT(!uv_is_closing((uv_handle_t *)req->handle));

pinger_write_ping(pinger);

Expand Down
2 changes: 2 additions & 0 deletions test/test-shutdown-close.c
Expand Up @@ -57,7 +57,9 @@ static void connect_cb(uv_connect_t* req, int status) {

r = uv_shutdown(&shutdown_req, req->handle, shutdown_cb);
ASSERT(r == 0);
ASSERT(!uv_is_closing((uv_handle_t*) req->handle));
uv_close((uv_handle_t*) req->handle, close_cb);
ASSERT(uv_is_closing((uv_handle_t*) req->handle));

connect_cb_called++;
}
Expand Down

0 comments on commit b309f2e

Please sign in to comment.