visaljs 0.0.3 → 0.0.5
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.
- package/README.md +3 -1
- package/cli.js +155 -27
- package/node/include/js_node.h +2 -0
- package/node/prelude/async_hooks.js +0 -0
- package/node/prelude/buffer.js +0 -0
- package/node/prelude/events.js +0 -0
- package/node/prelude/fs.js +0 -0
- package/node/prelude/http2.js +0 -0
- package/node/prelude/internal/crypto/asym.js +0 -0
- package/node/prelude/internal/crypto/cipher.js +0 -0
- package/node/prelude/internal/crypto/kdf.js +0 -0
- package/node/prelude/internal/crypto/keys.js +0 -0
- package/node/prelude/internal/crypto/random.js +0 -0
- package/node/prelude/internal/crypto/util.js +0 -0
- package/node/prelude/internal/errors.js +0 -0
- package/node/prelude/internal/querystring.js +0 -0
- package/node/prelude/internal/tls/wrap.js +5 -2
- package/node/prelude/module.js +0 -0
- package/node/prelude/net.js +1 -2
- package/node/prelude/os.js +2 -2
- package/node/prelude/path.js +0 -0
- package/node/prelude/process.js +0 -0
- package/node/prelude/querystring.js +0 -0
- package/node/prelude/stream.js +0 -0
- package/node/prelude/stream_promises.js +0 -0
- package/node/prelude/stream_web.js +0 -0
- package/node/prelude/string_decoder.js +0 -0
- package/node/prelude/tty.js +0 -0
- package/node/prelude/url.js +0 -0
- package/node/prelude/util.js +0 -0
- package/node/prelude/zlib.js +0 -0
- package/node/src/host_fs.c +10 -2
- package/node/src/host_os.c +0 -0
- package/node/src/host_sys.c +44 -32
- package/node/third_party/libuv/LICENSE +0 -0
- package/node/third_party/libuv/include/uv/aix.h +0 -0
- package/node/third_party/libuv/include/uv/bsd.h +0 -0
- package/node/third_party/libuv/include/uv/darwin.h +0 -0
- package/node/third_party/libuv/include/uv/errno.h +0 -0
- package/node/third_party/libuv/include/uv/linux.h +0 -0
- package/node/third_party/libuv/include/uv/os390.h +0 -0
- package/node/third_party/libuv/include/uv/posix.h +0 -0
- package/node/third_party/libuv/include/uv/sunos.h +0 -0
- package/node/third_party/libuv/include/uv/threadpool.h +0 -0
- package/node/third_party/libuv/include/uv/tree.h +0 -0
- package/node/third_party/libuv/include/uv/unix.h +0 -0
- package/node/third_party/libuv/include/uv/version.h +0 -0
- package/node/third_party/libuv/include/uv/win.h +0 -0
- package/node/third_party/libuv/include/uv.h +0 -0
- package/node/third_party/libuv/src/fs-poll.c +0 -0
- package/node/third_party/libuv/src/heap-inl.h +0 -0
- package/node/third_party/libuv/src/idna.c +0 -0
- package/node/third_party/libuv/src/idna.h +0 -0
- package/node/third_party/libuv/src/inet.c +0 -0
- package/node/third_party/libuv/src/queue.h +0 -0
- package/node/third_party/libuv/src/random.c +0 -0
- package/node/third_party/libuv/src/strscpy.c +0 -0
- package/node/third_party/libuv/src/strscpy.h +0 -0
- package/node/third_party/libuv/src/strtok.c +0 -0
- package/node/third_party/libuv/src/strtok.h +0 -0
- package/node/third_party/libuv/src/thread-common.c +0 -0
- package/node/third_party/libuv/src/threadpool.c +0 -0
- package/node/third_party/libuv/src/timer.c +0 -0
- package/node/third_party/libuv/src/unix/async.c +0 -0
- package/node/third_party/libuv/src/unix/bsd-ifaddrs.c +0 -0
- package/node/third_party/libuv/src/unix/core.c +0 -0
- package/node/third_party/libuv/src/unix/darwin-proctitle.c +0 -0
- package/node/third_party/libuv/src/unix/darwin-stub.h +0 -0
- package/node/third_party/libuv/src/unix/darwin-syscalls.h +0 -0
- package/node/third_party/libuv/src/unix/darwin.c +0 -0
- package/node/third_party/libuv/src/unix/dl.c +0 -0
- package/node/third_party/libuv/src/unix/fs.c +0 -0
- package/node/third_party/libuv/src/unix/fsevents.c +0 -0
- package/node/third_party/libuv/src/unix/getaddrinfo.c +0 -0
- package/node/third_party/libuv/src/unix/getnameinfo.c +0 -0
- package/node/third_party/libuv/src/unix/internal.h +0 -0
- package/node/third_party/libuv/src/unix/kqueue.c +0 -0
- package/node/third_party/libuv/src/unix/linux.c +0 -0
- package/node/third_party/libuv/src/unix/loop-watcher.c +0 -0
- package/node/third_party/libuv/src/unix/loop.c +0 -0
- package/node/third_party/libuv/src/unix/pipe.c +0 -0
- package/node/third_party/libuv/src/unix/poll.c +0 -0
- package/node/third_party/libuv/src/unix/process.c +0 -0
- package/node/third_party/libuv/src/unix/procfs-exepath.c +0 -0
- package/node/third_party/libuv/src/unix/proctitle.c +0 -0
- package/node/third_party/libuv/src/unix/random-devurandom.c +0 -0
- package/node/third_party/libuv/src/unix/random-getentropy.c +0 -0
- package/node/third_party/libuv/src/unix/random-getrandom.c +0 -0
- package/node/third_party/libuv/src/unix/random-sysctl-linux.c +0 -0
- package/node/third_party/libuv/src/unix/signal.c +0 -0
- package/node/third_party/libuv/src/unix/stream.c +0 -0
- package/node/third_party/libuv/src/unix/tcp.c +0 -0
- package/node/third_party/libuv/src/unix/thread.c +0 -0
- package/node/third_party/libuv/src/unix/tty.c +0 -0
- package/node/third_party/libuv/src/unix/udp.c +0 -0
- package/node/third_party/libuv/src/uv-common.c +0 -0
- package/node/third_party/libuv/src/uv-common.h +0 -0
- package/node/third_party/libuv/src/uv-data-getter-setters.c +0 -0
- package/node/third_party/libuv/src/version.c +0 -0
- package/node/third_party/libuv/src/win/async.c +98 -0
- package/node/third_party/libuv/src/win/atomicops-inl.h +61 -0
- package/node/third_party/libuv/src/win/core.c +683 -0
- package/node/third_party/libuv/src/win/detect-wakeup.c +56 -0
- package/node/third_party/libuv/src/win/dl.c +135 -0
- package/node/third_party/libuv/src/win/error.c +183 -0
- package/node/third_party/libuv/src/win/fs-event.c +620 -0
- package/node/third_party/libuv/src/win/fs-fd-hash-inl.h +200 -0
- package/node/third_party/libuv/src/win/fs.c +3774 -0
- package/node/third_party/libuv/src/win/getaddrinfo.c +388 -0
- package/node/third_party/libuv/src/win/getnameinfo.c +146 -0
- package/node/third_party/libuv/src/win/handle-inl.h +180 -0
- package/node/third_party/libuv/src/win/handle.c +162 -0
- package/node/third_party/libuv/src/win/internal.h +335 -0
- package/node/third_party/libuv/src/win/loop-watcher.c +122 -0
- package/node/third_party/libuv/src/win/pipe.c +2725 -0
- package/node/third_party/libuv/src/win/poll.c +586 -0
- package/node/third_party/libuv/src/win/process-stdio.c +419 -0
- package/node/third_party/libuv/src/win/process.c +1407 -0
- package/node/third_party/libuv/src/win/req-inl.h +214 -0
- package/node/third_party/libuv/src/win/signal.c +282 -0
- package/node/third_party/libuv/src/win/snprintf.c +42 -0
- package/node/third_party/libuv/src/win/stream-inl.h +54 -0
- package/node/third_party/libuv/src/win/stream.c +252 -0
- package/node/third_party/libuv/src/win/tcp.c +1674 -0
- package/node/third_party/libuv/src/win/thread.c +568 -0
- package/node/third_party/libuv/src/win/tty.c +2460 -0
- package/node/third_party/libuv/src/win/udp.c +1162 -0
- package/node/third_party/libuv/src/win/util.c +1750 -0
- package/node/third_party/libuv/src/win/winapi.c +144 -0
- package/node/third_party/libuv/src/win/winapi.h +4831 -0
- package/node/third_party/libuv/src/win/winsock.c +575 -0
- package/node/third_party/libuv/src/win/winsock.h +160 -0
- package/node/third_party/llhttp/LICENSE +0 -0
- package/node/third_party/llhttp/api.c +0 -0
- package/node/third_party/llhttp/http.c +0 -0
- package/node/third_party/llhttp/llhttp.c +0 -0
- package/node/third_party/llhttp/llhttp.h +0 -0
- package/package.json +3 -2
- package/runtime/include/js_atoms.gen.h +0 -0
- package/runtime/include/js_atoms.h +0 -0
- package/runtime/include/js_bigint.h +0 -0
- package/runtime/include/js_buffer.h +0 -0
- package/runtime/include/js_builtins.h +0 -0
- package/runtime/include/js_console.h +0 -0
- package/runtime/include/js_convert.h +0 -0
- package/runtime/include/js_core.def +0 -0
- package/runtime/include/js_error.h +0 -0
- package/runtime/include/js_exception.h +0 -0
- package/runtime/include/js_function.h +0 -0
- package/runtime/include/js_gc.h +0 -0
- package/runtime/include/js_generator.h +0 -0
- package/runtime/include/js_host.h +0 -0
- package/runtime/include/js_jobs.h +0 -0
- package/runtime/include/js_module.h +0 -0
- package/runtime/include/js_object.h +0 -0
- package/runtime/include/js_ops.h +0 -0
- package/runtime/include/js_promise.h +0 -0
- package/runtime/include/js_regexp.h +0 -0
- package/runtime/include/js_runtime.h +0 -0
- package/runtime/include/js_symbol.h +0 -0
- package/runtime/include/js_web.h +0 -0
- package/runtime/include/jscell.h +0 -0
- package/runtime/include/jscontext.h +0 -0
- package/runtime/include/jsnum.h +0 -0
- package/runtime/include/jsstring.h +0 -0
- package/runtime/include/jsvalue.h +0 -0
- package/runtime/src/arguments.c +0 -0
- package/runtime/src/array.c +0 -0
- package/runtime/src/arraybuffer.c +0 -0
- package/runtime/src/async_iter.c +0 -0
- package/runtime/src/atoms.c +0 -0
- package/runtime/src/base64.c +0 -0
- package/runtime/src/bigint.c +0 -0
- package/runtime/src/blob.c +0 -0
- package/runtime/src/boringssl_support.cc +4 -1
- package/runtime/src/buffer.c +0 -0
- package/runtime/src/builtin_table.c +0 -0
- package/runtime/src/builtins.c +0 -0
- package/runtime/src/builtins_util.h +0 -0
- package/runtime/src/collections.c +0 -0
- package/runtime/src/components.c +0 -0
- package/runtime/src/console.c +0 -0
- package/runtime/src/convert.c +0 -0
- package/runtime/src/core_all.c +0 -0
- package/runtime/src/crypto.c +0 -0
- package/runtime/src/crypto_host.c +0 -0
- package/runtime/src/crypto_kdf.c +0 -0
- package/runtime/src/crypto_key.c +0 -0
- package/runtime/src/date.c +0 -0
- package/runtime/src/domexception.c +0 -0
- package/runtime/src/elements.c +0 -0
- package/runtime/src/elements.h +0 -0
- package/runtime/src/encoding.c +0 -0
- package/runtime/src/error.c +0 -0
- package/runtime/src/events.c +0 -0
- package/runtime/src/exception.c +0 -0
- package/runtime/src/fetch.c +0 -0
- package/runtime/src/function.c +0 -0
- package/runtime/src/gc.c +0 -0
- package/runtime/src/generator.c +0 -0
- package/runtime/src/global.c +0 -0
- package/runtime/src/headers.c +0 -0
- package/runtime/src/inspect.c +0 -0
- package/runtime/src/internal.h +0 -0
- package/runtime/src/iterate.c +0 -0
- package/runtime/src/iterator.c +0 -0
- package/runtime/src/jobs.c +0 -0
- package/runtime/src/jsnum.c +0 -0
- package/runtime/src/json.c +0 -0
- package/runtime/src/math.c +0 -0
- package/runtime/src/module.c +0 -0
- package/runtime/src/number.c +0 -0
- package/runtime/src/object.c +0 -0
- package/runtime/src/ops.c +0 -0
- package/runtime/src/os.c +0 -0
- package/runtime/src/os.h +0 -0
- package/runtime/src/process.c +7 -0
- package/runtime/src/promise.c +0 -0
- package/runtime/src/proxy.c +0 -0
- package/runtime/src/reflect.c +0 -0
- package/runtime/src/regexp.c +0 -0
- package/runtime/src/regexp_anchor.h +0 -0
- package/runtime/src/regexp_message.h +0 -0
- package/runtime/src/shape.c +0 -0
- package/runtime/src/shape.h +0 -0
- package/runtime/src/streams.c +0 -0
- package/runtime/src/streams.h +0 -0
- package/runtime/src/string.c +0 -0
- package/runtime/src/string_builtins.c +0 -0
- package/runtime/src/symbol.c +0 -0
- package/runtime/src/test_host.c +0 -0
- package/runtime/src/typedarray.c +0 -0
- package/runtime/src/tznames.gen.h +0 -0
- package/runtime/src/uri.c +0 -0
- package/runtime/src/url.c +0 -0
- package/runtime/src/weak.c +0 -0
- package/runtime/src/web.c +0 -0
- package/runtime/src/wrapper.c +0 -0
- package/runtime/src/writable.c +0 -0
- package/runtime/third_party/ada-idna/LICENSE-MIT +0 -0
- package/runtime/third_party/ada-idna/README.md +0 -0
- package/runtime/third_party/ada-idna/convert.mjs +0 -0
- package/runtime/third_party/ada-idna/idna.c +0 -0
- package/runtime/third_party/ada-idna/idna.h +0 -0
- package/runtime/third_party/ada-idna/idna_tables.h +0 -0
- package/runtime/third_party/quickjs-dtoa/LICENSE +0 -0
- package/runtime/third_party/quickjs-dtoa/README.md +0 -0
- package/runtime/third_party/quickjs-dtoa/dtoa.c +0 -0
- package/runtime/third_party/quickjs-dtoa/dtoa.h +0 -0
- package/runtime/third_party/quickjs-dtoa/dtoa_compat.h +0 -0
- package/runtime/third_party/quickjs-regexp/LICENSE +0 -0
- package/runtime/third_party/quickjs-regexp/README.md +0 -0
- package/runtime/third_party/quickjs-regexp/cutils.c +0 -0
- package/runtime/third_party/quickjs-regexp/cutils.h +0 -0
- package/runtime/third_party/quickjs-regexp/libregexp-opcode.h +0 -0
- package/runtime/third_party/quickjs-regexp/libregexp.c +0 -0
- package/runtime/third_party/quickjs-regexp/libregexp.h +0 -0
- package/runtime/third_party/quickjs-regexp/libunicode-table.h +0 -0
- package/runtime/third_party/quickjs-regexp/libunicode.c +0 -0
- package/runtime/third_party/quickjs-regexp/libunicode.h +0 -0
- package/runtime/third_party/v8-ieee754/LICENSE +0 -0
- package/runtime/third_party/v8-ieee754/README.md +0 -0
- package/runtime/third_party/v8-ieee754/convert.py +0 -0
- package/runtime/third_party/v8-ieee754/ieee754.c +0 -0
- package/runtime/third_party/v8-ieee754/ieee754.h +0 -0
- package/runtime/tools/regexp_compile.c +0 -0
|
@@ -0,0 +1,388 @@
|
|
|
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 <assert.h>
|
|
23
|
+
|
|
24
|
+
#include "uv.h"
|
|
25
|
+
#include "internal.h"
|
|
26
|
+
#include "req-inl.h"
|
|
27
|
+
#include "idna.h"
|
|
28
|
+
|
|
29
|
+
/* EAI_* constants. */
|
|
30
|
+
#include <winsock2.h>
|
|
31
|
+
|
|
32
|
+
/* Needed for ConvertInterfaceIndexToLuid and ConvertInterfaceLuidToNameA */
|
|
33
|
+
#include <iphlpapi.h>
|
|
34
|
+
|
|
35
|
+
int uv__getaddrinfo_translate_error(int sys_err) {
|
|
36
|
+
switch (sys_err) {
|
|
37
|
+
case 0: return 0;
|
|
38
|
+
case WSATRY_AGAIN: return UV_EAI_AGAIN;
|
|
39
|
+
case WSAEINVAL: return UV_EAI_BADFLAGS;
|
|
40
|
+
case WSANO_RECOVERY: return UV_EAI_FAIL;
|
|
41
|
+
case WSAEAFNOSUPPORT: return UV_EAI_FAMILY;
|
|
42
|
+
case WSA_NOT_ENOUGH_MEMORY: return UV_EAI_MEMORY;
|
|
43
|
+
case WSAHOST_NOT_FOUND: return UV_EAI_NONAME;
|
|
44
|
+
case WSATYPE_NOT_FOUND: return UV_EAI_SERVICE;
|
|
45
|
+
case WSAESOCKTNOSUPPORT: return UV_EAI_SOCKTYPE;
|
|
46
|
+
default: return uv_translate_sys_error(sys_err);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
/*
|
|
52
|
+
* MinGW is missing this
|
|
53
|
+
*/
|
|
54
|
+
#if !defined(_MSC_VER) && !defined(__MINGW64_VERSION_MAJOR)
|
|
55
|
+
typedef struct addrinfoW {
|
|
56
|
+
int ai_flags;
|
|
57
|
+
int ai_family;
|
|
58
|
+
int ai_socktype;
|
|
59
|
+
int ai_protocol;
|
|
60
|
+
size_t ai_addrlen;
|
|
61
|
+
WCHAR* ai_canonname;
|
|
62
|
+
struct sockaddr* ai_addr;
|
|
63
|
+
struct addrinfoW* ai_next;
|
|
64
|
+
} ADDRINFOW, *PADDRINFOW;
|
|
65
|
+
|
|
66
|
+
DECLSPEC_IMPORT int WSAAPI GetAddrInfoW(const WCHAR* node,
|
|
67
|
+
const WCHAR* service,
|
|
68
|
+
const ADDRINFOW* hints,
|
|
69
|
+
PADDRINFOW* result);
|
|
70
|
+
|
|
71
|
+
DECLSPEC_IMPORT void WSAAPI FreeAddrInfoW(PADDRINFOW pAddrInfo);
|
|
72
|
+
#endif
|
|
73
|
+
|
|
74
|
+
static size_t align_offset(size_t off, size_t alignment) {
|
|
75
|
+
return ((off + alignment - 1) / alignment) * alignment;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
#ifndef NDIS_IF_MAX_STRING_SIZE
|
|
79
|
+
#define NDIS_IF_MAX_STRING_SIZE IF_MAX_STRING_SIZE
|
|
80
|
+
#endif
|
|
81
|
+
|
|
82
|
+
static void uv__getaddrinfo_work(struct uv__work* w) {
|
|
83
|
+
uv_getaddrinfo_t* req;
|
|
84
|
+
struct addrinfoW* hints;
|
|
85
|
+
int err;
|
|
86
|
+
|
|
87
|
+
req = container_of(w, uv_getaddrinfo_t, work_req);
|
|
88
|
+
hints = req->addrinfow;
|
|
89
|
+
req->addrinfow = NULL;
|
|
90
|
+
err = GetAddrInfoW(req->node, req->service, hints, &req->addrinfow);
|
|
91
|
+
req->retcode = uv__getaddrinfo_translate_error(err);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
/*
|
|
96
|
+
* Called from uv_run when complete. Call user specified callback
|
|
97
|
+
* then free returned addrinfo
|
|
98
|
+
* Returned addrinfo strings are converted from UTF-16 to UTF-8.
|
|
99
|
+
*
|
|
100
|
+
* To minimize allocation we calculate total size required,
|
|
101
|
+
* and copy all structs and referenced strings into the one block.
|
|
102
|
+
* Each size calculation is adjusted to avoid unaligned pointers.
|
|
103
|
+
*/
|
|
104
|
+
static void uv__getaddrinfo_done(struct uv__work* w, int status) {
|
|
105
|
+
uv_getaddrinfo_t* req = container_of(w, uv_getaddrinfo_t, work_req);
|
|
106
|
+
|
|
107
|
+
/* release input parameter memory */
|
|
108
|
+
uv__free(req->alloc);
|
|
109
|
+
req->alloc = NULL;
|
|
110
|
+
|
|
111
|
+
if (status == UV_ECANCELED) {
|
|
112
|
+
assert(req->retcode == 0);
|
|
113
|
+
req->retcode = UV_EAI_CANCELED;
|
|
114
|
+
goto complete;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if (req->retcode == 0) {
|
|
118
|
+
char* alloc_ptr = NULL;
|
|
119
|
+
size_t cur_off = 0;
|
|
120
|
+
size_t addrinfo_len;
|
|
121
|
+
/* Convert addrinfoW to addrinfo. First calculate required length. */
|
|
122
|
+
struct addrinfoW* addrinfow_ptr = req->addrinfow;
|
|
123
|
+
while (addrinfow_ptr != NULL) {
|
|
124
|
+
cur_off = align_offset(cur_off, sizeof(void*));
|
|
125
|
+
cur_off += sizeof(struct addrinfo);
|
|
126
|
+
/* TODO: This alignment could be smaller, if we could
|
|
127
|
+
portably get the alignment for sockaddr. */
|
|
128
|
+
cur_off = align_offset(cur_off, sizeof(void*));
|
|
129
|
+
cur_off += addrinfow_ptr->ai_addrlen;
|
|
130
|
+
if (addrinfow_ptr->ai_canonname != NULL) {
|
|
131
|
+
ssize_t name_len =
|
|
132
|
+
uv_utf16_length_as_wtf8(addrinfow_ptr->ai_canonname, -1);
|
|
133
|
+
if (name_len < 0) {
|
|
134
|
+
req->retcode = name_len;
|
|
135
|
+
goto complete;
|
|
136
|
+
}
|
|
137
|
+
cur_off += name_len + 1;
|
|
138
|
+
}
|
|
139
|
+
addrinfow_ptr = addrinfow_ptr->ai_next;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/* allocate memory for addrinfo results */
|
|
143
|
+
addrinfo_len = cur_off;
|
|
144
|
+
alloc_ptr = uv__malloc(addrinfo_len);
|
|
145
|
+
|
|
146
|
+
/* do conversions */
|
|
147
|
+
if (alloc_ptr != NULL) {
|
|
148
|
+
struct addrinfo *addrinfo_ptr = (struct addrinfo *)alloc_ptr;
|
|
149
|
+
cur_off = 0;
|
|
150
|
+
addrinfow_ptr = req->addrinfow;
|
|
151
|
+
|
|
152
|
+
for (;;) {
|
|
153
|
+
cur_off += sizeof(struct addrinfo);
|
|
154
|
+
assert(cur_off <= addrinfo_len);
|
|
155
|
+
/* copy addrinfo struct data */
|
|
156
|
+
addrinfo_ptr->ai_family = addrinfow_ptr->ai_family;
|
|
157
|
+
addrinfo_ptr->ai_socktype = addrinfow_ptr->ai_socktype;
|
|
158
|
+
addrinfo_ptr->ai_protocol = addrinfow_ptr->ai_protocol;
|
|
159
|
+
addrinfo_ptr->ai_flags = addrinfow_ptr->ai_flags;
|
|
160
|
+
addrinfo_ptr->ai_addrlen = addrinfow_ptr->ai_addrlen;
|
|
161
|
+
addrinfo_ptr->ai_canonname = NULL;
|
|
162
|
+
addrinfo_ptr->ai_addr = NULL;
|
|
163
|
+
addrinfo_ptr->ai_next = NULL;
|
|
164
|
+
|
|
165
|
+
/* copy sockaddr */
|
|
166
|
+
if (addrinfo_ptr->ai_addrlen > 0) {
|
|
167
|
+
cur_off = align_offset(cur_off, sizeof(void *));
|
|
168
|
+
addrinfo_ptr->ai_addr = (struct sockaddr *)(alloc_ptr + cur_off);
|
|
169
|
+
cur_off += addrinfo_ptr->ai_addrlen;
|
|
170
|
+
assert(cur_off <= addrinfo_len);
|
|
171
|
+
memcpy(addrinfo_ptr->ai_addr,
|
|
172
|
+
addrinfow_ptr->ai_addr,
|
|
173
|
+
addrinfo_ptr->ai_addrlen);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/* convert canonical name to UTF-8 */
|
|
177
|
+
if (addrinfow_ptr->ai_canonname != NULL) {
|
|
178
|
+
ssize_t name_len = addrinfo_len - cur_off;
|
|
179
|
+
addrinfo_ptr->ai_canonname = alloc_ptr + cur_off;
|
|
180
|
+
int r = uv__copy_utf16_to_utf8(addrinfow_ptr->ai_canonname,
|
|
181
|
+
-1,
|
|
182
|
+
addrinfo_ptr->ai_canonname,
|
|
183
|
+
(size_t*)&name_len);
|
|
184
|
+
assert(r == 0);
|
|
185
|
+
cur_off += name_len + 1;
|
|
186
|
+
assert(cur_off <= addrinfo_len);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/* set next ptr */
|
|
190
|
+
addrinfow_ptr = addrinfow_ptr->ai_next;
|
|
191
|
+
if (addrinfow_ptr == NULL)
|
|
192
|
+
break;
|
|
193
|
+
cur_off = align_offset(cur_off, sizeof(void *));
|
|
194
|
+
struct addrinfo *next_addrinfo_ptr = (struct addrinfo *)(alloc_ptr + cur_off);
|
|
195
|
+
addrinfo_ptr->ai_next = next_addrinfo_ptr;
|
|
196
|
+
addrinfo_ptr = next_addrinfo_ptr;
|
|
197
|
+
}
|
|
198
|
+
req->addrinfo = (struct addrinfo*)alloc_ptr;
|
|
199
|
+
} else {
|
|
200
|
+
req->retcode = UV_EAI_MEMORY;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/* return memory to system */
|
|
205
|
+
if (req->addrinfow != NULL) {
|
|
206
|
+
FreeAddrInfoW(req->addrinfow);
|
|
207
|
+
req->addrinfow = NULL;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
complete:
|
|
211
|
+
uv__req_unregister(req->loop);
|
|
212
|
+
|
|
213
|
+
/* finally do callback with converted result */
|
|
214
|
+
if (req->getaddrinfo_cb)
|
|
215
|
+
req->getaddrinfo_cb(req, req->retcode, req->addrinfo);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
void uv_freeaddrinfo(struct addrinfo* ai) {
|
|
220
|
+
char* alloc_ptr = (char*)ai;
|
|
221
|
+
|
|
222
|
+
/* release copied result memory */
|
|
223
|
+
uv__free(alloc_ptr);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
/*
|
|
228
|
+
* Entry point for getaddrinfo
|
|
229
|
+
* we convert the UTF-8 strings to UNICODE
|
|
230
|
+
* and save the UNICODE string pointers in the req
|
|
231
|
+
* We also copy hints so that caller does not need to keep memory until the
|
|
232
|
+
* callback.
|
|
233
|
+
* return 0 if a callback will be made
|
|
234
|
+
* return error code if validation fails
|
|
235
|
+
*
|
|
236
|
+
* To minimize allocation we calculate total size required,
|
|
237
|
+
* and copy all structs and referenced strings into the one block.
|
|
238
|
+
* Each size calculation is adjusted to avoid unaligned pointers.
|
|
239
|
+
*/
|
|
240
|
+
int uv_getaddrinfo(uv_loop_t* loop,
|
|
241
|
+
uv_getaddrinfo_t* req,
|
|
242
|
+
uv_getaddrinfo_cb getaddrinfo_cb,
|
|
243
|
+
const char* node,
|
|
244
|
+
const char* service,
|
|
245
|
+
const struct addrinfo* hints) {
|
|
246
|
+
char hostname_ascii[256];
|
|
247
|
+
size_t off = 0;
|
|
248
|
+
size_t nodesize = 0;
|
|
249
|
+
size_t servicesize = 0;
|
|
250
|
+
size_t serviceoff = 0;
|
|
251
|
+
size_t hintssize = 0;
|
|
252
|
+
size_t hintoff = 0;
|
|
253
|
+
ssize_t rc;
|
|
254
|
+
|
|
255
|
+
if (req == NULL || (node == NULL && service == NULL)) {
|
|
256
|
+
return UV_EINVAL;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
UV_REQ_INIT(req, UV_GETADDRINFO);
|
|
260
|
+
req->getaddrinfo_cb = getaddrinfo_cb;
|
|
261
|
+
req->addrinfo = NULL;
|
|
262
|
+
req->loop = loop;
|
|
263
|
+
req->retcode = 0;
|
|
264
|
+
|
|
265
|
+
/* calculate required memory size for all input values */
|
|
266
|
+
if (node != NULL) {
|
|
267
|
+
rc = uv__idna_toascii(node,
|
|
268
|
+
node + strlen(node),
|
|
269
|
+
hostname_ascii,
|
|
270
|
+
hostname_ascii + sizeof(hostname_ascii));
|
|
271
|
+
if (rc < 0)
|
|
272
|
+
return rc;
|
|
273
|
+
nodesize = strlen(hostname_ascii) + 1;
|
|
274
|
+
node = hostname_ascii;
|
|
275
|
+
off += nodesize * sizeof(WCHAR);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
if (service != NULL) {
|
|
279
|
+
rc = uv_wtf8_length_as_utf16(service);
|
|
280
|
+
if (rc < 0)
|
|
281
|
+
return rc;
|
|
282
|
+
servicesize = rc;
|
|
283
|
+
off = align_offset(off, sizeof(WCHAR));
|
|
284
|
+
serviceoff = off;
|
|
285
|
+
off += servicesize * sizeof(WCHAR);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
if (hints != NULL) {
|
|
289
|
+
off = align_offset(off, sizeof(void *));
|
|
290
|
+
hintoff = off;
|
|
291
|
+
hintssize = sizeof(struct addrinfoW);
|
|
292
|
+
off += hintssize;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/* allocate memory for inputs, and partition it as needed */
|
|
296
|
+
req->alloc = uv__malloc(off);
|
|
297
|
+
if (!req->alloc)
|
|
298
|
+
return UV_ENOMEM;
|
|
299
|
+
|
|
300
|
+
/* Convert node string to UTF16 into allocated memory and save pointer in the
|
|
301
|
+
* request. The node here has been converted to ascii. */
|
|
302
|
+
if (node != NULL) {
|
|
303
|
+
req->node = (WCHAR*) req->alloc;
|
|
304
|
+
uv_wtf8_to_utf16(node, req->node, nodesize);
|
|
305
|
+
} else {
|
|
306
|
+
req->node = NULL;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/* Convert service string to UTF16 into allocated memory and save pointer in
|
|
310
|
+
* the req. */
|
|
311
|
+
if (service != NULL) {
|
|
312
|
+
req->service = (WCHAR*) ((char*) req->alloc + serviceoff);
|
|
313
|
+
uv_wtf8_to_utf16(service, req->service, servicesize);
|
|
314
|
+
} else {
|
|
315
|
+
req->service = NULL;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/* copy hints to allocated memory and save pointer in req */
|
|
319
|
+
if (hints != NULL) {
|
|
320
|
+
req->addrinfow = (struct addrinfoW*) ((char*) req->alloc + hintoff);
|
|
321
|
+
req->addrinfow->ai_family = hints->ai_family;
|
|
322
|
+
req->addrinfow->ai_socktype = hints->ai_socktype;
|
|
323
|
+
req->addrinfow->ai_protocol = hints->ai_protocol;
|
|
324
|
+
req->addrinfow->ai_flags = hints->ai_flags;
|
|
325
|
+
req->addrinfow->ai_addrlen = 0;
|
|
326
|
+
req->addrinfow->ai_canonname = NULL;
|
|
327
|
+
req->addrinfow->ai_addr = NULL;
|
|
328
|
+
req->addrinfow->ai_next = NULL;
|
|
329
|
+
} else {
|
|
330
|
+
req->addrinfow = NULL;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
uv__req_register(loop);
|
|
334
|
+
|
|
335
|
+
if (getaddrinfo_cb) {
|
|
336
|
+
uv__work_submit(loop,
|
|
337
|
+
&req->work_req,
|
|
338
|
+
UV__WORK_SLOW_IO,
|
|
339
|
+
uv__getaddrinfo_work,
|
|
340
|
+
uv__getaddrinfo_done);
|
|
341
|
+
return 0;
|
|
342
|
+
} else {
|
|
343
|
+
uv__getaddrinfo_work(&req->work_req);
|
|
344
|
+
uv__getaddrinfo_done(&req->work_req, 0);
|
|
345
|
+
return req->retcode;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
int uv_if_indextoname(unsigned int ifindex, char* buffer, size_t* size) {
|
|
350
|
+
NET_LUID luid;
|
|
351
|
+
wchar_t wname[NDIS_IF_MAX_STRING_SIZE + 1]; /* Add one for the NUL. */
|
|
352
|
+
int r;
|
|
353
|
+
|
|
354
|
+
if (buffer == NULL || size == NULL || *size == 0)
|
|
355
|
+
return UV_EINVAL;
|
|
356
|
+
|
|
357
|
+
r = ConvertInterfaceIndexToLuid(ifindex, &luid);
|
|
358
|
+
|
|
359
|
+
if (r != 0)
|
|
360
|
+
return uv_translate_sys_error(r);
|
|
361
|
+
|
|
362
|
+
r = ConvertInterfaceLuidToNameW(&luid, wname, ARRAY_SIZE(wname));
|
|
363
|
+
|
|
364
|
+
if (r != 0)
|
|
365
|
+
return uv_translate_sys_error(r);
|
|
366
|
+
|
|
367
|
+
return uv__copy_utf16_to_utf8(wname, -1, buffer, size);
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
int uv_if_indextoiid(unsigned int ifindex, char* buffer, size_t* size) {
|
|
371
|
+
int r;
|
|
372
|
+
|
|
373
|
+
if (buffer == NULL || size == NULL || *size == 0)
|
|
374
|
+
return UV_EINVAL;
|
|
375
|
+
|
|
376
|
+
r = snprintf(buffer, *size, "%d", ifindex);
|
|
377
|
+
|
|
378
|
+
if (r < 0)
|
|
379
|
+
return uv_translate_sys_error(r);
|
|
380
|
+
|
|
381
|
+
if (r >= (int) *size) {
|
|
382
|
+
*size = r + 1;
|
|
383
|
+
return UV_ENOBUFS;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
*size = r;
|
|
387
|
+
return 0;
|
|
388
|
+
}
|
|
@@ -0,0 +1,146 @@
|
|
|
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 <assert.h>
|
|
23
|
+
#include <stdio.h>
|
|
24
|
+
|
|
25
|
+
#include "uv.h"
|
|
26
|
+
#include "internal.h"
|
|
27
|
+
#include "req-inl.h"
|
|
28
|
+
|
|
29
|
+
#ifndef GetNameInfo
|
|
30
|
+
int WSAAPI GetNameInfoW(
|
|
31
|
+
const SOCKADDR *pSockaddr,
|
|
32
|
+
socklen_t SockaddrLength,
|
|
33
|
+
PWCHAR pNodeBuffer,
|
|
34
|
+
DWORD NodeBufferSize,
|
|
35
|
+
PWCHAR pServiceBuffer,
|
|
36
|
+
DWORD ServiceBufferSize,
|
|
37
|
+
INT Flags
|
|
38
|
+
);
|
|
39
|
+
#endif
|
|
40
|
+
|
|
41
|
+
static void uv__getnameinfo_work(struct uv__work* w) {
|
|
42
|
+
uv_getnameinfo_t* req;
|
|
43
|
+
WCHAR host[NI_MAXHOST];
|
|
44
|
+
WCHAR service[NI_MAXSERV];
|
|
45
|
+
size_t size;
|
|
46
|
+
int ret;
|
|
47
|
+
|
|
48
|
+
req = container_of(w, uv_getnameinfo_t, work_req);
|
|
49
|
+
if (GetNameInfoW((struct sockaddr*)&req->storage,
|
|
50
|
+
sizeof(req->storage),
|
|
51
|
+
host,
|
|
52
|
+
ARRAY_SIZE(host),
|
|
53
|
+
service,
|
|
54
|
+
ARRAY_SIZE(service),
|
|
55
|
+
req->flags)) {
|
|
56
|
+
ret = WSAGetLastError();
|
|
57
|
+
req->retcode = uv__getaddrinfo_translate_error(ret);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
size = sizeof(req->host);
|
|
62
|
+
ret = uv__copy_utf16_to_utf8(host, -1, req->host, &size);
|
|
63
|
+
if (ret < 0) {
|
|
64
|
+
req->retcode = ret;
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
size = sizeof(req->service);
|
|
69
|
+
ret = uv__copy_utf16_to_utf8(service, -1, req->service, &size);
|
|
70
|
+
if (ret < 0) {
|
|
71
|
+
req->retcode = ret;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
/*
|
|
77
|
+
* Called from uv_run when complete.
|
|
78
|
+
*/
|
|
79
|
+
static void uv__getnameinfo_done(struct uv__work* w, int status) {
|
|
80
|
+
uv_getnameinfo_t* req;
|
|
81
|
+
char* host;
|
|
82
|
+
char* service;
|
|
83
|
+
|
|
84
|
+
req = container_of(w, uv_getnameinfo_t, work_req);
|
|
85
|
+
uv__req_unregister(req->loop);
|
|
86
|
+
host = service = NULL;
|
|
87
|
+
|
|
88
|
+
if (status == UV_ECANCELED) {
|
|
89
|
+
assert(req->retcode == 0);
|
|
90
|
+
req->retcode = UV_EAI_CANCELED;
|
|
91
|
+
} else if (req->retcode == 0) {
|
|
92
|
+
host = req->host;
|
|
93
|
+
service = req->service;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (req->getnameinfo_cb)
|
|
97
|
+
req->getnameinfo_cb(req, req->retcode, host, service);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
/*
|
|
102
|
+
* Entry point for getnameinfo
|
|
103
|
+
* return 0 if a callback will be made
|
|
104
|
+
* return error code if validation fails
|
|
105
|
+
*/
|
|
106
|
+
int uv_getnameinfo(uv_loop_t* loop,
|
|
107
|
+
uv_getnameinfo_t* req,
|
|
108
|
+
uv_getnameinfo_cb getnameinfo_cb,
|
|
109
|
+
const struct sockaddr* addr,
|
|
110
|
+
int flags) {
|
|
111
|
+
if (req == NULL || addr == NULL)
|
|
112
|
+
return UV_EINVAL;
|
|
113
|
+
|
|
114
|
+
if (addr->sa_family == AF_INET) {
|
|
115
|
+
memcpy(&req->storage,
|
|
116
|
+
addr,
|
|
117
|
+
sizeof(struct sockaddr_in));
|
|
118
|
+
} else if (addr->sa_family == AF_INET6) {
|
|
119
|
+
memcpy(&req->storage,
|
|
120
|
+
addr,
|
|
121
|
+
sizeof(struct sockaddr_in6));
|
|
122
|
+
} else {
|
|
123
|
+
return UV_EINVAL;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
UV_REQ_INIT(req, UV_GETNAMEINFO);
|
|
127
|
+
uv__req_register(loop);
|
|
128
|
+
|
|
129
|
+
req->getnameinfo_cb = getnameinfo_cb;
|
|
130
|
+
req->flags = flags;
|
|
131
|
+
req->loop = loop;
|
|
132
|
+
req->retcode = 0;
|
|
133
|
+
|
|
134
|
+
if (getnameinfo_cb) {
|
|
135
|
+
uv__work_submit(loop,
|
|
136
|
+
&req->work_req,
|
|
137
|
+
UV__WORK_SLOW_IO,
|
|
138
|
+
uv__getnameinfo_work,
|
|
139
|
+
uv__getnameinfo_done);
|
|
140
|
+
return 0;
|
|
141
|
+
} else {
|
|
142
|
+
uv__getnameinfo_work(&req->work_req);
|
|
143
|
+
uv__getnameinfo_done(&req->work_req, 0);
|
|
144
|
+
return req->retcode;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
@@ -0,0 +1,180 @@
|
|
|
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
|
+
#include <io.h>
|
|
27
|
+
|
|
28
|
+
#include "uv.h"
|
|
29
|
+
#include "internal.h"
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
#define DECREASE_ACTIVE_COUNT(loop, handle) \
|
|
33
|
+
do { \
|
|
34
|
+
if (--(handle)->activecnt == 0 && \
|
|
35
|
+
!((handle)->flags & UV_HANDLE_CLOSING)) { \
|
|
36
|
+
uv__handle_stop((handle)); \
|
|
37
|
+
} \
|
|
38
|
+
assert((handle)->activecnt >= 0); \
|
|
39
|
+
} while (0)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
#define INCREASE_ACTIVE_COUNT(loop, handle) \
|
|
43
|
+
do { \
|
|
44
|
+
if ((handle)->activecnt++ == 0) { \
|
|
45
|
+
uv__handle_start((handle)); \
|
|
46
|
+
} \
|
|
47
|
+
assert((handle)->activecnt > 0); \
|
|
48
|
+
} while (0)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
#define DECREASE_PENDING_REQ_COUNT(handle) \
|
|
52
|
+
do { \
|
|
53
|
+
assert(handle->reqs_pending > 0); \
|
|
54
|
+
handle->reqs_pending--; \
|
|
55
|
+
\
|
|
56
|
+
if (handle->flags & UV_HANDLE_CLOSING && \
|
|
57
|
+
handle->reqs_pending == 0) { \
|
|
58
|
+
uv__want_endgame(loop, (uv_handle_t*)handle); \
|
|
59
|
+
} \
|
|
60
|
+
} while (0)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
#define uv__handle_closing(handle) \
|
|
64
|
+
do { \
|
|
65
|
+
assert(!((handle)->flags & UV_HANDLE_CLOSING)); \
|
|
66
|
+
\
|
|
67
|
+
if (!(((handle)->flags & UV_HANDLE_ACTIVE) && \
|
|
68
|
+
((handle)->flags & UV_HANDLE_REF))) \
|
|
69
|
+
uv__active_handle_add((uv_handle_t*) (handle)); \
|
|
70
|
+
\
|
|
71
|
+
(handle)->flags |= UV_HANDLE_CLOSING; \
|
|
72
|
+
(handle)->flags &= ~UV_HANDLE_ACTIVE; \
|
|
73
|
+
} while (0)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
#define uv__handle_close(handle) \
|
|
77
|
+
do { \
|
|
78
|
+
uv__queue_remove(&(handle)->handle_queue); \
|
|
79
|
+
uv__active_handle_rm((uv_handle_t*) (handle)); \
|
|
80
|
+
\
|
|
81
|
+
(handle)->flags |= UV_HANDLE_CLOSED; \
|
|
82
|
+
\
|
|
83
|
+
if ((handle)->close_cb) \
|
|
84
|
+
(handle)->close_cb((uv_handle_t*) (handle)); \
|
|
85
|
+
} while (0)
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
INLINE static void uv__want_endgame(uv_loop_t* loop, uv_handle_t* handle) {
|
|
89
|
+
if (!(handle->flags & UV_HANDLE_ENDGAME_QUEUED)) {
|
|
90
|
+
handle->flags |= UV_HANDLE_ENDGAME_QUEUED;
|
|
91
|
+
|
|
92
|
+
handle->endgame_next = loop->endgame_handles;
|
|
93
|
+
loop->endgame_handles = handle;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
INLINE static void uv__process_endgames(uv_loop_t* loop) {
|
|
99
|
+
uv_handle_t* handle;
|
|
100
|
+
|
|
101
|
+
while (loop->endgame_handles) {
|
|
102
|
+
handle = loop->endgame_handles;
|
|
103
|
+
loop->endgame_handles = handle->endgame_next;
|
|
104
|
+
|
|
105
|
+
handle->flags &= ~UV_HANDLE_ENDGAME_QUEUED;
|
|
106
|
+
|
|
107
|
+
switch (handle->type) {
|
|
108
|
+
case UV_TCP:
|
|
109
|
+
uv__tcp_endgame(loop, (uv_tcp_t*) handle);
|
|
110
|
+
break;
|
|
111
|
+
|
|
112
|
+
case UV_NAMED_PIPE:
|
|
113
|
+
uv__pipe_endgame(loop, (uv_pipe_t*) handle);
|
|
114
|
+
break;
|
|
115
|
+
|
|
116
|
+
case UV_TTY:
|
|
117
|
+
uv__tty_endgame(loop, (uv_tty_t*) handle);
|
|
118
|
+
break;
|
|
119
|
+
|
|
120
|
+
case UV_UDP:
|
|
121
|
+
uv__udp_endgame(loop, (uv_udp_t*) handle);
|
|
122
|
+
break;
|
|
123
|
+
|
|
124
|
+
case UV_POLL:
|
|
125
|
+
uv__poll_endgame(loop, (uv_poll_t*) handle);
|
|
126
|
+
break;
|
|
127
|
+
|
|
128
|
+
case UV_TIMER:
|
|
129
|
+
uv__timer_close((uv_timer_t*) handle);
|
|
130
|
+
uv__handle_close(handle);
|
|
131
|
+
break;
|
|
132
|
+
|
|
133
|
+
case UV_PREPARE:
|
|
134
|
+
case UV_CHECK:
|
|
135
|
+
case UV_IDLE:
|
|
136
|
+
uv__loop_watcher_endgame(loop, handle);
|
|
137
|
+
break;
|
|
138
|
+
|
|
139
|
+
case UV_ASYNC:
|
|
140
|
+
uv__async_endgame(loop, (uv_async_t*) handle);
|
|
141
|
+
break;
|
|
142
|
+
|
|
143
|
+
case UV_SIGNAL:
|
|
144
|
+
uv__signal_endgame(loop, (uv_signal_t*) handle);
|
|
145
|
+
break;
|
|
146
|
+
|
|
147
|
+
case UV_PROCESS:
|
|
148
|
+
uv__process_endgame(loop, (uv_process_t*) handle);
|
|
149
|
+
break;
|
|
150
|
+
|
|
151
|
+
case UV_FS_EVENT:
|
|
152
|
+
uv__fs_event_endgame(loop, (uv_fs_event_t*) handle);
|
|
153
|
+
break;
|
|
154
|
+
|
|
155
|
+
case UV_FS_POLL:
|
|
156
|
+
uv__fs_poll_endgame(loop, (uv_fs_poll_t*) handle);
|
|
157
|
+
break;
|
|
158
|
+
|
|
159
|
+
default:
|
|
160
|
+
assert(0);
|
|
161
|
+
break;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
INLINE static HANDLE uv__get_osfhandle(int fd)
|
|
167
|
+
{
|
|
168
|
+
/* _get_osfhandle() raises an assert in debug builds if the FD is invalid.
|
|
169
|
+
* But it also correctly checks the FD and returns INVALID_HANDLE_VALUE for
|
|
170
|
+
* invalid FDs in release builds (or if you let the assert continue). So this
|
|
171
|
+
* wrapper function disables asserts when calling _get_osfhandle. */
|
|
172
|
+
|
|
173
|
+
HANDLE handle;
|
|
174
|
+
UV_BEGIN_DISABLE_CRT_ASSERT();
|
|
175
|
+
handle = (HANDLE) _get_osfhandle(fd);
|
|
176
|
+
UV_END_DISABLE_CRT_ASSERT();
|
|
177
|
+
return handle;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
#endif /* UV_WIN_HANDLE_INL_H_ */
|