parent
685b36ba66
commit
b309f2e2e6
10
include/uv.h
10
include/uv.h
@ -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
|
||||
*
|
||||
|
||||
@ -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));
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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);
|
||||
|
||||
|
||||
@ -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++;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user