Add uv_is_closing()

Closes #367.
This commit is contained in:
Vladimir Dronnikov 2012-04-01 21:05:06 +02:00 committed by Bert Belder
parent 685b36ba66
commit b309f2e2e6
7 changed files with 26 additions and 0 deletions

View File

@ -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
*

View File

@ -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));

View File

@ -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;

View File

@ -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);

View File

@ -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);
@ -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);

View File

@ -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);

View File

@ -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++;
}