asyncengine 0.0.1.testing1 → 0.0.2.alpha1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +3 -0
- data/Rakefile +38 -0
- data/asyncengine.gemspec +8 -4
- data/ext/asyncengine/ae_call_from_other_thread.c +106 -0
- data/ext/asyncengine/ae_call_from_other_thread.h +12 -0
- data/ext/asyncengine/ae_handle_common.c +193 -48
- data/ext/asyncengine/ae_handle_common.h +40 -13
- data/ext/asyncengine/ae_ip_utils.c +246 -0
- data/ext/asyncengine/ae_ip_utils.h +25 -0
- data/ext/asyncengine/ae_next_tick.c +81 -21
- data/ext/asyncengine/ae_next_tick.h +4 -2
- data/ext/asyncengine/ae_resolver.c +156 -0
- data/ext/asyncengine/ae_resolver.h +10 -0
- data/ext/asyncengine/ae_tcp.c +908 -0
- data/ext/asyncengine/ae_tcp.h +20 -0
- data/ext/asyncengine/ae_timer.c +355 -81
- data/ext/asyncengine/ae_timer.h +11 -4
- data/ext/asyncengine/ae_udp.c +579 -13
- data/ext/asyncengine/ae_udp.h +15 -2
- data/ext/asyncengine/ae_utils.c +192 -0
- data/ext/asyncengine/ae_utils.h +16 -0
- data/ext/asyncengine/asyncengine_ruby.c +469 -26
- data/ext/asyncengine/asyncengine_ruby.h +49 -11
- data/ext/asyncengine/debug.h +68 -0
- data/ext/asyncengine/extconf.rb +26 -2
- data/ext/asyncengine/ip_parser.c +5954 -0
- data/ext/asyncengine/ip_parser.h +16 -0
- data/ext/asyncengine/libuv/AUTHORS +16 -0
- data/ext/asyncengine/libuv/common.gypi +4 -4
- data/ext/asyncengine/libuv/config-mingw.mk +6 -6
- data/ext/asyncengine/libuv/config-unix.mk +13 -13
- data/ext/asyncengine/libuv/gyp_uv +5 -1
- data/ext/asyncengine/libuv/ibc_tests/exec_test.sh +8 -0
- data/ext/asyncengine/libuv/ibc_tests/uv_shutdown_write_issue.c +171 -0
- data/ext/asyncengine/libuv/ibc_tests/uv_tcp_close_while_connecting.c +102 -0
- data/ext/asyncengine/libuv/include/uv-private/ngx-queue.h +3 -1
- data/ext/asyncengine/libuv/include/uv-private/uv-unix.h +103 -50
- data/ext/asyncengine/libuv/include/uv-private/uv-win.h +76 -24
- data/ext/asyncengine/libuv/include/uv.h +353 -88
- data/ext/asyncengine/libuv/src/ares/ares__close_sockets.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares__get_hostent.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares__read_line.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares__timeval.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_cancel.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_data.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_destroy.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_expand_name.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_expand_string.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_fds.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_free_hostent.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_free_string.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_gethostbyaddr.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_gethostbyname.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_getnameinfo.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_getopt.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_getsock.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_init.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_library_init.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_llist.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_mkquery.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_nowarn.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_options.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_parse_a_reply.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_parse_aaaa_reply.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_parse_mx_reply.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_parse_ns_reply.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_parse_ptr_reply.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_parse_srv_reply.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_parse_txt_reply.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_process.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_query.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_search.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_send.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_strcasecmp.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_strdup.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_strerror.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_timeout.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_version.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_writev.o +0 -0
- data/ext/asyncengine/libuv/src/ares/bitncmp.o +0 -0
- data/ext/asyncengine/libuv/src/ares/inet_net_pton.o +0 -0
- data/ext/asyncengine/libuv/src/ares/inet_ntop.o +0 -0
- data/ext/asyncengine/libuv/src/cares.c +225 -0
- data/ext/asyncengine/libuv/src/cares.o +0 -0
- data/ext/asyncengine/libuv/src/fs-poll.c +237 -0
- data/ext/asyncengine/libuv/src/fs-poll.o +0 -0
- data/ext/asyncengine/libuv/src/unix/async.c +78 -17
- data/ext/asyncengine/libuv/src/unix/async.o +0 -0
- data/ext/asyncengine/libuv/src/unix/core.c +305 -213
- data/ext/asyncengine/libuv/src/unix/core.o +0 -0
- data/ext/asyncengine/libuv/src/unix/cygwin.c +1 -1
- data/ext/asyncengine/libuv/src/unix/darwin.c +2 -1
- data/ext/asyncengine/libuv/src/unix/dl.c +36 -44
- data/ext/asyncengine/libuv/src/unix/dl.o +0 -0
- data/ext/asyncengine/libuv/src/unix/eio/eio.o +0 -0
- data/ext/asyncengine/libuv/src/unix/error.c +6 -0
- data/ext/asyncengine/libuv/src/unix/error.o +0 -0
- data/ext/asyncengine/libuv/src/unix/ev/ev.c +8 -4
- data/ext/asyncengine/libuv/src/unix/ev/ev.o +0 -0
- data/ext/asyncengine/libuv/src/unix/freebsd.c +1 -1
- data/ext/asyncengine/libuv/src/unix/fs.c +25 -33
- data/ext/asyncengine/libuv/src/unix/fs.o +0 -0
- data/ext/asyncengine/libuv/src/unix/internal.h +50 -31
- data/ext/asyncengine/libuv/src/unix/kqueue.c +2 -7
- data/ext/asyncengine/libuv/src/unix/linux/core.o +0 -0
- data/ext/asyncengine/libuv/src/unix/linux/inotify.c +12 -14
- data/ext/asyncengine/libuv/src/unix/linux/inotify.o +0 -0
- data/ext/asyncengine/libuv/src/unix/linux/{core.c → linux-core.c} +1 -1
- data/ext/asyncengine/libuv/src/unix/linux/linux-core.o +0 -0
- data/ext/asyncengine/libuv/src/unix/linux/syscalls.c +147 -1
- data/ext/asyncengine/libuv/src/unix/linux/syscalls.h +39 -2
- data/ext/asyncengine/libuv/src/unix/linux/syscalls.o +0 -0
- data/ext/asyncengine/libuv/src/unix/loop-watcher.c +63 -0
- data/ext/asyncengine/libuv/src/unix/loop-watcher.o +0 -0
- data/ext/asyncengine/libuv/src/unix/loop.c +29 -6
- data/ext/asyncengine/libuv/src/unix/loop.o +0 -0
- data/ext/asyncengine/libuv/src/unix/netbsd.c +1 -1
- data/ext/asyncengine/libuv/src/unix/openbsd.c +1 -1
- data/ext/asyncengine/libuv/src/unix/pipe.c +31 -36
- data/ext/asyncengine/libuv/src/unix/pipe.o +0 -0
- data/ext/asyncengine/libuv/src/unix/poll.c +116 -0
- data/ext/asyncengine/libuv/src/unix/poll.o +0 -0
- data/ext/asyncengine/libuv/src/unix/process.c +193 -115
- data/ext/asyncengine/libuv/src/unix/process.o +0 -0
- data/ext/asyncengine/libuv/src/unix/stream.c +146 -153
- data/ext/asyncengine/libuv/src/unix/stream.o +0 -0
- data/ext/asyncengine/libuv/src/unix/sunos.c +45 -36
- data/ext/asyncengine/libuv/src/unix/tcp.c +6 -5
- data/ext/asyncengine/libuv/src/unix/tcp.o +0 -0
- data/ext/asyncengine/libuv/src/unix/thread.c +82 -25
- data/ext/asyncengine/libuv/src/unix/thread.o +0 -0
- data/ext/asyncengine/libuv/src/unix/timer.c +69 -58
- data/ext/asyncengine/libuv/src/unix/timer.o +0 -0
- data/ext/asyncengine/libuv/src/unix/tty.c +3 -3
- data/ext/asyncengine/libuv/src/unix/tty.o +0 -0
- data/ext/asyncengine/libuv/src/unix/udp.c +57 -66
- data/ext/asyncengine/libuv/src/unix/udp.o +0 -0
- data/ext/asyncengine/libuv/src/unix/uv-eio.c +33 -50
- data/ext/asyncengine/libuv/src/unix/uv-eio.o +0 -0
- data/ext/asyncengine/libuv/src/uv-common.c +68 -38
- data/ext/asyncengine/libuv/src/uv-common.h +104 -20
- data/ext/asyncengine/libuv/src/uv-common.o +0 -0
- data/ext/asyncengine/libuv/src/win/async.c +20 -17
- data/ext/asyncengine/libuv/src/win/core.c +44 -31
- data/ext/asyncengine/libuv/src/win/dl.c +40 -36
- data/ext/asyncengine/libuv/src/win/error.c +21 -1
- data/ext/asyncengine/libuv/src/win/fs-event.c +19 -21
- data/ext/asyncengine/libuv/src/win/fs.c +541 -189
- data/ext/asyncengine/libuv/src/win/getaddrinfo.c +56 -63
- data/ext/asyncengine/libuv/src/win/handle-inl.h +145 -0
- data/ext/asyncengine/libuv/src/win/handle.c +26 -101
- data/ext/asyncengine/libuv/src/win/internal.h +92 -107
- data/ext/asyncengine/libuv/src/win/loop-watcher.c +6 -14
- data/ext/asyncengine/libuv/src/win/pipe.c +78 -64
- data/ext/asyncengine/libuv/src/win/poll.c +618 -0
- data/ext/asyncengine/libuv/src/win/process-stdio.c +479 -0
- data/ext/asyncengine/libuv/src/win/process.c +147 -274
- data/ext/asyncengine/libuv/src/win/req-inl.h +225 -0
- data/ext/asyncengine/libuv/src/win/req.c +0 -149
- data/ext/asyncengine/libuv/src/{unix/check.c → win/stream-inl.h} +31 -42
- data/ext/asyncengine/libuv/src/win/stream.c +9 -43
- data/ext/asyncengine/libuv/src/win/tcp.c +200 -82
- data/ext/asyncengine/libuv/src/win/thread.c +42 -2
- data/ext/asyncengine/libuv/src/win/threadpool.c +3 -2
- data/ext/asyncengine/libuv/src/win/timer.c +13 -63
- data/ext/asyncengine/libuv/src/win/tty.c +26 -20
- data/ext/asyncengine/libuv/src/win/udp.c +26 -17
- data/ext/asyncengine/libuv/src/win/util.c +312 -167
- data/ext/asyncengine/libuv/src/win/winapi.c +16 -1
- data/ext/asyncengine/libuv/src/win/winapi.h +33 -9
- data/ext/asyncengine/libuv/src/win/winsock.c +88 -1
- data/ext/asyncengine/libuv/src/win/winsock.h +36 -3
- data/ext/asyncengine/libuv/test/benchmark-ares.c +16 -17
- data/ext/asyncengine/libuv/test/benchmark-fs-stat.c +164 -0
- data/ext/asyncengine/libuv/test/benchmark-list.h +9 -0
- data/ext/asyncengine/libuv/{src/unix/prepare.c → test/benchmark-loop-count.c} +42 -33
- data/ext/asyncengine/libuv/test/benchmark-million-timers.c +65 -0
- data/ext/asyncengine/libuv/test/benchmark-pound.c +1 -1
- data/ext/asyncengine/libuv/test/benchmark-sizes.c +2 -0
- data/ext/asyncengine/libuv/test/benchmark-spawn.c +7 -1
- data/ext/asyncengine/libuv/test/benchmark-udp-packet-storm.c +1 -1
- data/ext/asyncengine/libuv/test/echo-server.c +8 -0
- data/ext/asyncengine/libuv/test/run-tests.c +30 -0
- data/ext/asyncengine/libuv/test/runner-unix.c +6 -26
- data/ext/asyncengine/libuv/test/runner-win.c +5 -63
- data/ext/asyncengine/libuv/test/runner.c +10 -1
- data/ext/asyncengine/libuv/test/task.h +0 -8
- data/ext/asyncengine/libuv/test/test-async.c +43 -141
- data/ext/asyncengine/libuv/test/test-callback-order.c +76 -0
- data/ext/asyncengine/libuv/test/test-counters-init.c +2 -3
- data/ext/asyncengine/libuv/test/test-dlerror.c +17 -8
- data/ext/asyncengine/libuv/test/test-fs-event.c +31 -39
- data/ext/asyncengine/libuv/test/test-fs-poll.c +146 -0
- data/ext/asyncengine/libuv/test/test-fs.c +114 -2
- data/ext/asyncengine/libuv/test/test-gethostbyname.c +8 -8
- data/ext/asyncengine/libuv/test/test-hrtime.c +18 -15
- data/ext/asyncengine/libuv/test/test-ipc.c +8 -2
- data/ext/asyncengine/libuv/test/test-list.h +59 -9
- data/ext/asyncengine/libuv/test/test-loop-handles.c +2 -25
- data/ext/asyncengine/libuv/{src/unix/idle.c → test/test-poll-close.c} +37 -39
- data/ext/asyncengine/libuv/test/test-poll.c +573 -0
- data/ext/asyncengine/libuv/test/test-ref.c +79 -63
- data/ext/asyncengine/libuv/test/test-run-once.c +15 -11
- data/ext/asyncengine/libuv/test/test-semaphore.c +111 -0
- data/ext/asyncengine/libuv/test/test-spawn.c +368 -20
- data/ext/asyncengine/libuv/test/test-stdio-over-pipes.c +25 -35
- data/ext/asyncengine/libuv/test/test-tcp-close-while-connecting.c +80 -0
- data/ext/asyncengine/libuv/test/test-tcp-close.c +1 -1
- data/ext/asyncengine/libuv/test/test-tcp-connect-error-after-write.c +95 -0
- data/ext/asyncengine/libuv/test/test-tcp-connect-timeout.c +85 -0
- data/ext/asyncengine/libuv/test/test-tcp-shutdown-after-write.c +131 -0
- data/ext/asyncengine/libuv/test/test-tcp-write-error.c +2 -2
- data/ext/asyncengine/libuv/test/test-tcp-writealot.c +29 -54
- data/ext/asyncengine/libuv/test/test-timer-again.c +1 -1
- data/ext/asyncengine/libuv/test/test-timer.c +23 -1
- data/ext/asyncengine/libuv/test/test-udp-options.c +1 -1
- data/ext/asyncengine/libuv/test/{test-eio-overflow.c → test-walk-handles.c} +31 -44
- data/ext/asyncengine/libuv/uv.gyp +26 -9
- data/ext/asyncengine/rb_utilities.c +54 -0
- data/ext/asyncengine/rb_utilities.h +63 -0
- data/lib/asyncengine.rb +45 -38
- data/lib/asyncengine/asyncengine_ext.so +0 -0
- data/lib/asyncengine/debug.rb +37 -0
- data/lib/asyncengine/handle.rb +9 -0
- data/lib/asyncengine/tcp.rb +28 -0
- data/lib/asyncengine/timer.rb +18 -28
- data/lib/asyncengine/udp.rb +29 -0
- data/lib/asyncengine/utils.rb +32 -0
- data/lib/asyncengine/uv_error.rb +17 -0
- data/lib/asyncengine/version.rb +9 -1
- data/test/ae_test_helper.rb +62 -0
- data/test/test_basic.rb +169 -0
- data/test/test_call_from_other_thread.rb +55 -0
- data/test/test_error.rb +92 -0
- data/test/test_ip_utils.rb +44 -0
- data/test/test_next_tick.rb +37 -0
- data/test/test_resolver.rb +51 -0
- data/test/test_threads.rb +69 -0
- data/test/test_timer.rb +95 -0
- data/test/test_udp.rb +216 -0
- data/test/test_utils.rb +49 -0
- metadata +84 -57
- data/ext/asyncengine/libuv/mkmf.log +0 -24
- data/ext/asyncengine/libuv/src/unix/cares.c +0 -194
- data/ext/asyncengine/libuv/src/unix/cares.o +0 -0
- data/ext/asyncengine/libuv/src/unix/check.o +0 -0
- data/ext/asyncengine/libuv/src/unix/idle.o +0 -0
- data/ext/asyncengine/libuv/src/unix/prepare.o +0 -0
- data/ext/asyncengine/libuv/src/win/cares.c +0 -290
- data/lib/asyncengine/errors.rb +0 -5
- data/lib/asyncengine/next_tick.rb +0 -24
@@ -32,30 +32,50 @@ static uv_connect_t connect_req;
|
|
32
32
|
|
33
33
|
static char buffer[32767];
|
34
34
|
|
35
|
+
static int req_cb_called;
|
36
|
+
static int connect_cb_called;
|
37
|
+
static int write_cb_called;
|
38
|
+
static int shutdown_cb_called;
|
39
|
+
|
35
40
|
|
36
41
|
static void fail_cb(void) {
|
37
42
|
FATAL("fail_cb should not have been called");
|
38
43
|
}
|
39
44
|
|
40
45
|
|
41
|
-
static void
|
42
|
-
|
46
|
+
static void req_cb(uv_handle_t* req, int status) {
|
47
|
+
req_cb_called++;
|
48
|
+
}
|
43
49
|
|
44
|
-
ASSERT(req == &connect_req);
|
45
|
-
ASSERT(status == 0);
|
46
50
|
|
47
|
-
|
48
|
-
|
51
|
+
static void shutdown_cb(uv_shutdown_t* req, int status) {
|
52
|
+
ASSERT(req == &shutdown_req);
|
53
|
+
shutdown_cb_called++;
|
49
54
|
}
|
50
55
|
|
51
56
|
|
57
|
+
static void write_cb(uv_write_t* req, int status) {
|
58
|
+
ASSERT(req == &write_req);
|
59
|
+
uv_shutdown(&shutdown_req, req->handle, shutdown_cb);
|
60
|
+
write_cb_called++;
|
61
|
+
}
|
62
|
+
|
52
63
|
|
53
|
-
static void
|
64
|
+
static void connect_and_write(uv_connect_t* req, int status) {
|
65
|
+
uv_buf_t buf = uv_buf_init(buffer, sizeof buffer);
|
54
66
|
ASSERT(req == &connect_req);
|
55
67
|
ASSERT(status == 0);
|
68
|
+
uv_write(&write_req, req->handle, &buf, 1, write_cb);
|
69
|
+
connect_cb_called++;
|
70
|
+
}
|
56
71
|
|
57
|
-
|
58
|
-
|
72
|
+
|
73
|
+
|
74
|
+
static void connect_and_shutdown(uv_connect_t* req, int status) {
|
75
|
+
ASSERT(req == &connect_req);
|
76
|
+
ASSERT(status == 0);
|
77
|
+
uv_shutdown(&shutdown_req, req->handle, shutdown_cb);
|
78
|
+
connect_cb_called++;
|
59
79
|
}
|
60
80
|
|
61
81
|
|
@@ -69,7 +89,7 @@ TEST_IMPL(idle_ref) {
|
|
69
89
|
uv_idle_t h;
|
70
90
|
uv_idle_init(uv_default_loop(), &h);
|
71
91
|
uv_idle_start(&h, NULL);
|
72
|
-
uv_unref(
|
92
|
+
uv_unref((uv_handle_t*)&h);
|
73
93
|
uv_run(uv_default_loop());
|
74
94
|
return 0;
|
75
95
|
}
|
@@ -78,7 +98,7 @@ TEST_IMPL(idle_ref) {
|
|
78
98
|
TEST_IMPL(async_ref) {
|
79
99
|
uv_async_t h;
|
80
100
|
uv_async_init(uv_default_loop(), &h, NULL);
|
81
|
-
uv_unref(
|
101
|
+
uv_unref((uv_handle_t*)&h);
|
82
102
|
uv_run(uv_default_loop());
|
83
103
|
return 0;
|
84
104
|
}
|
@@ -88,7 +108,7 @@ TEST_IMPL(prepare_ref) {
|
|
88
108
|
uv_prepare_t h;
|
89
109
|
uv_prepare_init(uv_default_loop(), &h);
|
90
110
|
uv_prepare_start(&h, NULL);
|
91
|
-
uv_unref(
|
111
|
+
uv_unref((uv_handle_t*)&h);
|
92
112
|
uv_run(uv_default_loop());
|
93
113
|
return 0;
|
94
114
|
}
|
@@ -98,17 +118,16 @@ TEST_IMPL(check_ref) {
|
|
98
118
|
uv_check_t h;
|
99
119
|
uv_check_init(uv_default_loop(), &h);
|
100
120
|
uv_check_start(&h, NULL);
|
101
|
-
uv_unref(
|
121
|
+
uv_unref((uv_handle_t*)&h);
|
102
122
|
uv_run(uv_default_loop());
|
103
123
|
return 0;
|
104
124
|
}
|
105
125
|
|
106
126
|
|
107
|
-
static void prepare_cb(uv_prepare_t*
|
108
|
-
ASSERT(
|
127
|
+
static void prepare_cb(uv_prepare_t* h, int status) {
|
128
|
+
ASSERT(h != NULL);
|
109
129
|
ASSERT(status == 0);
|
110
|
-
|
111
|
-
uv_unref(uv_default_loop());
|
130
|
+
uv_unref((uv_handle_t*)h);
|
112
131
|
}
|
113
132
|
|
114
133
|
|
@@ -124,7 +143,7 @@ TEST_IMPL(unref_in_prepare_cb) {
|
|
124
143
|
TEST_IMPL(timer_ref) {
|
125
144
|
uv_timer_t h;
|
126
145
|
uv_timer_init(uv_default_loop(), &h);
|
127
|
-
uv_unref(
|
146
|
+
uv_unref((uv_handle_t*)&h);
|
128
147
|
uv_run(uv_default_loop());
|
129
148
|
return 0;
|
130
149
|
}
|
@@ -133,8 +152,8 @@ TEST_IMPL(timer_ref) {
|
|
133
152
|
TEST_IMPL(timer_ref2) {
|
134
153
|
uv_timer_t h;
|
135
154
|
uv_timer_init(uv_default_loop(), &h);
|
136
|
-
uv_timer_start(&h, (uv_timer_cb)
|
137
|
-
uv_unref(
|
155
|
+
uv_timer_start(&h, (uv_timer_cb)fail_cb, 42, 42);
|
156
|
+
uv_unref((uv_handle_t*)&h);
|
138
157
|
uv_run(uv_default_loop());
|
139
158
|
return 0;
|
140
159
|
}
|
@@ -142,62 +161,65 @@ TEST_IMPL(timer_ref2) {
|
|
142
161
|
|
143
162
|
TEST_IMPL(fs_event_ref) {
|
144
163
|
uv_fs_event_t h;
|
145
|
-
uv_fs_event_init(uv_default_loop(), &h, ".", (uv_fs_event_cb)
|
146
|
-
uv_unref(
|
164
|
+
uv_fs_event_init(uv_default_loop(), &h, ".", (uv_fs_event_cb)fail_cb, 0);
|
165
|
+
uv_unref((uv_handle_t*)&h);
|
147
166
|
uv_run(uv_default_loop());
|
148
167
|
return 0;
|
149
168
|
}
|
150
169
|
|
151
170
|
|
152
|
-
TEST_IMPL(
|
153
|
-
|
154
|
-
|
155
|
-
|
171
|
+
TEST_IMPL(fs_poll_ref) {
|
172
|
+
uv_fs_poll_t h;
|
173
|
+
uv_fs_poll_init(uv_default_loop(), &h);
|
174
|
+
uv_fs_poll_start(&h, NULL, ".", 999);
|
175
|
+
uv_unref((uv_handle_t*)&h);
|
156
176
|
uv_run(uv_default_loop());
|
157
177
|
return 0;
|
158
178
|
}
|
159
179
|
|
160
180
|
|
161
|
-
TEST_IMPL(
|
181
|
+
TEST_IMPL(tcp_ref) {
|
162
182
|
uv_tcp_t h;
|
163
183
|
uv_tcp_init(uv_default_loop(), &h);
|
164
|
-
|
165
|
-
uv_unref(uv_default_loop());
|
184
|
+
uv_unref((uv_handle_t*)&h);
|
166
185
|
uv_run(uv_default_loop());
|
167
186
|
return 0;
|
168
187
|
}
|
169
188
|
|
170
189
|
|
171
|
-
TEST_IMPL(
|
172
|
-
struct sockaddr_in addr = uv_ip4_addr("127.0.0.1", TEST_PORT);
|
190
|
+
TEST_IMPL(tcp_ref2) {
|
173
191
|
uv_tcp_t h;
|
174
192
|
uv_tcp_init(uv_default_loop(), &h);
|
175
|
-
|
176
|
-
uv_unref(
|
177
|
-
uv_unref(uv_default_loop()); /* connect req refs the loop */
|
193
|
+
uv_listen((uv_stream_t*)&h, 128, (uv_connection_cb)fail_cb);
|
194
|
+
uv_unref((uv_handle_t*)&h);
|
178
195
|
uv_run(uv_default_loop());
|
179
196
|
return 0;
|
180
197
|
}
|
181
198
|
|
182
199
|
|
183
|
-
TEST_IMPL(
|
200
|
+
TEST_IMPL(tcp_ref3) {
|
184
201
|
struct sockaddr_in addr = uv_ip4_addr("127.0.0.1", TEST_PORT);
|
185
202
|
uv_tcp_t h;
|
186
203
|
uv_tcp_init(uv_default_loop(), &h);
|
187
|
-
uv_tcp_connect(&connect_req, &h, addr,
|
188
|
-
uv_unref(
|
204
|
+
uv_tcp_connect(&connect_req, &h, addr, connect_and_shutdown);
|
205
|
+
uv_unref((uv_handle_t*)&h);
|
189
206
|
uv_run(uv_default_loop());
|
207
|
+
ASSERT(connect_cb_called == 1);
|
208
|
+
ASSERT(shutdown_cb_called == 1);
|
190
209
|
return 0;
|
191
210
|
}
|
192
211
|
|
193
212
|
|
194
|
-
TEST_IMPL(
|
213
|
+
TEST_IMPL(tcp_ref4) {
|
195
214
|
struct sockaddr_in addr = uv_ip4_addr("127.0.0.1", TEST_PORT);
|
196
215
|
uv_tcp_t h;
|
197
216
|
uv_tcp_init(uv_default_loop(), &h);
|
198
|
-
uv_tcp_connect(&connect_req, &h, addr,
|
199
|
-
uv_unref(
|
217
|
+
uv_tcp_connect(&connect_req, &h, addr, connect_and_write);
|
218
|
+
uv_unref((uv_handle_t*)&h);
|
200
219
|
uv_run(uv_default_loop());
|
220
|
+
ASSERT(connect_cb_called == 1);
|
221
|
+
ASSERT(write_cb_called == 1);
|
222
|
+
ASSERT(shutdown_cb_called == 1);
|
201
223
|
return 0;
|
202
224
|
}
|
203
225
|
|
@@ -205,7 +227,7 @@ TEST_IMPL(tcp_ref5) {
|
|
205
227
|
TEST_IMPL(udp_ref) {
|
206
228
|
uv_udp_t h;
|
207
229
|
uv_udp_init(uv_default_loop(), &h);
|
208
|
-
uv_unref(
|
230
|
+
uv_unref((uv_handle_t*)&h);
|
209
231
|
uv_run(uv_default_loop());
|
210
232
|
return 0;
|
211
233
|
}
|
@@ -217,7 +239,7 @@ TEST_IMPL(udp_ref2) {
|
|
217
239
|
uv_udp_init(uv_default_loop(), &h);
|
218
240
|
uv_udp_bind(&h, addr, 0);
|
219
241
|
uv_udp_recv_start(&h, (uv_alloc_cb)fail_cb, (uv_udp_recv_cb)fail_cb);
|
220
|
-
uv_unref(
|
242
|
+
uv_unref((uv_handle_t*)&h);
|
221
243
|
uv_run(uv_default_loop());
|
222
244
|
return 0;
|
223
245
|
}
|
@@ -230,10 +252,10 @@ TEST_IMPL(udp_ref3) {
|
|
230
252
|
uv_udp_t h;
|
231
253
|
|
232
254
|
uv_udp_init(uv_default_loop(), &h);
|
233
|
-
uv_udp_send(&req, &h, &buf, 1, addr, (uv_udp_send_cb)
|
234
|
-
uv_unref(
|
235
|
-
uv_unref(uv_default_loop()); /* send req refs the loop */
|
255
|
+
uv_udp_send(&req, &h, &buf, 1, addr, (uv_udp_send_cb)req_cb);
|
256
|
+
uv_unref((uv_handle_t*)&h);
|
236
257
|
uv_run(uv_default_loop());
|
258
|
+
ASSERT(req_cb_called == 1);
|
237
259
|
|
238
260
|
return 0;
|
239
261
|
}
|
@@ -242,7 +264,7 @@ TEST_IMPL(udp_ref3) {
|
|
242
264
|
TEST_IMPL(pipe_ref) {
|
243
265
|
uv_pipe_t h;
|
244
266
|
uv_pipe_init(uv_default_loop(), &h, 0);
|
245
|
-
uv_unref(
|
267
|
+
uv_unref((uv_handle_t*)&h);
|
246
268
|
uv_run(uv_default_loop());
|
247
269
|
return 0;
|
248
270
|
}
|
@@ -252,7 +274,7 @@ TEST_IMPL(pipe_ref2) {
|
|
252
274
|
uv_pipe_t h;
|
253
275
|
uv_pipe_init(uv_default_loop(), &h, 0);
|
254
276
|
uv_listen((uv_stream_t*)&h, 128, (uv_connection_cb)fail_cb);
|
255
|
-
uv_unref(
|
277
|
+
uv_unref((uv_handle_t*)&h);
|
256
278
|
uv_run(uv_default_loop());
|
257
279
|
return 0;
|
258
280
|
}
|
@@ -261,10 +283,11 @@ TEST_IMPL(pipe_ref2) {
|
|
261
283
|
TEST_IMPL(pipe_ref3) {
|
262
284
|
uv_pipe_t h;
|
263
285
|
uv_pipe_init(uv_default_loop(), &h, 0);
|
264
|
-
uv_pipe_connect(&connect_req, &h, TEST_PIPENAME,
|
265
|
-
uv_unref(
|
266
|
-
uv_unref(uv_default_loop()); /* connect req refs the loop */
|
286
|
+
uv_pipe_connect(&connect_req, &h, TEST_PIPENAME, connect_and_shutdown);
|
287
|
+
uv_unref((uv_handle_t*)&h);
|
267
288
|
uv_run(uv_default_loop());
|
289
|
+
ASSERT(connect_cb_called == 1);
|
290
|
+
ASSERT(shutdown_cb_called == 1);
|
268
291
|
return 0;
|
269
292
|
}
|
270
293
|
|
@@ -272,19 +295,12 @@ TEST_IMPL(pipe_ref3) {
|
|
272
295
|
TEST_IMPL(pipe_ref4) {
|
273
296
|
uv_pipe_t h;
|
274
297
|
uv_pipe_init(uv_default_loop(), &h, 0);
|
275
|
-
uv_pipe_connect(&connect_req, &h, TEST_PIPENAME,
|
276
|
-
uv_unref(
|
277
|
-
uv_run(uv_default_loop());
|
278
|
-
return 0;
|
279
|
-
}
|
280
|
-
|
281
|
-
|
282
|
-
TEST_IMPL(pipe_ref5) {
|
283
|
-
uv_pipe_t h;
|
284
|
-
uv_pipe_init(uv_default_loop(), &h, 0);
|
285
|
-
uv_pipe_connect(&connect_req, &h, TEST_PIPENAME, shutdown_unref_cb);
|
286
|
-
uv_unref(uv_default_loop());
|
298
|
+
uv_pipe_connect(&connect_req, &h, TEST_PIPENAME, connect_and_write);
|
299
|
+
uv_unref((uv_handle_t*)&h);
|
287
300
|
uv_run(uv_default_loop());
|
301
|
+
ASSERT(connect_cb_called == 1);
|
302
|
+
ASSERT(write_cb_called == 1);
|
303
|
+
ASSERT(shutdown_cb_called == 1);
|
288
304
|
return 0;
|
289
305
|
}
|
290
306
|
|
@@ -312,7 +328,7 @@ TEST_IMPL(process_ref) {
|
|
312
328
|
r = uv_spawn(uv_default_loop(), &h, options);
|
313
329
|
ASSERT(r == 0);
|
314
330
|
|
315
|
-
uv_unref(
|
331
|
+
uv_unref((uv_handle_t*)&h);
|
316
332
|
uv_run(uv_default_loop());
|
317
333
|
|
318
334
|
r = uv_process_kill(&h, /* SIGTERM */ 15);
|
@@ -22,23 +22,27 @@
|
|
22
22
|
#include "uv.h"
|
23
23
|
#include "task.h"
|
24
24
|
|
25
|
-
|
25
|
+
#define NUM_TICKS 64
|
26
|
+
|
27
|
+
static uv_idle_t idle_handle;
|
28
|
+
static int idle_counter;
|
29
|
+
|
26
30
|
|
27
31
|
static void idle_cb(uv_idle_t* handle, int status) {
|
28
|
-
ASSERT(handle
|
32
|
+
ASSERT(handle == &idle_handle);
|
29
33
|
ASSERT(status == 0);
|
30
|
-
|
34
|
+
|
35
|
+
if (++idle_counter == NUM_TICKS)
|
36
|
+
uv_idle_stop(handle);
|
31
37
|
}
|
32
38
|
|
33
39
|
|
34
40
|
TEST_IMPL(run_once) {
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
}
|
42
|
-
ASSERT(n == 500);
|
41
|
+
uv_idle_init(uv_default_loop(), &idle_handle);
|
42
|
+
uv_idle_start(&idle_handle, idle_cb);
|
43
|
+
|
44
|
+
while (uv_run_once(uv_default_loop()));
|
45
|
+
ASSERT(idle_counter == NUM_TICKS);
|
46
|
+
|
43
47
|
return 0;
|
44
48
|
}
|
@@ -0,0 +1,111 @@
|
|
1
|
+
/* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
|
2
|
+
*
|
3
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
* of this software and associated documentation files (the "Software"), to
|
5
|
+
* deal in the Software without restriction, including without limitation the
|
6
|
+
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
7
|
+
* sell copies of the Software, and to permit persons to whom the Software is
|
8
|
+
* furnished to do so, subject to the following conditions:
|
9
|
+
*
|
10
|
+
* The above copyright notice and this permission notice shall be included in
|
11
|
+
* all copies or substantial portions of the Software.
|
12
|
+
*
|
13
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
18
|
+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
19
|
+
* IN THE SOFTWARE.
|
20
|
+
*/
|
21
|
+
|
22
|
+
#include "uv.h"
|
23
|
+
#include "task.h"
|
24
|
+
|
25
|
+
#include <stdlib.h>
|
26
|
+
#include <string.h>
|
27
|
+
|
28
|
+
typedef struct {
|
29
|
+
uv_mutex_t mutex;
|
30
|
+
uv_sem_t sem;
|
31
|
+
int delay;
|
32
|
+
volatile int posted;
|
33
|
+
} worker_config;
|
34
|
+
|
35
|
+
|
36
|
+
static void worker(void* arg) {
|
37
|
+
worker_config* c = arg;
|
38
|
+
|
39
|
+
if (c->delay)
|
40
|
+
uv_sleep(c->delay);
|
41
|
+
|
42
|
+
uv_mutex_lock(&c->mutex);
|
43
|
+
ASSERT(c->posted == 0);
|
44
|
+
uv_sem_post(&c->sem);
|
45
|
+
c->posted = 1;
|
46
|
+
uv_mutex_unlock(&c->mutex);
|
47
|
+
}
|
48
|
+
|
49
|
+
|
50
|
+
TEST_IMPL(semaphore_1) {
|
51
|
+
uv_thread_t thread;
|
52
|
+
worker_config wc;
|
53
|
+
|
54
|
+
memset(&wc, 0, sizeof(wc));
|
55
|
+
|
56
|
+
ASSERT(0 == uv_sem_init(&wc.sem, 0));
|
57
|
+
ASSERT(0 == uv_mutex_init(&wc.mutex));
|
58
|
+
ASSERT(0 == uv_thread_create(&thread, worker, &wc));
|
59
|
+
|
60
|
+
uv_sleep(100);
|
61
|
+
uv_mutex_lock(&wc.mutex);
|
62
|
+
ASSERT(wc.posted == 1);
|
63
|
+
uv_sem_wait(&wc.sem); /* should not block */
|
64
|
+
uv_mutex_unlock(&wc.mutex); /* ergo, it should be ok to unlock after wait */
|
65
|
+
|
66
|
+
ASSERT(0 == uv_thread_join(&thread));
|
67
|
+
uv_mutex_destroy(&wc.mutex);
|
68
|
+
uv_sem_destroy(&wc.sem);
|
69
|
+
|
70
|
+
return 0;
|
71
|
+
}
|
72
|
+
|
73
|
+
|
74
|
+
TEST_IMPL(semaphore_2) {
|
75
|
+
uv_thread_t thread;
|
76
|
+
worker_config wc;
|
77
|
+
|
78
|
+
memset(&wc, 0, sizeof(wc));
|
79
|
+
wc.delay = 100;
|
80
|
+
|
81
|
+
ASSERT(0 == uv_sem_init(&wc.sem, 0));
|
82
|
+
ASSERT(0 == uv_mutex_init(&wc.mutex));
|
83
|
+
ASSERT(0 == uv_thread_create(&thread, worker, &wc));
|
84
|
+
|
85
|
+
uv_sem_wait(&wc.sem);
|
86
|
+
|
87
|
+
ASSERT(0 == uv_thread_join(&thread));
|
88
|
+
uv_mutex_destroy(&wc.mutex);
|
89
|
+
uv_sem_destroy(&wc.sem);
|
90
|
+
|
91
|
+
return 0;
|
92
|
+
}
|
93
|
+
|
94
|
+
|
95
|
+
TEST_IMPL(semaphore_3) {
|
96
|
+
uv_sem_t sem;
|
97
|
+
|
98
|
+
ASSERT(0 == uv_sem_init(&sem, 3));
|
99
|
+
uv_sem_wait(&sem); /* should not block */
|
100
|
+
uv_sem_wait(&sem); /* should not block */
|
101
|
+
ASSERT(0 == uv_sem_trywait(&sem));
|
102
|
+
ASSERT(-1 == uv_sem_trywait(&sem));
|
103
|
+
|
104
|
+
uv_sem_post(&sem);
|
105
|
+
ASSERT(0 == uv_sem_trywait(&sem));
|
106
|
+
ASSERT(-1 == uv_sem_trywait(&sem));
|
107
|
+
|
108
|
+
uv_sem_destroy(&sem);
|
109
|
+
|
110
|
+
return 0;
|
111
|
+
}
|