asyncengine 0.0.1.testing1 → 0.0.2.alpha1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
|
Binary file
|
|
@@ -38,11 +38,11 @@ int uv_tty_init(uv_loop_t* loop, uv_tty_t* tty, int fd, int readable) {
|
|
|
38
38
|
|
|
39
39
|
if (readable) {
|
|
40
40
|
uv__nonblock(fd, 1);
|
|
41
|
-
uv__stream_open((uv_stream_t*)tty, fd,
|
|
41
|
+
uv__stream_open((uv_stream_t*)tty, fd, UV_STREAM_READABLE);
|
|
42
42
|
} else {
|
|
43
43
|
/* Note: writable tty we set to blocking mode. */
|
|
44
|
-
uv__stream_open((uv_stream_t*)tty, fd,
|
|
45
|
-
tty->
|
|
44
|
+
uv__stream_open((uv_stream_t*)tty, fd, UV_STREAM_WRITABLE);
|
|
45
|
+
tty->flags |= UV_STREAM_BLOCKING;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
loop->counters.tty_init++;
|
|
Binary file
|
|
@@ -31,63 +31,39 @@
|
|
|
31
31
|
|
|
32
32
|
static void uv__udp_run_completed(uv_udp_t* handle);
|
|
33
33
|
static void uv__udp_run_pending(uv_udp_t* handle);
|
|
34
|
-
static void uv__udp_recvmsg(
|
|
35
|
-
static void uv__udp_sendmsg(
|
|
34
|
+
static void uv__udp_recvmsg(uv_loop_t* loop, uv__io_t* w, int revents);
|
|
35
|
+
static void uv__udp_sendmsg(uv_loop_t* loop, uv__io_t* w, int revents);
|
|
36
36
|
static int uv__udp_maybe_deferred_bind(uv_udp_t* handle, int domain);
|
|
37
37
|
static int uv__udp_send(uv_udp_send_t* req, uv_udp_t* handle, uv_buf_t bufs[],
|
|
38
38
|
int bufcnt, struct sockaddr* addr, socklen_t addrlen, uv_udp_send_cb send_cb);
|
|
39
39
|
|
|
40
40
|
|
|
41
41
|
static void uv__udp_start_watcher(uv_udp_t* handle,
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
int
|
|
45
|
-
if (
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
ev_unref(handle->loop->ev);
|
|
42
|
+
uv__io_t* w,
|
|
43
|
+
uv__io_cb cb,
|
|
44
|
+
int events) {
|
|
45
|
+
if (uv__io_active(w)) return;
|
|
46
|
+
uv__io_init(w, cb, handle->fd, events);
|
|
47
|
+
uv__io_start(handle->loop, w);
|
|
48
|
+
uv__handle_start(handle);
|
|
50
49
|
}
|
|
51
50
|
|
|
52
51
|
|
|
53
|
-
static void uv__udp_stop_watcher(uv_udp_t* handle,
|
|
54
|
-
if (!
|
|
55
|
-
|
|
56
|
-
ev_io_stop(handle->loop->ev, w);
|
|
57
|
-
ev_io_set(w, -1, 0);
|
|
58
|
-
ev_set_cb(w, NULL);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
static void uv__udp_start_read_watcher(uv_udp_t* handle) {
|
|
63
|
-
uv__udp_start_watcher(handle,
|
|
64
|
-
&handle->read_watcher,
|
|
65
|
-
uv__udp_recvmsg,
|
|
66
|
-
EV_READ);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
static void uv__udp_start_write_watcher(uv_udp_t* handle) {
|
|
71
|
-
uv__udp_start_watcher(handle,
|
|
72
|
-
&handle->write_watcher,
|
|
73
|
-
uv__udp_sendmsg,
|
|
74
|
-
EV_WRITE);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
static void uv__udp_stop_read_watcher(uv_udp_t* handle) {
|
|
79
|
-
uv__udp_stop_watcher(handle, &handle->read_watcher);
|
|
80
|
-
}
|
|
81
|
-
|
|
52
|
+
static void uv__udp_stop_watcher(uv_udp_t* handle, uv__io_t* w) {
|
|
53
|
+
if (!uv__io_active(w)) return;
|
|
54
|
+
uv__io_stop(handle->loop, w);
|
|
82
55
|
|
|
83
|
-
|
|
84
|
-
|
|
56
|
+
if (!uv__io_active(&handle->read_watcher) &&
|
|
57
|
+
!uv__io_active(&handle->write_watcher))
|
|
58
|
+
{
|
|
59
|
+
uv__handle_stop(handle);
|
|
60
|
+
}
|
|
85
61
|
}
|
|
86
62
|
|
|
87
63
|
|
|
88
64
|
void uv__udp_close(uv_udp_t* handle) {
|
|
89
|
-
|
|
90
|
-
|
|
65
|
+
uv__udp_stop_watcher(handle, &handle->write_watcher);
|
|
66
|
+
uv__udp_stop_watcher(handle, &handle->read_watcher);
|
|
91
67
|
close(handle->fd);
|
|
92
68
|
handle->fd = -1;
|
|
93
69
|
}
|
|
@@ -97,8 +73,8 @@ void uv__udp_finish_close(uv_udp_t* handle) {
|
|
|
97
73
|
uv_udp_send_t* req;
|
|
98
74
|
ngx_queue_t* q;
|
|
99
75
|
|
|
100
|
-
assert(!
|
|
101
|
-
assert(!
|
|
76
|
+
assert(!uv__io_active(&handle->write_watcher));
|
|
77
|
+
assert(!uv__io_active(&handle->read_watcher));
|
|
102
78
|
assert(handle->fd == -1);
|
|
103
79
|
|
|
104
80
|
uv__udp_run_completed(handle);
|
|
@@ -108,6 +84,8 @@ void uv__udp_finish_close(uv_udp_t* handle) {
|
|
|
108
84
|
ngx_queue_remove(q);
|
|
109
85
|
|
|
110
86
|
req = ngx_queue_data(q, uv_udp_send_t, queue);
|
|
87
|
+
uv__req_unregister(handle->loop, req);
|
|
88
|
+
|
|
111
89
|
if (req->send_cb) {
|
|
112
90
|
/* FIXME proper error code like UV_EABORTED */
|
|
113
91
|
uv__set_artificial_error(handle->loop, UV_EINTR);
|
|
@@ -138,7 +116,8 @@ static void uv__udp_run_pending(uv_udp_t* handle) {
|
|
|
138
116
|
|
|
139
117
|
memset(&h, 0, sizeof h);
|
|
140
118
|
h.msg_name = &req->addr;
|
|
141
|
-
h.msg_namelen = req->
|
|
119
|
+
h.msg_namelen = (req->addr.sin6_family == AF_INET6 ?
|
|
120
|
+
sizeof(struct sockaddr_in6) : sizeof(struct sockaddr_in));
|
|
142
121
|
h.msg_iov = (struct iovec*)req->bufs;
|
|
143
122
|
h.msg_iovlen = req->bufcnt;
|
|
144
123
|
|
|
@@ -185,12 +164,10 @@ static void uv__udp_run_completed(uv_udp_t* handle) {
|
|
|
185
164
|
|
|
186
165
|
while (!ngx_queue_empty(&handle->write_completed_queue)) {
|
|
187
166
|
q = ngx_queue_head(&handle->write_completed_queue);
|
|
188
|
-
assert(q != NULL);
|
|
189
|
-
|
|
190
167
|
ngx_queue_remove(q);
|
|
191
168
|
|
|
192
169
|
req = ngx_queue_data(q, uv_udp_send_t, queue);
|
|
193
|
-
|
|
170
|
+
uv__req_unregister(handle->loop, req);
|
|
194
171
|
|
|
195
172
|
if (req->bufs != req->bufsml)
|
|
196
173
|
free(req->bufs);
|
|
@@ -212,30 +189,36 @@ static void uv__udp_run_completed(uv_udp_t* handle) {
|
|
|
212
189
|
}
|
|
213
190
|
|
|
214
191
|
|
|
215
|
-
static void uv__udp_recvmsg(
|
|
192
|
+
static void uv__udp_recvmsg(uv_loop_t* loop, uv__io_t* w, int revents) {
|
|
216
193
|
struct sockaddr_storage peer;
|
|
217
194
|
struct msghdr h;
|
|
218
195
|
uv_udp_t* handle;
|
|
219
196
|
ssize_t nread;
|
|
220
197
|
uv_buf_t buf;
|
|
221
198
|
int flags;
|
|
199
|
+
int count;
|
|
222
200
|
|
|
223
201
|
handle = container_of(w, uv_udp_t, read_watcher);
|
|
224
202
|
assert(handle->type == UV_UDP);
|
|
225
|
-
assert(revents &
|
|
203
|
+
assert(revents & UV__IO_READ);
|
|
226
204
|
|
|
227
205
|
assert(handle->recv_cb != NULL);
|
|
228
206
|
assert(handle->alloc_cb != NULL);
|
|
229
207
|
|
|
208
|
+
/* Prevent loop starvation when the data comes in as fast as (or faster than)
|
|
209
|
+
* we can read it. XXX Need to rearm fd if we switch to edge-triggered I/O.
|
|
210
|
+
*/
|
|
211
|
+
count = 32;
|
|
212
|
+
|
|
213
|
+
memset(&h, 0, sizeof(h));
|
|
214
|
+
h.msg_name = &peer;
|
|
215
|
+
|
|
230
216
|
do {
|
|
231
|
-
/* FIXME: hoist alloc_cb out the loop but for now follow uv__read() */
|
|
232
217
|
buf = handle->alloc_cb((uv_handle_t*)handle, 64 * 1024);
|
|
233
218
|
assert(buf.len > 0);
|
|
234
219
|
assert(buf.base != NULL);
|
|
235
220
|
|
|
236
|
-
|
|
237
|
-
h.msg_name = &peer;
|
|
238
|
-
h.msg_namelen = sizeof peer;
|
|
221
|
+
h.msg_namelen = sizeof(peer);
|
|
239
222
|
h.msg_iov = (struct iovec*)&buf;
|
|
240
223
|
h.msg_iovlen = 1;
|
|
241
224
|
|
|
@@ -269,17 +252,18 @@ static void uv__udp_recvmsg(EV_P_ ev_io* w, int revents) {
|
|
|
269
252
|
}
|
|
270
253
|
/* recv_cb callback may decide to pause or close the handle */
|
|
271
254
|
while (nread != -1
|
|
255
|
+
&& count-- > 0
|
|
272
256
|
&& handle->fd != -1
|
|
273
257
|
&& handle->recv_cb != NULL);
|
|
274
258
|
}
|
|
275
259
|
|
|
276
260
|
|
|
277
|
-
static void uv__udp_sendmsg(
|
|
261
|
+
static void uv__udp_sendmsg(uv_loop_t* loop, uv__io_t* w, int revents) {
|
|
278
262
|
uv_udp_t* handle;
|
|
279
263
|
|
|
280
264
|
handle = container_of(w, uv_udp_t, write_watcher);
|
|
281
265
|
assert(handle->type == UV_UDP);
|
|
282
|
-
assert(revents &
|
|
266
|
+
assert(revents & UV__IO_WRITE);
|
|
283
267
|
|
|
284
268
|
assert(!ngx_queue_empty(&handle->write_queue)
|
|
285
269
|
|| !ngx_queue_empty(&handle->write_completed_queue));
|
|
@@ -292,11 +276,11 @@ static void uv__udp_sendmsg(EV_P_ ev_io* w, int revents) {
|
|
|
292
276
|
|
|
293
277
|
if (!ngx_queue_empty(&handle->write_completed_queue)) {
|
|
294
278
|
/* Schedule completion callbacks. */
|
|
295
|
-
|
|
279
|
+
uv__io_feed(handle->loop, &handle->write_watcher, UV__IO_WRITE);
|
|
296
280
|
}
|
|
297
281
|
else if (ngx_queue_empty(&handle->write_queue)) {
|
|
298
282
|
/* Pending queue and completion queue empty, stop watcher. */
|
|
299
|
-
|
|
283
|
+
uv__udp_stop_watcher(handle, &handle->write_watcher);
|
|
300
284
|
}
|
|
301
285
|
}
|
|
302
286
|
|
|
@@ -437,14 +421,13 @@ static int uv__udp_send(uv_udp_send_t* req,
|
|
|
437
421
|
if (uv__udp_maybe_deferred_bind(handle, addr->sa_family))
|
|
438
422
|
return -1;
|
|
439
423
|
|
|
440
|
-
uv__req_init(handle->loop,
|
|
424
|
+
uv__req_init(handle->loop, req, UV_UDP_SEND);
|
|
441
425
|
|
|
426
|
+
assert(addrlen <= sizeof(req->addr));
|
|
442
427
|
memcpy(&req->addr, addr, addrlen);
|
|
443
|
-
req->addrlen = addrlen;
|
|
444
428
|
req->send_cb = send_cb;
|
|
445
429
|
req->handle = handle;
|
|
446
430
|
req->bufcnt = bufcnt;
|
|
447
|
-
req->type = UV_UDP_SEND;
|
|
448
431
|
|
|
449
432
|
if (bufcnt <= UV_REQ_BUFSML_SIZE) {
|
|
450
433
|
req->bufs = req->bufsml;
|
|
@@ -456,7 +439,11 @@ static int uv__udp_send(uv_udp_send_t* req,
|
|
|
456
439
|
memcpy(req->bufs, bufs, bufcnt * sizeof(bufs[0]));
|
|
457
440
|
|
|
458
441
|
ngx_queue_insert_tail(&handle->write_queue, &req->queue);
|
|
459
|
-
|
|
442
|
+
|
|
443
|
+
uv__udp_start_watcher(handle,
|
|
444
|
+
&handle->write_watcher,
|
|
445
|
+
uv__udp_sendmsg,
|
|
446
|
+
UV__IO_WRITE);
|
|
460
447
|
|
|
461
448
|
return 0;
|
|
462
449
|
}
|
|
@@ -646,7 +633,7 @@ int uv_udp_recv_start(uv_udp_t* handle,
|
|
|
646
633
|
return -1;
|
|
647
634
|
}
|
|
648
635
|
|
|
649
|
-
if (
|
|
636
|
+
if (uv__io_active(&handle->read_watcher)) {
|
|
650
637
|
uv__set_artificial_error(handle->loop, UV_EALREADY);
|
|
651
638
|
return -1;
|
|
652
639
|
}
|
|
@@ -656,14 +643,18 @@ int uv_udp_recv_start(uv_udp_t* handle,
|
|
|
656
643
|
|
|
657
644
|
handle->alloc_cb = alloc_cb;
|
|
658
645
|
handle->recv_cb = recv_cb;
|
|
659
|
-
|
|
646
|
+
|
|
647
|
+
uv__udp_start_watcher(handle,
|
|
648
|
+
&handle->read_watcher,
|
|
649
|
+
uv__udp_recvmsg,
|
|
650
|
+
UV__IO_READ);
|
|
660
651
|
|
|
661
652
|
return 0;
|
|
662
653
|
}
|
|
663
654
|
|
|
664
655
|
|
|
665
656
|
int uv_udp_recv_stop(uv_udp_t* handle) {
|
|
666
|
-
|
|
657
|
+
uv__udp_stop_watcher(handle, &handle->read_watcher);
|
|
667
658
|
handle->alloc_cb = NULL;
|
|
668
659
|
handle->recv_cb = NULL;
|
|
669
660
|
return 0;
|
|
Binary file
|
|
@@ -22,52 +22,37 @@
|
|
|
22
22
|
|
|
23
23
|
#include "uv.h"
|
|
24
24
|
#include "eio.h"
|
|
25
|
+
#include "internal.h"
|
|
25
26
|
|
|
26
27
|
#include <assert.h>
|
|
27
28
|
#include <stdio.h>
|
|
28
29
|
|
|
29
30
|
|
|
30
|
-
static
|
|
31
|
-
assert(watcher == &(watcher->loop->uv_eio_poller));
|
|
31
|
+
static uv_once_t uv__eio_init_once_guard = UV_ONCE_INIT;
|
|
32
32
|
|
|
33
|
-
/* printf("uv_eio_poller\n"); */
|
|
34
33
|
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
static void uv_eio_do_poll(uv_idle_t* watcher, int status) {
|
|
35
|
+
uv_loop_t* loop = watcher->loop;
|
|
36
|
+
assert(watcher == &loop->uv_eio_poller);
|
|
37
|
+
if (eio_poll(&loop->uv_eio_channel) != -1)
|
|
37
38
|
uv_idle_stop(watcher);
|
|
38
|
-
uv_unref(watcher->loop);
|
|
39
|
-
}
|
|
40
39
|
}
|
|
41
40
|
|
|
42
41
|
|
|
43
42
|
/* Called from the main thread. */
|
|
44
43
|
static void uv_eio_want_poll_notifier_cb(uv_async_t* watcher, int status) {
|
|
45
44
|
uv_loop_t* loop = watcher->loop;
|
|
46
|
-
|
|
47
45
|
assert(watcher == &loop->uv_eio_want_poll_notifier);
|
|
48
|
-
|
|
49
|
-
/* printf("want poll notifier\n"); */
|
|
50
|
-
|
|
51
|
-
if (eio_poll(&watcher->loop->uv_eio_channel) == -1 && !uv_is_active((uv_handle_t*) &loop->uv_eio_poller)) {
|
|
52
|
-
/* printf("uv_eio_poller start\n"); */
|
|
46
|
+
if (eio_poll(&loop->uv_eio_channel) == -1)
|
|
53
47
|
uv_idle_start(&loop->uv_eio_poller, uv_eio_do_poll);
|
|
54
|
-
uv_ref(loop);
|
|
55
|
-
}
|
|
56
48
|
}
|
|
57
49
|
|
|
58
50
|
|
|
59
51
|
static void uv_eio_done_poll_notifier_cb(uv_async_t* watcher, int revents) {
|
|
60
52
|
uv_loop_t* loop = watcher->loop;
|
|
61
|
-
|
|
62
53
|
assert(watcher == &loop->uv_eio_done_poll_notifier);
|
|
63
|
-
|
|
64
|
-
/* printf("done poll notifier\n"); */
|
|
65
|
-
|
|
66
|
-
if (eio_poll(&watcher->loop->uv_eio_channel) != -1 && uv_is_active((uv_handle_t*) &loop->uv_eio_poller)) {
|
|
67
|
-
/* printf("uv_eio_poller stop\n"); */
|
|
54
|
+
if (eio_poll(&loop->uv_eio_channel) != -1)
|
|
68
55
|
uv_idle_stop(&loop->uv_eio_poller);
|
|
69
|
-
uv_unref(loop);
|
|
70
|
-
}
|
|
71
56
|
}
|
|
72
57
|
|
|
73
58
|
|
|
@@ -77,13 +62,8 @@ static void uv_eio_done_poll_notifier_cb(uv_async_t* watcher, int revents) {
|
|
|
77
62
|
*/
|
|
78
63
|
static void uv_eio_want_poll(eio_channel *channel) {
|
|
79
64
|
/* Signal the main thread that eio_poll need to be processed. */
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
* TODO need to select the correct uv_loop_t and async_send to
|
|
83
|
-
* uv_eio_want_poll_notifier.
|
|
84
|
-
*/
|
|
85
|
-
|
|
86
|
-
uv_async_send(&((uv_loop_t *)channel->data)->uv_eio_want_poll_notifier);
|
|
65
|
+
uv_loop_t* loop = channel->data;
|
|
66
|
+
uv_async_send(&loop->uv_eio_want_poll_notifier);
|
|
87
67
|
}
|
|
88
68
|
|
|
89
69
|
|
|
@@ -92,7 +72,8 @@ static void uv_eio_done_poll(eio_channel *channel) {
|
|
|
92
72
|
* Signal the main thread that we should stop calling eio_poll().
|
|
93
73
|
* from the idle watcher.
|
|
94
74
|
*/
|
|
95
|
-
|
|
75
|
+
uv_loop_t* loop = channel->data;
|
|
76
|
+
uv_async_send(&loop->uv_eio_done_poll_notifier);
|
|
96
77
|
}
|
|
97
78
|
|
|
98
79
|
|
|
@@ -100,25 +81,27 @@ static void uv__eio_init(void) {
|
|
|
100
81
|
eio_init(uv_eio_want_poll, uv_eio_done_poll);
|
|
101
82
|
}
|
|
102
83
|
|
|
103
|
-
static uv_once_t uv__eio_init_once_guard = UV_ONCE_INIT;
|
|
104
|
-
|
|
105
84
|
|
|
106
85
|
void uv_eio_init(uv_loop_t* loop) {
|
|
107
|
-
if (loop->counters.eio_init
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
86
|
+
if (loop->counters.eio_init) return;
|
|
87
|
+
loop->counters.eio_init = 1;
|
|
88
|
+
|
|
89
|
+
uv_idle_init(loop, &loop->uv_eio_poller);
|
|
90
|
+
uv_idle_start(&loop->uv_eio_poller, uv_eio_do_poll);
|
|
91
|
+
loop->uv_eio_poller.flags |= UV__HANDLE_INTERNAL;
|
|
92
|
+
|
|
93
|
+
loop->uv_eio_want_poll_notifier.data = loop;
|
|
94
|
+
uv_async_init(loop,
|
|
95
|
+
&loop->uv_eio_want_poll_notifier,
|
|
96
|
+
uv_eio_want_poll_notifier_cb);
|
|
97
|
+
loop->uv_eio_want_poll_notifier.flags |= UV__HANDLE_INTERNAL;
|
|
98
|
+
uv__handle_unref(&loop->uv_eio_want_poll_notifier);
|
|
99
|
+
|
|
100
|
+
uv_async_init(loop,
|
|
101
|
+
&loop->uv_eio_done_poll_notifier,
|
|
102
|
+
uv_eio_done_poll_notifier_cb);
|
|
103
|
+
loop->uv_eio_done_poll_notifier.flags |= UV__HANDLE_INTERNAL;
|
|
104
|
+
uv__handle_unref(&loop->uv_eio_done_poll_notifier);
|
|
105
|
+
|
|
106
|
+
uv_once(&uv__eio_init_once_guard, uv__eio_init);
|
|
124
107
|
}
|
|
Binary file
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
#include "uv.h"
|
|
23
23
|
#include "uv-common.h"
|
|
24
24
|
|
|
25
|
+
#include <stdio.h>
|
|
25
26
|
#include <assert.h>
|
|
26
27
|
#include <stddef.h> /* NULL */
|
|
27
28
|
#include <stdlib.h> /* malloc */
|
|
@@ -87,7 +88,7 @@ size_t uv_strlcat(char* dst, const char* src, size_t size) {
|
|
|
87
88
|
}
|
|
88
89
|
|
|
89
90
|
|
|
90
|
-
uv_buf_t uv_buf_init(char* base,
|
|
91
|
+
uv_buf_t uv_buf_init(char* base, unsigned int len) {
|
|
91
92
|
uv_buf_t buf;
|
|
92
93
|
buf.base = base;
|
|
93
94
|
buf.len = len;
|
|
@@ -199,43 +200,6 @@ int uv_ip6_name(struct sockaddr_in6* src, char* dst, size_t size) {
|
|
|
199
200
|
}
|
|
200
201
|
|
|
201
202
|
|
|
202
|
-
static int cmp_ares_tasks(const uv_ares_task_t* a, const uv_ares_task_t* b) {
|
|
203
|
-
if (a->sock < b->sock) return -1;
|
|
204
|
-
if (a->sock > b->sock) return 1;
|
|
205
|
-
return 0;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
RB_GENERATE_STATIC(uv__ares_tasks, uv_ares_task_s, node, cmp_ares_tasks)
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
/* add ares handle to list */
|
|
213
|
-
void uv_add_ares_handle(uv_loop_t* loop, uv_ares_task_t* handle) {
|
|
214
|
-
assert(loop == handle->loop);
|
|
215
|
-
RB_INSERT(uv__ares_tasks, &loop->uv_ares_handles_, handle);
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
/* find matching ares handle in list */
|
|
220
|
-
uv_ares_task_t* uv_find_ares_handle(uv_loop_t* loop, ares_socket_t sock) {
|
|
221
|
-
uv_ares_task_t handle;
|
|
222
|
-
handle.sock = sock;
|
|
223
|
-
return RB_FIND(uv__ares_tasks, &loop->uv_ares_handles_, &handle);
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
/* remove ares handle in list */
|
|
228
|
-
void uv_remove_ares_handle(uv_ares_task_t* handle) {
|
|
229
|
-
RB_REMOVE(uv__ares_tasks, &handle->loop->uv_ares_handles_, handle);
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
/* Returns 1 if the uv_ares_handles_ list is empty. 0 otherwise. */
|
|
234
|
-
int uv_ares_handles_empty(uv_loop_t* loop) {
|
|
235
|
-
return RB_EMPTY(&loop->uv_ares_handles_);
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
|
|
239
203
|
int uv_tcp_bind(uv_tcp_t* handle, struct sockaddr_in addr) {
|
|
240
204
|
if (handle->type != UV_TCP || addr.sin_family != AF_INET) {
|
|
241
205
|
uv__set_artificial_error(handle->loop, UV_EFAULT);
|
|
@@ -352,3 +316,69 @@ int uv_thread_create(uv_thread_t *tid, void (*entry)(void *arg), void *arg) {
|
|
|
352
316
|
|
|
353
317
|
return 0;
|
|
354
318
|
}
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
void uv_walk(uv_loop_t* loop, uv_walk_cb walk_cb, void* arg) {
|
|
322
|
+
ngx_queue_t* q;
|
|
323
|
+
uv_handle_t* h;
|
|
324
|
+
|
|
325
|
+
ngx_queue_foreach(q, &loop->handle_queue) {
|
|
326
|
+
h = ngx_queue_data(q, uv_handle_t, handle_queue);
|
|
327
|
+
if (h->flags & UV__HANDLE_INTERNAL) continue;
|
|
328
|
+
walk_cb(h, arg);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
|
|
333
|
+
#ifndef NDEBUG
|
|
334
|
+
static void uv__print_handles(uv_loop_t* loop, int only_active) {
|
|
335
|
+
const char* type;
|
|
336
|
+
ngx_queue_t* q;
|
|
337
|
+
uv_handle_t* h;
|
|
338
|
+
|
|
339
|
+
if (loop == NULL)
|
|
340
|
+
loop = uv_default_loop();
|
|
341
|
+
|
|
342
|
+
ngx_queue_foreach(q, &loop->handle_queue) {
|
|
343
|
+
h = ngx_queue_data(q, uv_handle_t, handle_queue);
|
|
344
|
+
|
|
345
|
+
if (only_active && !uv__is_active(h))
|
|
346
|
+
continue;
|
|
347
|
+
|
|
348
|
+
switch (h->type) {
|
|
349
|
+
#define X(uc, lc) case UV_##uc: type = #lc; break;
|
|
350
|
+
UV_HANDLE_TYPE_MAP(X)
|
|
351
|
+
#undef X
|
|
352
|
+
default: type = "<unknown>";
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
fprintf(stderr,
|
|
356
|
+
"[%c%c%c] %-8s %p\n",
|
|
357
|
+
"R-"[!(h->flags & UV__HANDLE_REF)],
|
|
358
|
+
"A-"[!(h->flags & UV__HANDLE_ACTIVE)],
|
|
359
|
+
"I-"[!(h->flags & UV__HANDLE_INTERNAL)],
|
|
360
|
+
type,
|
|
361
|
+
(void*)h);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
|
|
366
|
+
void uv_print_all_handles(uv_loop_t* loop) {
|
|
367
|
+
uv__print_handles(loop, 0);
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
|
|
371
|
+
void uv_print_active_handles(uv_loop_t* loop) {
|
|
372
|
+
uv__print_handles(loop, 1);
|
|
373
|
+
}
|
|
374
|
+
#endif
|
|
375
|
+
|
|
376
|
+
|
|
377
|
+
void uv_ref(uv_handle_t* handle) {
|
|
378
|
+
uv__handle_ref(handle);
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
|
|
382
|
+
void uv_unref(uv_handle_t* handle) {
|
|
383
|
+
uv__handle_unref(handle);
|
|
384
|
+
}
|