diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2011-05-19 10:37:51 -0700 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2011-05-19 10:37:51 -0700 |
commit | 4b60e87afec10e7e051e37cd5d00d0fbe3568a7d (patch) | |
tree | 146d940fb18ad305fa1887f223805a7da41bc7da /deps/uv/test/test-callback-stack.c | |
parent | 3ac0ada758004ffe141d79c282e16ed8c8f4cc83 (diff) | |
download | android-node-v8-4b60e87afec10e7e051e37cd5d00d0fbe3568a7d.tar.gz android-node-v8-4b60e87afec10e7e051e37cd5d00d0fbe3568a7d.tar.bz2 android-node-v8-4b60e87afec10e7e051e37cd5d00d0fbe3568a7d.zip |
Upgrade libuv to 9c2dd6bea970b2376696aba070bdfc2873843cfb
Diffstat (limited to 'deps/uv/test/test-callback-stack.c')
-rw-r--r-- | deps/uv/test/test-callback-stack.c | 40 |
1 files changed, 24 insertions, 16 deletions
diff --git a/deps/uv/test/test-callback-stack.c b/deps/uv/test/test-callback-stack.c index 986f863dc3..d136c9a764 100644 --- a/deps/uv/test/test-callback-stack.c +++ b/deps/uv/test/test-callback-stack.c @@ -30,14 +30,14 @@ static const char MESSAGE[] = "Failure is for the weak. Everyone dies alone."; -static uv_handle_t client; -static uv_req_t connect_req, write_req, timeout_req, shutdown_req; +static uv_handle_t client, timer; +static uv_req_t connect_req, write_req, shutdown_req; static int nested = 0; static int close_cb_called = 0; static int connect_cb_called = 0; static int write_cb_called = 0; -static int timeout_cb_called = 0; +static int timer_cb_called = 0; static int bytes_received = 0; static int shutdown_cb_called = 0; @@ -58,7 +58,7 @@ static void shutdown_cb(uv_req_t* req, int status) { } -static void read_cb(uv_handle_t* handle, int nread, uv_buf buf) { +static void read_cb(uv_handle_t* handle, int nread, uv_buf_t buf) { ASSERT(nested == 0 && "read_cb must be called from a fresh stack"); printf("Read. nread == %d\n", nread); @@ -100,9 +100,12 @@ static void read_cb(uv_handle_t* handle, int nread, uv_buf buf) { } -static void timeout_cb(uv_req_t* req, int64_t skew, int status) { +static void timer_cb(uv_handle_t* handle, int status) { + int r; + + ASSERT(handle == &timer); ASSERT(status == 0); - ASSERT(nested == 0 && "timeout_cb must be called from a fresh stack"); + ASSERT(nested == 0 && "timer_cb must be called from a fresh stack"); puts("Timeout complete. Now read data..."); @@ -112,11 +115,16 @@ static void timeout_cb(uv_req_t* req, int64_t skew, int status) { } nested--; - timeout_cb_called++; + timer_cb_called++; + + r = uv_close(handle); + ASSERT(r == 0); } static void write_cb(uv_req_t* req, int status) { + int r; + ASSERT(status == 0); ASSERT(nested == 0 && "write_cb must be called from a fresh stack"); @@ -127,10 +135,10 @@ static void write_cb(uv_req_t* req, int status) { /* back to our receive buffer when we start reading. This maximizes the */ /* tempation for the backend to use dirty stack for calling read_cb. */ nested++; - uv_req_init(&timeout_req, NULL, timeout_cb); - if (uv_timeout(&timeout_req, 500)) { - FATAL("uv_timeout failed"); - } + r = uv_timer_init(&timer, close_cb, NULL); + ASSERT(r == 0); + r = uv_timer_start(&timer, timer_cb, 500, 0); + ASSERT(r == 0); nested--; write_cb_called++; @@ -138,7 +146,7 @@ static void write_cb(uv_req_t* req, int status) { static void connect_cb(uv_req_t* req, int status) { - uv_buf buf; + uv_buf_t buf; puts("Connected. Write some data to echo server..."); @@ -162,8 +170,8 @@ static void connect_cb(uv_req_t* req, int status) { } -static uv_buf alloc_cb(uv_handle_t* handle, size_t size) { - uv_buf buf; +static uv_buf_t alloc_cb(uv_handle_t* handle, size_t size) { + uv_buf_t buf; buf.len = size; buf.base = (char*) malloc(size); ASSERT(buf.base); @@ -194,10 +202,10 @@ TEST_IMPL(callback_stack) { ASSERT(nested == 0); ASSERT(connect_cb_called == 1 && "connect_cb must be called exactly once"); ASSERT(write_cb_called == 1 && "write_cb must be called exactly once"); - ASSERT(timeout_cb_called == 1 && "timeout_cb must be called exactly once"); + ASSERT(timer_cb_called == 1 && "timer_cb must be called exactly once"); ASSERT(bytes_received == sizeof MESSAGE); ASSERT(shutdown_cb_called == 1 && "shutdown_cb must be called exactly once"); - ASSERT(close_cb_called == 1 && "close_cb must be called exactly once"); + ASSERT(close_cb_called == 2 && "close_cb must be called exactly twice"); return 0; } |