ext/libuv/test/test-callback-stack.c in libuv-0.10.2 vs ext/libuv/test/test-callback-stack.c in libuv-0.10.3
- old
+ new
@@ -43,16 +43,14 @@
static int timer_cb_called = 0;
static int bytes_received = 0;
static int shutdown_cb_called = 0;
-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);
- return buf;
+static void alloc_cb(uv_handle_t* handle, size_t size, uv_buf_t* buf) {
+ buf->len = size;
+ buf->base = malloc(size);
+ ASSERT(buf->base != NULL);
}
static void close_cb(uv_handle_t* handle) {
ASSERT(nested == 0 && "close_cb must be called from a fresh stack");
@@ -67,15 +65,15 @@
shutdown_cb_called++;
}
-static void read_cb(uv_stream_t* tcp, ssize_t nread, uv_buf_t buf) {
+static void read_cb(uv_stream_t* tcp, ssize_t nread, const uv_buf_t* buf) {
ASSERT(nested == 0 && "read_cb must be called from a fresh stack");
printf("Read. nread == %d\n", (int)nread);
- free(buf.base);
+ free(buf->base);
if (nread == 0) {
return;
} else if (nread < 0) {
@@ -171,20 +169,25 @@
connect_cb_called++;
}
TEST_IMPL(callback_stack) {
- struct sockaddr_in addr = uv_ip4_addr("127.0.0.1", TEST_PORT);
+ struct sockaddr_in addr;
+ ASSERT(0 == uv_ip4_addr("127.0.0.1", TEST_PORT, &addr));
+
if (uv_tcp_init(uv_default_loop(), &client)) {
FATAL("uv_tcp_init failed");
}
puts("Connecting...");
nested++;
- if (uv_tcp_connect(&connect_req, &client, addr, connect_cb)) {
+ if (uv_tcp_connect(&connect_req,
+ &client,
+ (const struct sockaddr*) &addr,
+ connect_cb)) {
FATAL("uv_tcp_connect failed");
}
nested--;
uv_run(uv_default_loop(), UV_RUN_DEFAULT);