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
@@ -19,6 +19,7 @@
|
|
19
19
|
* IN THE SOFTWARE.
|
20
20
|
*/
|
21
21
|
|
22
|
+
#include <stdio.h>
|
22
23
|
#include <string.h>
|
23
24
|
|
24
25
|
#include "runner.h"
|
@@ -28,7 +29,10 @@ char executable_path[PATHMAX] = { '\0' };
|
|
28
29
|
|
29
30
|
|
30
31
|
static void log_progress(int total, int passed, int failed, const char* name) {
|
31
|
-
|
32
|
+
if (total == 0)
|
33
|
+
total = 1;
|
34
|
+
|
35
|
+
LOGF("[%% %3d|+ %3d|- %3d]: %s", (int) ((passed + failed) / ((double) total) * 100.0),
|
32
36
|
passed, failed, name);
|
33
37
|
}
|
34
38
|
|
@@ -89,6 +93,11 @@ int run_test(const char* test, int timeout, int benchmark_output) {
|
|
89
93
|
main_proc = NULL;
|
90
94
|
process_count = 0;
|
91
95
|
|
96
|
+
#ifndef _WIN32
|
97
|
+
/* Clean up stale socket from previous run. */
|
98
|
+
remove(TEST_PIPENAME);
|
99
|
+
#endif
|
100
|
+
|
92
101
|
/* If it's a helper the user asks for, start it directly. */
|
93
102
|
for (task = TASKS; task->main; task++) {
|
94
103
|
if (task->is_helper && strcmp(test, task->process_name) == 0) {
|
@@ -103,14 +103,6 @@ typedef enum {
|
|
103
103
|
int run_helper_##name()
|
104
104
|
|
105
105
|
|
106
|
-
/* Create a thread. Returns the thread identifier, or 0 on failure. */
|
107
|
-
uintptr_t uv_create_thread(void (*entry)(void* arg), void* arg);
|
108
|
-
|
109
|
-
/* Wait for a thread to terminate. Should return 0 if the thread ended, -1 on
|
110
|
-
* error.
|
111
|
-
*/
|
112
|
-
int uv_wait_thread(uintptr_t thread_id);
|
113
|
-
|
114
106
|
/* Pause the calling thread for a number of milliseconds. */
|
115
107
|
void uv_sleep(int msec);
|
116
108
|
|
@@ -24,192 +24,94 @@
|
|
24
24
|
#include <stdio.h>
|
25
25
|
#include <stdlib.h>
|
26
26
|
|
27
|
+
static uv_thread_t thread;
|
28
|
+
static uv_mutex_t mutex;
|
27
29
|
|
28
|
-
static uv_prepare_t
|
30
|
+
static uv_prepare_t prepare;
|
31
|
+
static uv_async_t async;
|
29
32
|
|
30
|
-
static
|
31
|
-
|
33
|
+
static volatile int async_cb_called;
|
34
|
+
static int prepare_cb_called;
|
35
|
+
static int close_cb_called;
|
32
36
|
|
33
|
-
static int prepare_cb_called = 0;
|
34
37
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
static int close_cb_called = 0;
|
40
|
-
|
41
|
-
static uintptr_t thread1_id = 0;
|
42
|
-
#if 0
|
43
|
-
static uintptr_t thread2_id = 0;
|
44
|
-
static uintptr_t thread3_id = 0;
|
45
|
-
#endif
|
46
|
-
|
47
|
-
|
48
|
-
/* Thread 1 makes sure that async1_cb_called reaches 3 before exiting. */
|
49
|
-
void thread1_entry(void *arg) {
|
50
|
-
uv_sleep(50);
|
51
|
-
|
52
|
-
while (1) {
|
53
|
-
switch (async1_cb_called) {
|
54
|
-
case 0:
|
55
|
-
uv_async_send(&async1_handle);
|
56
|
-
break;
|
57
|
-
|
58
|
-
case 1:
|
59
|
-
uv_async_send(&async1_handle);
|
60
|
-
break;
|
61
|
-
|
62
|
-
case 2:
|
63
|
-
uv_async_send(&async1_handle);
|
64
|
-
break;
|
65
|
-
|
66
|
-
default:
|
67
|
-
return;
|
68
|
-
}
|
69
|
-
}
|
70
|
-
}
|
71
|
-
|
72
|
-
#if 0
|
73
|
-
/* Thread 2 calls uv_async_send on async_handle_2 8 times. */
|
74
|
-
void thread2_entry(void *arg) {
|
75
|
-
int i;
|
76
|
-
|
77
|
-
while (1) {
|
78
|
-
switch (async1_cb_called) {
|
79
|
-
case 0:
|
80
|
-
uv_async_send(&async2_handle);
|
81
|
-
break;
|
38
|
+
void thread_cb(void *arg) {
|
39
|
+
int n;
|
40
|
+
int r;
|
82
41
|
|
83
|
-
|
84
|
-
|
85
|
-
|
42
|
+
for (;;) {
|
43
|
+
uv_mutex_lock(&mutex);
|
44
|
+
n = async_cb_called;
|
45
|
+
uv_mutex_unlock(&mutex);
|
86
46
|
|
87
|
-
|
88
|
-
|
89
|
-
break;
|
47
|
+
if (n == 3) {
|
48
|
+
break;
|
90
49
|
}
|
91
|
-
uv_sleep(5);
|
92
|
-
}
|
93
50
|
|
94
|
-
|
95
|
-
|
51
|
+
r = uv_async_send(&async);
|
52
|
+
ASSERT(r == 0);
|
96
53
|
}
|
97
54
|
}
|
98
55
|
|
99
56
|
|
100
|
-
/* Thread 3 calls uv_async_send on async_handle_2 8 times
|
101
|
-
* after waiting half a second first.
|
102
|
-
*/
|
103
|
-
void thread3_entry(void *arg) {
|
104
|
-
int i;
|
105
|
-
|
106
|
-
for (i = 0; i < 8; i++) {
|
107
|
-
uv_async_send(&async2_handle);
|
108
|
-
}
|
109
|
-
}
|
110
|
-
#endif
|
111
|
-
|
112
|
-
|
113
57
|
static void close_cb(uv_handle_t* handle) {
|
114
58
|
ASSERT(handle != NULL);
|
115
59
|
close_cb_called++;
|
116
60
|
}
|
117
61
|
|
118
62
|
|
119
|
-
static void
|
120
|
-
|
121
|
-
ASSERT(status == 0);
|
122
|
-
|
123
|
-
async1_cb_called++;
|
124
|
-
printf("async1_cb #%d\n", async1_cb_called);
|
125
|
-
|
126
|
-
if (async1_cb_called > 2 && !async1_closed) {
|
127
|
-
async1_closed = 1;
|
128
|
-
uv_close((uv_handle_t*)handle, close_cb);
|
129
|
-
}
|
130
|
-
}
|
131
|
-
|
63
|
+
static void async_cb(uv_async_t* handle, int status) {
|
64
|
+
int n;
|
132
65
|
|
133
|
-
|
134
|
-
static void async2_cb(uv_handle_t* handle, int status) {
|
135
|
-
ASSERT(handle == &async2_handle);
|
66
|
+
ASSERT(handle == &async);
|
136
67
|
ASSERT(status == 0);
|
137
68
|
|
138
|
-
|
139
|
-
|
69
|
+
uv_mutex_lock(&mutex);
|
70
|
+
n = ++async_cb_called;
|
71
|
+
uv_mutex_unlock(&mutex);
|
140
72
|
|
141
|
-
if (
|
142
|
-
uv_close(
|
73
|
+
if (n == 3) {
|
74
|
+
uv_close((uv_handle_t*)&async, close_cb);
|
75
|
+
uv_close((uv_handle_t*)&prepare, close_cb);
|
143
76
|
}
|
144
77
|
}
|
145
|
-
#endif
|
146
78
|
|
147
79
|
|
148
80
|
static void prepare_cb(uv_prepare_t* handle, int status) {
|
149
|
-
|
150
|
-
ASSERT(status == 0);
|
151
|
-
|
152
|
-
switch (prepare_cb_called) {
|
153
|
-
case 0:
|
154
|
-
thread1_id = uv_create_thread(thread1_entry, NULL);
|
155
|
-
ASSERT(thread1_id != 0);
|
156
|
-
break;
|
157
|
-
|
158
|
-
#if 0
|
159
|
-
case 1:
|
160
|
-
thread2_id = uv_create_thread(thread2_entry, NULL);
|
161
|
-
ASSERT(thread2_id != 0);
|
162
|
-
break;
|
163
|
-
|
164
|
-
case 2:
|
165
|
-
thread3_id = uv_create_thread(thread3_entry, NULL);
|
166
|
-
ASSERT(thread3_id != 0);
|
167
|
-
break;
|
168
|
-
#endif
|
81
|
+
int r;
|
169
82
|
|
170
|
-
|
171
|
-
|
172
|
-
break;
|
83
|
+
ASSERT(handle == &prepare);
|
84
|
+
ASSERT(status == 0);
|
173
85
|
|
174
|
-
|
175
|
-
|
176
|
-
}
|
86
|
+
if (prepare_cb_called++)
|
87
|
+
return;
|
177
88
|
|
178
|
-
|
89
|
+
r = uv_thread_create(&thread, thread_cb, NULL);
|
90
|
+
ASSERT(r == 0);
|
91
|
+
uv_mutex_unlock(&mutex);
|
179
92
|
}
|
180
93
|
|
181
94
|
|
182
95
|
TEST_IMPL(async) {
|
183
96
|
int r;
|
184
97
|
|
185
|
-
r =
|
186
|
-
ASSERT(r == 0);
|
187
|
-
r = uv_prepare_start(&prepare_handle, prepare_cb);
|
98
|
+
r = uv_mutex_init(&mutex);
|
188
99
|
ASSERT(r == 0);
|
100
|
+
uv_mutex_lock(&mutex);
|
189
101
|
|
190
|
-
r =
|
102
|
+
r = uv_prepare_init(uv_default_loop(), &prepare);
|
191
103
|
ASSERT(r == 0);
|
192
|
-
|
193
|
-
#if 0
|
194
|
-
r = uv_async_init(&async2_handle, async2_cb, close_cb, NULL);
|
104
|
+
r = uv_prepare_start(&prepare, prepare_cb);
|
195
105
|
ASSERT(r == 0);
|
196
|
-
#endif
|
197
106
|
|
198
|
-
r =
|
107
|
+
r = uv_async_init(uv_default_loop(), &async, async_cb);
|
199
108
|
ASSERT(r == 0);
|
200
109
|
|
201
|
-
r =
|
202
|
-
ASSERT(r == 0);
|
203
|
-
#if 0
|
204
|
-
r = uv_wait_thread(thread2_id);
|
205
|
-
ASSERT(r == 0);
|
206
|
-
r = uv_wait_thread(thread3_id);
|
110
|
+
r = uv_run(uv_default_loop());
|
207
111
|
ASSERT(r == 0);
|
208
|
-
#endif
|
209
112
|
|
210
|
-
ASSERT(prepare_cb_called
|
211
|
-
ASSERT(
|
212
|
-
/* ASSERT(async2_cb_called = 16); */
|
113
|
+
ASSERT(prepare_cb_called > 0);
|
114
|
+
ASSERT(async_cb_called == 3);
|
213
115
|
ASSERT(close_cb_called == 2);
|
214
116
|
|
215
117
|
return 0;
|
@@ -0,0 +1,76 @@
|
|
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
|
+
static int idle_cb_called;
|
26
|
+
static int timer_cb_called;
|
27
|
+
|
28
|
+
static uv_idle_t idle_handle;
|
29
|
+
static uv_timer_t timer_handle;
|
30
|
+
|
31
|
+
|
32
|
+
/* idle_cb should run before timer_cb */
|
33
|
+
static void idle_cb(uv_idle_t* handle, int status) {
|
34
|
+
ASSERT(idle_cb_called == 0);
|
35
|
+
ASSERT(timer_cb_called == 0);
|
36
|
+
uv_idle_stop(handle);
|
37
|
+
idle_cb_called++;
|
38
|
+
}
|
39
|
+
|
40
|
+
|
41
|
+
static void timer_cb(uv_timer_t* handle, int status) {
|
42
|
+
ASSERT(idle_cb_called == 1);
|
43
|
+
ASSERT(timer_cb_called == 0);
|
44
|
+
uv_timer_stop(handle);
|
45
|
+
timer_cb_called++;
|
46
|
+
}
|
47
|
+
|
48
|
+
|
49
|
+
static void next_tick(uv_idle_t* handle, int status) {
|
50
|
+
uv_loop_t* loop = handle->loop;
|
51
|
+
uv_idle_stop(handle);
|
52
|
+
uv_idle_init(loop, &idle_handle);
|
53
|
+
uv_idle_start(&idle_handle, idle_cb);
|
54
|
+
uv_timer_init(loop, &timer_handle);
|
55
|
+
uv_timer_start(&timer_handle, timer_cb, 0, 0);
|
56
|
+
}
|
57
|
+
|
58
|
+
|
59
|
+
TEST_IMPL(callback_order) {
|
60
|
+
uv_loop_t* loop;
|
61
|
+
uv_idle_t idle;
|
62
|
+
|
63
|
+
loop = uv_default_loop();
|
64
|
+
uv_idle_init(loop, &idle);
|
65
|
+
uv_idle_start(&idle, next_tick);
|
66
|
+
|
67
|
+
ASSERT(idle_cb_called == 0);
|
68
|
+
ASSERT(timer_cb_called == 0);
|
69
|
+
|
70
|
+
uv_run(loop);
|
71
|
+
|
72
|
+
ASSERT(idle_cb_called == 1);
|
73
|
+
ASSERT(timer_cb_called == 1);
|
74
|
+
|
75
|
+
return 0;
|
76
|
+
}
|
@@ -78,7 +78,7 @@ static void create_dir(uv_loop_t* loop, const char* name) {
|
|
78
78
|
uv_fs_t req;
|
79
79
|
r = uv_fs_rmdir(loop, &req, name, NULL);
|
80
80
|
r = uv_fs_mkdir(loop, &req, name, 0755, NULL);
|
81
|
-
ASSERT(r == 0);
|
81
|
+
ASSERT(r == 0 || uv_last_error(loop).code == UV_EEXIST);
|
82
82
|
uv_fs_req_cleanup(&req);
|
83
83
|
}
|
84
84
|
|
@@ -208,8 +208,7 @@ TEST_IMPL(counters_init) {
|
|
208
208
|
r = uv_fs_event_init(uv_default_loop(), &fs_event, "watch_dir", NULL, 0);
|
209
209
|
ASSERT(r == 0);
|
210
210
|
ASSERT(uv_default_loop()->counters.fs_event_init == ++fs_event_init_prev);
|
211
|
-
|
212
|
-
ASSERT(r == 0);
|
211
|
+
uv_fs_rmdir(uv_default_loop(), &fs_req, "watch_dir", NULL);
|
213
212
|
uv_fs_req_cleanup(&fs_req);
|
214
213
|
|
215
214
|
return 0;
|
@@ -23,8 +23,12 @@
|
|
23
23
|
#include "task.h"
|
24
24
|
#include <string.h>
|
25
25
|
|
26
|
-
|
27
|
-
|
26
|
+
|
27
|
+
TEST_IMPL(dlerror) {
|
28
|
+
const char* path = "test/fixtures/load_error.node";
|
29
|
+
const char* msg;
|
30
|
+
uv_lib_t lib;
|
31
|
+
int r;
|
28
32
|
|
29
33
|
#ifdef __linux__
|
30
34
|
const char* dlerror_desc = "file too short";
|
@@ -36,14 +40,19 @@ const char* msg;
|
|
36
40
|
const char* dlerror_desc = "";
|
37
41
|
#endif
|
38
42
|
|
39
|
-
uv_lib_t lib;
|
40
|
-
uv_err_t r;
|
41
|
-
|
42
|
-
TEST_IMPL(dlerror) {
|
43
43
|
r = uv_dlopen(path, &lib);
|
44
|
-
|
44
|
+
ASSERT(r == -1);
|
45
|
+
|
46
|
+
msg = uv_dlerror(&lib);
|
45
47
|
ASSERT(msg != NULL);
|
46
48
|
ASSERT(strstr(msg, dlerror_desc) != NULL);
|
47
|
-
|
49
|
+
|
50
|
+
/* Should return the same error twice in a row. */
|
51
|
+
msg = uv_dlerror(&lib);
|
52
|
+
ASSERT(msg != NULL);
|
53
|
+
ASSERT(strstr(msg, dlerror_desc) != NULL);
|
54
|
+
|
55
|
+
uv_dlclose(&lib);
|
56
|
+
|
48
57
|
return 0;
|
49
58
|
}
|
@@ -38,6 +38,26 @@ static int close_cb_called = 0;
|
|
38
38
|
static int fs_event_cb_called = 0;
|
39
39
|
static int timer_cb_touch_called = 0;
|
40
40
|
|
41
|
+
static void cleanup_watch_dir() {
|
42
|
+
uv_loop_t* loop = uv_default_loop();
|
43
|
+
uv_fs_t readdir_req;
|
44
|
+
int i, r;
|
45
|
+
char *buffer, *name;
|
46
|
+
|
47
|
+
r = uv_fs_readdir(loop, &readdir_req, "watch_dir", 0, NULL);
|
48
|
+
buffer = readdir_req.ptr;
|
49
|
+
uv_chdir("watch_dir");
|
50
|
+
for (i = 0; i < readdir_req.result; i++) {
|
51
|
+
name = buffer;
|
52
|
+
r = remove(name);
|
53
|
+
ASSERT(r == 0);
|
54
|
+
buffer += strlen(name) + 1;
|
55
|
+
}
|
56
|
+
uv_chdir("..");
|
57
|
+
r = remove("watch_dir");
|
58
|
+
ASSERT(r == 0 || uv_last_error(loop).code == UV_ENOENT);
|
59
|
+
}
|
60
|
+
|
41
61
|
static void create_dir(uv_loop_t* loop, const char* name) {
|
42
62
|
int r;
|
43
63
|
uv_fs_t req;
|
@@ -160,14 +180,11 @@ static void timer_cb_touch(uv_timer_t* timer, int status) {
|
|
160
180
|
}
|
161
181
|
|
162
182
|
TEST_IMPL(fs_event_watch_dir) {
|
163
|
-
uv_fs_t fs_req;
|
164
183
|
uv_loop_t* loop = uv_default_loop();
|
165
184
|
int r;
|
166
185
|
|
167
186
|
/* Setup */
|
168
|
-
|
169
|
-
uv_fs_unlink(loop, &fs_req, "watch_dir/file2", NULL);
|
170
|
-
uv_fs_rmdir(loop, &fs_req, "watch_dir", NULL);
|
187
|
+
cleanup_watch_dir();
|
171
188
|
create_dir(loop, "watch_dir");
|
172
189
|
|
173
190
|
r = uv_fs_event_init(loop, &fs_event, "watch_dir", fs_event_cb_dir, 0);
|
@@ -184,22 +201,15 @@ TEST_IMPL(fs_event_watch_dir) {
|
|
184
201
|
ASSERT(close_cb_called == 2);
|
185
202
|
|
186
203
|
/* Cleanup */
|
187
|
-
|
188
|
-
r = uv_fs_unlink(loop, &fs_req, "watch_dir/file2", NULL);
|
189
|
-
r = uv_fs_rmdir(loop, &fs_req, "watch_dir", NULL);
|
190
|
-
|
204
|
+
cleanup_watch_dir();
|
191
205
|
return 0;
|
192
206
|
}
|
193
207
|
|
194
208
|
TEST_IMPL(fs_event_watch_file) {
|
195
|
-
uv_fs_t fs_req;
|
196
209
|
uv_loop_t* loop = uv_default_loop();
|
197
210
|
int r;
|
198
211
|
|
199
212
|
/* Setup */
|
200
|
-
uv_fs_unlink(loop, &fs_req, "watch_dir/file1", NULL);
|
201
|
-
uv_fs_unlink(loop, &fs_req, "watch_dir/file2", NULL);
|
202
|
-
uv_fs_rmdir(loop, &fs_req, "watch_dir", NULL);
|
203
213
|
create_dir(loop, "watch_dir");
|
204
214
|
create_file(loop, "watch_dir/file1");
|
205
215
|
create_file(loop, "watch_dir/file2");
|
@@ -218,10 +228,7 @@ TEST_IMPL(fs_event_watch_file) {
|
|
218
228
|
ASSERT(close_cb_called == 2);
|
219
229
|
|
220
230
|
/* Cleanup */
|
221
|
-
|
222
|
-
r = uv_fs_unlink(loop, &fs_req, "watch_dir/file2", NULL);
|
223
|
-
r = uv_fs_rmdir(loop, &fs_req, "watch_dir", NULL);
|
224
|
-
|
231
|
+
cleanup_watch_dir();
|
225
232
|
return 0;
|
226
233
|
}
|
227
234
|
|
@@ -264,13 +271,11 @@ TEST_IMPL(fs_event_watch_file_current_dir) {
|
|
264
271
|
|
265
272
|
|
266
273
|
TEST_IMPL(fs_event_no_callback_on_close) {
|
267
|
-
uv_fs_t fs_req;
|
268
274
|
uv_loop_t* loop = uv_default_loop();
|
269
275
|
int r;
|
270
276
|
|
271
277
|
/* Setup */
|
272
|
-
|
273
|
-
uv_fs_rmdir(loop, &fs_req, "watch_dir", NULL);
|
278
|
+
cleanup_watch_dir();
|
274
279
|
create_dir(loop, "watch_dir");
|
275
280
|
create_file(loop, "watch_dir/file1");
|
276
281
|
|
@@ -289,8 +294,7 @@ TEST_IMPL(fs_event_no_callback_on_close) {
|
|
289
294
|
ASSERT(close_cb_called == 1);
|
290
295
|
|
291
296
|
/* Cleanup */
|
292
|
-
|
293
|
-
r = uv_fs_rmdir(loop, &fs_req, "watch_dir", NULL);
|
297
|
+
cleanup_watch_dir();
|
294
298
|
|
295
299
|
return 0;
|
296
300
|
}
|
@@ -338,11 +342,12 @@ TEST_IMPL(fs_event_immediate_close) {
|
|
338
342
|
|
339
343
|
TEST_IMPL(fs_event_close_with_pending_event) {
|
340
344
|
uv_loop_t* loop;
|
341
|
-
uv_fs_t fs_req;
|
342
345
|
int r;
|
343
346
|
|
344
347
|
loop = uv_default_loop();
|
345
348
|
|
349
|
+
cleanup_watch_dir();
|
350
|
+
|
346
351
|
create_dir(loop, "watch_dir");
|
347
352
|
create_file(loop, "watch_dir/file");
|
348
353
|
|
@@ -359,10 +364,7 @@ TEST_IMPL(fs_event_close_with_pending_event) {
|
|
359
364
|
ASSERT(close_cb_called == 1);
|
360
365
|
|
361
366
|
/* Clean up */
|
362
|
-
|
363
|
-
ASSERT(r == 0);
|
364
|
-
r = uv_fs_rmdir(loop, &fs_req, "watch_dir", NULL);
|
365
|
-
ASSERT(r == 0);
|
367
|
+
cleanup_watch_dir();
|
366
368
|
|
367
369
|
return 0;
|
368
370
|
}
|
@@ -395,11 +397,12 @@ static void fs_event_cb_close(uv_fs_event_t* handle, const char* filename,
|
|
395
397
|
|
396
398
|
TEST_IMPL(fs_event_close_in_callback) {
|
397
399
|
uv_loop_t* loop;
|
398
|
-
uv_fs_t fs_req;
|
399
400
|
int r;
|
400
401
|
|
401
402
|
loop = uv_default_loop();
|
402
403
|
|
404
|
+
cleanup_watch_dir();
|
405
|
+
|
403
406
|
create_dir(loop, "watch_dir");
|
404
407
|
create_file(loop, "watch_dir/file1");
|
405
408
|
create_file(loop, "watch_dir/file2");
|
@@ -423,18 +426,7 @@ TEST_IMPL(fs_event_close_in_callback) {
|
|
423
426
|
ASSERT(fs_event_cb_called == 3);
|
424
427
|
|
425
428
|
/* Clean up */
|
426
|
-
|
427
|
-
ASSERT(r == 0);
|
428
|
-
r = uv_fs_unlink(loop, &fs_req, "watch_dir/file2", NULL);
|
429
|
-
ASSERT(r == 0);
|
430
|
-
r = uv_fs_unlink(loop, &fs_req, "watch_dir/file3", NULL);
|
431
|
-
ASSERT(r == 0);
|
432
|
-
r = uv_fs_unlink(loop, &fs_req, "watch_dir/file4", NULL);
|
433
|
-
ASSERT(r == 0);
|
434
|
-
r = uv_fs_unlink(loop, &fs_req, "watch_dir/file5", NULL);
|
435
|
-
ASSERT(r == 0);
|
436
|
-
r = uv_fs_rmdir(loop, &fs_req, "watch_dir", NULL);
|
437
|
-
ASSERT(r == 0);
|
429
|
+
cleanup_watch_dir();
|
438
430
|
|
439
431
|
return 0;
|
440
432
|
}
|