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
@@ -24,6 +24,7 @@
|
|
24
24
|
|
25
25
|
#include "uv.h"
|
26
26
|
#include "internal.h"
|
27
|
+
#include "req-inl.h"
|
27
28
|
|
28
29
|
|
29
30
|
/*
|
@@ -77,23 +78,21 @@ static uv_err_code uv_translate_eai_error(int eai_errno) {
|
|
77
78
|
|
78
79
|
/* getaddrinfo worker thread implementation */
|
79
80
|
static DWORD WINAPI getaddrinfo_thread_proc(void* parameter) {
|
80
|
-
uv_getaddrinfo_t*
|
81
|
-
uv_loop_t* loop =
|
81
|
+
uv_getaddrinfo_t* req = (uv_getaddrinfo_t*) parameter;
|
82
|
+
uv_loop_t* loop = req->loop;
|
82
83
|
int ret;
|
83
84
|
|
84
|
-
assert(
|
85
|
+
assert(req != NULL);
|
85
86
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
handle->retcode = ret;
|
87
|
+
/* call OS function on this thread */
|
88
|
+
ret = GetAddrInfoW(req->node,
|
89
|
+
req->service,
|
90
|
+
req->hints,
|
91
|
+
&req->res);
|
92
|
+
req->retcode = ret;
|
93
93
|
|
94
|
-
|
95
|
-
|
96
|
-
}
|
94
|
+
/* post getaddrinfo completed */
|
95
|
+
POST_COMPLETION_FOR_REQ(loop, req);
|
97
96
|
|
98
97
|
return 0;
|
99
98
|
}
|
@@ -108,8 +107,7 @@ static DWORD WINAPI getaddrinfo_thread_proc(void* parameter) {
|
|
108
107
|
* and copy all structs and referenced strings into the one block.
|
109
108
|
* Each size calculation is adjusted to avoid unaligned pointers.
|
110
109
|
*/
|
111
|
-
void uv_process_getaddrinfo_req(uv_loop_t* loop, uv_getaddrinfo_t*
|
112
|
-
uv_req_t* req) {
|
110
|
+
void uv_process_getaddrinfo_req(uv_loop_t* loop, uv_getaddrinfo_t* req) {
|
113
111
|
int addrinfo_len = 0;
|
114
112
|
int name_len = 0;
|
115
113
|
size_t addrinfo_struct_len = ALIGNED_SIZE(sizeof(struct addrinfo));
|
@@ -120,15 +118,15 @@ void uv_process_getaddrinfo_req(uv_loop_t* loop, uv_getaddrinfo_t* handle,
|
|
120
118
|
int status = 0;
|
121
119
|
|
122
120
|
/* release input parameter memory */
|
123
|
-
if (
|
124
|
-
free(
|
125
|
-
|
121
|
+
if (req->alloc != NULL) {
|
122
|
+
free(req->alloc);
|
123
|
+
req->alloc = NULL;
|
126
124
|
}
|
127
125
|
|
128
|
-
if (
|
126
|
+
if (req->retcode == 0) {
|
129
127
|
/* convert addrinfoW to addrinfo */
|
130
128
|
/* first calculate required length */
|
131
|
-
addrinfow_ptr =
|
129
|
+
addrinfow_ptr = req->res;
|
132
130
|
while (addrinfow_ptr != NULL) {
|
133
131
|
addrinfo_len += addrinfo_struct_len +
|
134
132
|
ALIGNED_SIZE(addrinfow_ptr->ai_addrlen);
|
@@ -150,7 +148,7 @@ void uv_process_getaddrinfo_req(uv_loop_t* loop, uv_getaddrinfo_t* handle,
|
|
150
148
|
/* do conversions */
|
151
149
|
if (alloc_ptr != NULL) {
|
152
150
|
cur_ptr = alloc_ptr;
|
153
|
-
addrinfow_ptr =
|
151
|
+
addrinfow_ptr = req->res;
|
154
152
|
|
155
153
|
while (addrinfow_ptr != NULL) {
|
156
154
|
/* copy addrinfo struct data */
|
@@ -206,21 +204,21 @@ void uv_process_getaddrinfo_req(uv_loop_t* loop, uv_getaddrinfo_t* handle,
|
|
206
204
|
}
|
207
205
|
} else {
|
208
206
|
/* GetAddrInfo failed */
|
209
|
-
uv__set_artificial_error(loop, uv_translate_eai_error(
|
207
|
+
uv__set_artificial_error(loop, uv_translate_eai_error(req->retcode));
|
210
208
|
status = -1;
|
211
209
|
}
|
212
210
|
|
213
211
|
/* return memory to system */
|
214
|
-
if (
|
215
|
-
FreeAddrInfoW(
|
216
|
-
|
212
|
+
if (req->res != NULL) {
|
213
|
+
FreeAddrInfoW(req->res);
|
214
|
+
req->res = NULL;
|
217
215
|
}
|
218
216
|
|
219
217
|
complete:
|
220
|
-
|
221
|
-
handle->getaddrinfo_cb(handle, status, (struct addrinfo*)alloc_ptr);
|
218
|
+
uv__req_unregister(loop, req);
|
222
219
|
|
223
|
-
|
220
|
+
/* finally do callback with converted result */
|
221
|
+
req->getaddrinfo_cb(req, status, (struct addrinfo*)alloc_ptr);
|
224
222
|
}
|
225
223
|
|
226
224
|
|
@@ -237,7 +235,7 @@ void uv_freeaddrinfo(struct addrinfo* ai) {
|
|
237
235
|
/*
|
238
236
|
* Entry point for getaddrinfo
|
239
237
|
* we convert the UTF-8 strings to UNICODE
|
240
|
-
* and save the UNICODE string pointers in the
|
238
|
+
* and save the UNICODE string pointers in the req
|
241
239
|
* We also copy hints so that caller does not need to keep memory until the
|
242
240
|
* callback.
|
243
241
|
* return UV_OK if a callback will be made
|
@@ -248,7 +246,7 @@ void uv_freeaddrinfo(struct addrinfo* ai) {
|
|
248
246
|
* Each size calculation is adjusted to avoid unaligned pointers.
|
249
247
|
*/
|
250
248
|
int uv_getaddrinfo(uv_loop_t* loop,
|
251
|
-
uv_getaddrinfo_t*
|
249
|
+
uv_getaddrinfo_t* req,
|
252
250
|
uv_getaddrinfo_cb getaddrinfo_cb,
|
253
251
|
const char* node,
|
254
252
|
const char* service,
|
@@ -258,18 +256,18 @@ int uv_getaddrinfo(uv_loop_t* loop,
|
|
258
256
|
int hintssize = 0;
|
259
257
|
char* alloc_ptr = NULL;
|
260
258
|
|
261
|
-
if (
|
259
|
+
if (req == NULL || getaddrinfo_cb == NULL ||
|
262
260
|
(node == NULL && service == NULL)) {
|
263
261
|
uv__set_sys_error(loop, WSAEINVAL);
|
264
262
|
goto error;
|
265
263
|
}
|
266
264
|
|
267
|
-
uv_req_init(loop, (uv_req_t*)
|
265
|
+
uv_req_init(loop, (uv_req_t*)req);
|
268
266
|
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
267
|
+
req->getaddrinfo_cb = getaddrinfo_cb;
|
268
|
+
req->res = NULL;
|
269
|
+
req->type = UV_GETADDRINFO;
|
270
|
+
req->loop = loop;
|
273
271
|
|
274
272
|
/* calculate required memory size for all input values */
|
275
273
|
if (node != NULL) {
|
@@ -300,12 +298,12 @@ int uv_getaddrinfo(uv_loop_t* loop,
|
|
300
298
|
}
|
301
299
|
|
302
300
|
/* save alloc_ptr now so we can free if error */
|
303
|
-
|
301
|
+
req->alloc = (void*)alloc_ptr;
|
304
302
|
|
305
303
|
/* convert node string to UTF16 into allocated memory and save pointer in */
|
306
|
-
/*
|
304
|
+
/* the reques. */
|
307
305
|
if (node != NULL) {
|
308
|
-
|
306
|
+
req->node = (wchar_t*)alloc_ptr;
|
309
307
|
if (uv_utf8_to_utf16(node,
|
310
308
|
(wchar_t*) alloc_ptr,
|
311
309
|
nodesize / sizeof(wchar_t)) == 0) {
|
@@ -314,13 +312,13 @@ int uv_getaddrinfo(uv_loop_t* loop,
|
|
314
312
|
}
|
315
313
|
alloc_ptr += nodesize;
|
316
314
|
} else {
|
317
|
-
|
315
|
+
req->node = NULL;
|
318
316
|
}
|
319
317
|
|
320
318
|
/* convert service string to UTF16 into allocated memory and save pointer */
|
321
|
-
/* in
|
319
|
+
/* in the req. */
|
322
320
|
if (service != NULL) {
|
323
|
-
|
321
|
+
req->service = (wchar_t*)alloc_ptr;
|
324
322
|
if (uv_utf8_to_utf16(service,
|
325
323
|
(wchar_t*) alloc_ptr,
|
326
324
|
servicesize / sizeof(wchar_t)) == 0) {
|
@@ -329,44 +327,39 @@ int uv_getaddrinfo(uv_loop_t* loop,
|
|
329
327
|
}
|
330
328
|
alloc_ptr += servicesize;
|
331
329
|
} else {
|
332
|
-
|
330
|
+
req->service = NULL;
|
333
331
|
}
|
334
332
|
|
335
|
-
/* copy hints to allocated memory and save pointer in
|
333
|
+
/* copy hints to allocated memory and save pointer in req */
|
336
334
|
if (hints != NULL) {
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
335
|
+
req->hints = (struct addrinfoW*)alloc_ptr;
|
336
|
+
req->hints->ai_family = hints->ai_family;
|
337
|
+
req->hints->ai_socktype = hints->ai_socktype;
|
338
|
+
req->hints->ai_protocol = hints->ai_protocol;
|
339
|
+
req->hints->ai_flags = hints->ai_flags;
|
340
|
+
req->hints->ai_addrlen = 0;
|
341
|
+
req->hints->ai_canonname = NULL;
|
342
|
+
req->hints->ai_addr = NULL;
|
343
|
+
req->hints->ai_next = NULL;
|
346
344
|
} else {
|
347
|
-
|
345
|
+
req->hints = NULL;
|
348
346
|
}
|
349
347
|
|
350
|
-
/* init request for Post handling */
|
351
|
-
uv_req_init(loop, &handle->getadddrinfo_req);
|
352
|
-
handle->getadddrinfo_req.data = handle;
|
353
|
-
handle->getadddrinfo_req.type = UV_GETADDRINFO_REQ;
|
354
|
-
|
355
348
|
/* Ask thread to run. Treat this as a long operation */
|
356
349
|
if (QueueUserWorkItem(&getaddrinfo_thread_proc,
|
357
|
-
|
350
|
+
req,
|
358
351
|
WT_EXECUTELONGFUNCTION) == 0) {
|
359
352
|
uv__set_sys_error(loop, GetLastError());
|
360
353
|
goto error;
|
361
354
|
}
|
362
355
|
|
363
|
-
|
356
|
+
uv__req_register(loop, req);
|
364
357
|
|
365
358
|
return 0;
|
366
359
|
|
367
360
|
error:
|
368
|
-
if (
|
369
|
-
free(
|
361
|
+
if (req != NULL && req->alloc != NULL) {
|
362
|
+
free(req->alloc);
|
370
363
|
}
|
371
364
|
return -1;
|
372
365
|
}
|
@@ -0,0 +1,145 @@
|
|
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
|
+
#ifndef UV_WIN_HANDLE_INL_H_
|
23
|
+
#define UV_WIN_HANDLE_INL_H_
|
24
|
+
|
25
|
+
#include <assert.h>
|
26
|
+
|
27
|
+
#include "uv.h"
|
28
|
+
#include "internal.h"
|
29
|
+
|
30
|
+
|
31
|
+
#define DECREASE_ACTIVE_COUNT(loop, handle) \
|
32
|
+
do { \
|
33
|
+
if (--(handle)->activecnt == 0 && \
|
34
|
+
!((handle)->flags & UV_HANDLE_CLOSING)) { \
|
35
|
+
uv__handle_stop((handle)); \
|
36
|
+
} \
|
37
|
+
assert((handle)->activecnt >= 0); \
|
38
|
+
} while (0)
|
39
|
+
|
40
|
+
|
41
|
+
#define INCREASE_ACTIVE_COUNT(loop, handle) \
|
42
|
+
do { \
|
43
|
+
if ((handle)->activecnt++ == 0) { \
|
44
|
+
uv__handle_start((handle)); \
|
45
|
+
} \
|
46
|
+
assert((handle)->activecnt > 0); \
|
47
|
+
} while (0)
|
48
|
+
|
49
|
+
|
50
|
+
#define DECREASE_PENDING_REQ_COUNT(handle) \
|
51
|
+
do { \
|
52
|
+
assert(handle->reqs_pending > 0); \
|
53
|
+
handle->reqs_pending--; \
|
54
|
+
\
|
55
|
+
if (handle->flags & UV_HANDLE_CLOSING && \
|
56
|
+
handle->reqs_pending == 0) { \
|
57
|
+
uv_want_endgame(loop, (uv_handle_t*)handle); \
|
58
|
+
} \
|
59
|
+
} while (0)
|
60
|
+
|
61
|
+
|
62
|
+
#define uv__handle_close(handle) \
|
63
|
+
do { \
|
64
|
+
ngx_queue_remove(&(handle)->handle_queue); \
|
65
|
+
(handle)->flags |= UV_HANDLE_CLOSED; \
|
66
|
+
if ((handle)->close_cb) { \
|
67
|
+
(handle)->close_cb((uv_handle_t*)(handle)); \
|
68
|
+
} \
|
69
|
+
} while (0)
|
70
|
+
|
71
|
+
|
72
|
+
INLINE static void uv_want_endgame(uv_loop_t* loop, uv_handle_t* handle) {
|
73
|
+
if (!(handle->flags & UV_HANDLE_ENDGAME_QUEUED)) {
|
74
|
+
handle->flags |= UV_HANDLE_ENDGAME_QUEUED;
|
75
|
+
|
76
|
+
handle->endgame_next = loop->endgame_handles;
|
77
|
+
loop->endgame_handles = handle;
|
78
|
+
}
|
79
|
+
}
|
80
|
+
|
81
|
+
|
82
|
+
INLINE static void uv_process_endgames(uv_loop_t* loop) {
|
83
|
+
uv_handle_t* handle;
|
84
|
+
|
85
|
+
while (loop->endgame_handles) {
|
86
|
+
handle = loop->endgame_handles;
|
87
|
+
loop->endgame_handles = handle->endgame_next;
|
88
|
+
|
89
|
+
handle->flags &= ~UV_HANDLE_ENDGAME_QUEUED;
|
90
|
+
|
91
|
+
switch (handle->type) {
|
92
|
+
case UV_TCP:
|
93
|
+
uv_tcp_endgame(loop, (uv_tcp_t*) handle);
|
94
|
+
break;
|
95
|
+
|
96
|
+
case UV_NAMED_PIPE:
|
97
|
+
uv_pipe_endgame(loop, (uv_pipe_t*) handle);
|
98
|
+
break;
|
99
|
+
|
100
|
+
case UV_TTY:
|
101
|
+
uv_tty_endgame(loop, (uv_tty_t*) handle);
|
102
|
+
break;
|
103
|
+
|
104
|
+
case UV_UDP:
|
105
|
+
uv_udp_endgame(loop, (uv_udp_t*) handle);
|
106
|
+
break;
|
107
|
+
|
108
|
+
case UV_POLL:
|
109
|
+
uv_poll_endgame(loop, (uv_poll_t*) handle);
|
110
|
+
break;
|
111
|
+
|
112
|
+
case UV_TIMER:
|
113
|
+
uv_timer_endgame(loop, (uv_timer_t*) handle);
|
114
|
+
break;
|
115
|
+
|
116
|
+
case UV_PREPARE:
|
117
|
+
case UV_CHECK:
|
118
|
+
case UV_IDLE:
|
119
|
+
uv_loop_watcher_endgame(loop, handle);
|
120
|
+
break;
|
121
|
+
|
122
|
+
case UV_ASYNC:
|
123
|
+
uv_async_endgame(loop, (uv_async_t*) handle);
|
124
|
+
break;
|
125
|
+
|
126
|
+
case UV_PROCESS:
|
127
|
+
uv_process_endgame(loop, (uv_process_t*) handle);
|
128
|
+
break;
|
129
|
+
|
130
|
+
case UV_FS_EVENT:
|
131
|
+
uv_fs_event_endgame(loop, (uv_fs_event_t*) handle);
|
132
|
+
break;
|
133
|
+
|
134
|
+
case UV_FS_POLL:
|
135
|
+
uv__fs_poll_endgame(loop, (uv_fs_poll_t*) handle);
|
136
|
+
break;
|
137
|
+
|
138
|
+
default:
|
139
|
+
assert(0);
|
140
|
+
break;
|
141
|
+
}
|
142
|
+
}
|
143
|
+
}
|
144
|
+
|
145
|
+
#endif /* UV_WIN_HANDLE_INL_H_ */
|
@@ -24,6 +24,7 @@
|
|
24
24
|
|
25
25
|
#include "uv.h"
|
26
26
|
#include "internal.h"
|
27
|
+
#include "handle-inl.h"
|
27
28
|
|
28
29
|
|
29
30
|
uv_handle_type uv_guess_handle(uv_file file) {
|
@@ -56,28 +57,17 @@ uv_handle_type uv_guess_handle(uv_file file) {
|
|
56
57
|
}
|
57
58
|
|
58
59
|
|
59
|
-
int uv_is_active(uv_handle_t* handle) {
|
60
|
-
|
61
|
-
|
62
|
-
case UV_IDLE:
|
63
|
-
case UV_PREPARE:
|
64
|
-
case UV_CHECK:
|
65
|
-
return (handle->flags & UV_HANDLE_ACTIVE) ? 1 : 0;
|
66
|
-
|
67
|
-
default:
|
68
|
-
return 1;
|
69
|
-
}
|
60
|
+
int uv_is_active(const uv_handle_t* handle) {
|
61
|
+
return (handle->flags & UV__HANDLE_ACTIVE) &&
|
62
|
+
!(handle->flags & UV_HANDLE_CLOSING);
|
70
63
|
}
|
71
64
|
|
72
65
|
|
73
66
|
void uv_close(uv_handle_t* handle, uv_close_cb cb) {
|
74
|
-
uv_pipe_t* pipe;
|
75
|
-
uv_udp_t* udp;
|
76
|
-
uv_process_t* process;
|
77
|
-
|
78
67
|
uv_loop_t* loop = handle->loop;
|
79
68
|
|
80
69
|
if (handle->flags & UV_HANDLE_CLOSING) {
|
70
|
+
assert(0);
|
81
71
|
return;
|
82
72
|
}
|
83
73
|
|
@@ -87,16 +77,11 @@ void uv_close(uv_handle_t* handle, uv_close_cb cb) {
|
|
87
77
|
/* Handle-specific close actions */
|
88
78
|
switch (handle->type) {
|
89
79
|
case UV_TCP:
|
90
|
-
uv_tcp_close((uv_tcp_t*)handle);
|
80
|
+
uv_tcp_close(loop, (uv_tcp_t*)handle);
|
91
81
|
return;
|
92
82
|
|
93
83
|
case UV_NAMED_PIPE:
|
94
|
-
|
95
|
-
pipe->flags &= ~(UV_HANDLE_READING | UV_HANDLE_LISTENING);
|
96
|
-
close_pipe(pipe, NULL, NULL);
|
97
|
-
if (pipe->reqs_pending == 0) {
|
98
|
-
uv_want_endgame(loop, handle);
|
99
|
-
}
|
84
|
+
uv_pipe_close(loop, (uv_pipe_t*) handle);
|
100
85
|
return;
|
101
86
|
|
102
87
|
case UV_TTY:
|
@@ -104,47 +89,53 @@ void uv_close(uv_handle_t* handle, uv_close_cb cb) {
|
|
104
89
|
return;
|
105
90
|
|
106
91
|
case UV_UDP:
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
}
|
92
|
+
uv_udp_close(loop, (uv_udp_t*) handle);
|
93
|
+
return;
|
94
|
+
|
95
|
+
case UV_POLL:
|
96
|
+
uv_poll_close(loop, (uv_poll_t*) handle);
|
113
97
|
return;
|
114
98
|
|
115
99
|
case UV_TIMER:
|
116
100
|
uv_timer_stop((uv_timer_t*)handle);
|
101
|
+
uv__handle_start(handle);
|
117
102
|
uv_want_endgame(loop, handle);
|
118
103
|
return;
|
119
104
|
|
120
105
|
case UV_PREPARE:
|
121
106
|
uv_prepare_stop((uv_prepare_t*)handle);
|
107
|
+
uv__handle_start(handle);
|
122
108
|
uv_want_endgame(loop, handle);
|
123
109
|
return;
|
124
110
|
|
125
111
|
case UV_CHECK:
|
126
112
|
uv_check_stop((uv_check_t*)handle);
|
113
|
+
uv__handle_start(handle);
|
127
114
|
uv_want_endgame(loop, handle);
|
128
115
|
return;
|
129
116
|
|
130
117
|
case UV_IDLE:
|
131
118
|
uv_idle_stop((uv_idle_t*)handle);
|
119
|
+
uv__handle_start(handle);
|
132
120
|
uv_want_endgame(loop, handle);
|
133
121
|
return;
|
134
122
|
|
135
123
|
case UV_ASYNC:
|
136
|
-
|
137
|
-
uv_want_endgame(loop, handle);
|
138
|
-
}
|
124
|
+
uv_async_close(loop, (uv_async_t*) handle);
|
139
125
|
return;
|
140
126
|
|
141
127
|
case UV_PROCESS:
|
142
|
-
|
143
|
-
uv_process_close(loop, process);
|
128
|
+
uv_process_close(loop, (uv_process_t*) handle);
|
144
129
|
return;
|
145
130
|
|
146
131
|
case UV_FS_EVENT:
|
147
|
-
uv_fs_event_close(loop, (uv_fs_event_t*)handle);
|
132
|
+
uv_fs_event_close(loop, (uv_fs_event_t*) handle);
|
133
|
+
return;
|
134
|
+
|
135
|
+
case UV_FS_POLL:
|
136
|
+
uv__fs_poll_close((uv_fs_poll_t*) handle);
|
137
|
+
uv__handle_start(handle);
|
138
|
+
uv_want_endgame(loop, handle);
|
148
139
|
return;
|
149
140
|
|
150
141
|
default:
|
@@ -154,72 +145,6 @@ void uv_close(uv_handle_t* handle, uv_close_cb cb) {
|
|
154
145
|
}
|
155
146
|
|
156
147
|
|
157
|
-
int uv_is_closing(uv_handle_t* handle) {
|
148
|
+
int uv_is_closing(const uv_handle_t* handle) {
|
158
149
|
return handle->flags & (UV_HANDLE_CLOSING | UV_HANDLE_CLOSED);
|
159
150
|
}
|
160
|
-
|
161
|
-
|
162
|
-
void uv_want_endgame(uv_loop_t* loop, uv_handle_t* handle) {
|
163
|
-
if (!(handle->flags & UV_HANDLE_ENDGAME_QUEUED)) {
|
164
|
-
handle->flags |= UV_HANDLE_ENDGAME_QUEUED;
|
165
|
-
|
166
|
-
handle->endgame_next = loop->endgame_handles;
|
167
|
-
loop->endgame_handles = handle;
|
168
|
-
}
|
169
|
-
}
|
170
|
-
|
171
|
-
|
172
|
-
void uv_process_endgames(uv_loop_t* loop) {
|
173
|
-
uv_handle_t* handle;
|
174
|
-
|
175
|
-
while (loop->endgame_handles && loop->refs > 0) {
|
176
|
-
handle = loop->endgame_handles;
|
177
|
-
loop->endgame_handles = handle->endgame_next;
|
178
|
-
|
179
|
-
handle->flags &= ~UV_HANDLE_ENDGAME_QUEUED;
|
180
|
-
|
181
|
-
switch (handle->type) {
|
182
|
-
case UV_TCP:
|
183
|
-
uv_tcp_endgame(loop, (uv_tcp_t*) handle);
|
184
|
-
break;
|
185
|
-
|
186
|
-
case UV_NAMED_PIPE:
|
187
|
-
uv_pipe_endgame(loop, (uv_pipe_t*) handle);
|
188
|
-
break;
|
189
|
-
|
190
|
-
case UV_TTY:
|
191
|
-
uv_tty_endgame(loop, (uv_tty_t*) handle);
|
192
|
-
break;
|
193
|
-
|
194
|
-
case UV_UDP:
|
195
|
-
uv_udp_endgame(loop, (uv_udp_t*) handle);
|
196
|
-
break;
|
197
|
-
|
198
|
-
case UV_TIMER:
|
199
|
-
uv_timer_endgame(loop, (uv_timer_t*) handle);
|
200
|
-
break;
|
201
|
-
|
202
|
-
case UV_PREPARE:
|
203
|
-
case UV_CHECK:
|
204
|
-
case UV_IDLE:
|
205
|
-
uv_loop_watcher_endgame(loop, handle);
|
206
|
-
break;
|
207
|
-
|
208
|
-
case UV_ASYNC:
|
209
|
-
uv_async_endgame(loop, (uv_async_t*) handle);
|
210
|
-
break;
|
211
|
-
|
212
|
-
case UV_PROCESS:
|
213
|
-
uv_process_endgame(loop, (uv_process_t*) handle);
|
214
|
-
break;
|
215
|
-
|
216
|
-
case UV_FS_EVENT:
|
217
|
-
uv_fs_event_endgame(loop, (uv_fs_event_t*) handle);
|
218
|
-
break;
|
219
|
-
|
220
|
-
default:
|
221
|
-
assert(0);
|
222
|
-
break;
|
223
|
-
}
|
224
|
-
}
|
225
|
-
}
|