This source file includes following definitions.
- shutdown_cb
- close_cb
- connect_cb
- TEST_IMPL
- TEST_IMPL
#include "uv.h"
#include "task.h"
static uv_shutdown_t shutdown_req;
static uv_connect_t connect_req;
static int connect_cb_called = 0;
static int shutdown_cb_called = 0;
static int close_cb_called = 0;
static void shutdown_cb(uv_shutdown_t* req, int status) {
ASSERT(req == &shutdown_req);
ASSERT(status == 0 || status == UV_ECANCELED);
shutdown_cb_called++;
}
static void close_cb(uv_handle_t* handle) {
close_cb_called++;
}
static void connect_cb(uv_connect_t* req, int status) {
int r;
ASSERT(req == &connect_req);
ASSERT(status == 0);
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++;
}
TEST_IMPL(shutdown_close_tcp) {
struct sockaddr_in addr = uv_ip4_addr("127.0.0.1", TEST_PORT);
uv_tcp_t h;
int r;
r = uv_tcp_init(uv_default_loop(), &h);
ASSERT(r == 0);
r = uv_tcp_connect(&connect_req, &h, addr, connect_cb);
ASSERT(r == 0);
r = uv_run(uv_default_loop(), UV_RUN_DEFAULT);
ASSERT(r == 0);
ASSERT(connect_cb_called == 1);
ASSERT(shutdown_cb_called == 1);
ASSERT(close_cb_called == 1);
MAKE_VALGRIND_HAPPY();
return 0;
}
TEST_IMPL(shutdown_close_pipe) {
uv_pipe_t h;
int r;
r = uv_pipe_init(uv_default_loop(), &h, 0);
ASSERT(r == 0);
uv_pipe_connect(&connect_req, &h, TEST_PIPENAME, connect_cb);
r = uv_run(uv_default_loop(), UV_RUN_DEFAULT);
ASSERT(r == 0);
ASSERT(connect_cb_called == 1);
ASSERT(shutdown_cb_called == 1);
ASSERT(close_cb_called == 1);
MAKE_VALGRIND_HAPPY();
return 0;
}