@ac-kit/node 0.1.0 → 0.2.0
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/CHANGELOG.md +55 -0
- package/README.md +2 -0
- package/dist/index.d.ts +5 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -2
- package/dist/index.js.map +1 -1
- package/dist/net/connection-closed-error.d.ts +12 -0
- package/dist/net/connection-closed-error.d.ts.map +1 -0
- package/dist/net/connection-closed-error.js +15 -0
- package/dist/net/connection-closed-error.js.map +1 -0
- package/dist/net/dgram-socket.d.ts +2 -2
- package/dist/net/dgram-socket.d.ts.map +1 -1
- package/dist/net/dgram-socket.js +35 -35
- package/dist/net/dgram-socket.js.map +1 -1
- package/dist/net/inet-socket.d.ts +64 -0
- package/dist/net/inet-socket.d.ts.map +1 -0
- package/dist/net/inet-socket.js +103 -0
- package/dist/net/inet-socket.js.map +1 -0
- package/dist/net/ipc-server.d.ts +63 -0
- package/dist/net/ipc-server.d.ts.map +1 -0
- package/dist/net/ipc-server.js +75 -0
- package/dist/net/ipc-server.js.map +1 -0
- package/dist/net/ipc-socket.d.ts +55 -22
- package/dist/net/ipc-socket.d.ts.map +1 -1
- package/dist/net/ipc-socket.js +50 -46
- package/dist/net/ipc-socket.js.map +1 -1
- package/dist/net/stream-server.d.ts +80 -0
- package/dist/net/stream-server.d.ts.map +1 -0
- package/dist/net/stream-server.js +129 -0
- package/dist/net/stream-server.js.map +1 -0
- package/dist/net/stream-socket.d.ts +37 -8
- package/dist/net/stream-socket.d.ts.map +1 -1
- package/dist/net/stream-socket.js +80 -27
- package/dist/net/stream-socket.js.map +1 -1
- package/dist/net/tcp-server.d.ts +31 -73
- package/dist/net/tcp-server.d.ts.map +1 -1
- package/dist/net/tcp-server.js +41 -147
- package/dist/net/tcp-server.js.map +1 -1
- package/dist/net/tcp-socket.d.ts +21 -61
- package/dist/net/tcp-socket.d.ts.map +1 -1
- package/dist/net/tcp-socket.js +23 -126
- package/dist/net/tcp-socket.js.map +1 -1
- package/dist/net/tls-server.d.ts +87 -0
- package/dist/net/tls-server.d.ts.map +1 -0
- package/dist/net/tls-server.js +103 -0
- package/dist/net/tls-server.js.map +1 -0
- package/dist/net/tls-socket.d.ts +235 -14
- package/dist/net/tls-socket.d.ts.map +1 -1
- package/dist/net/tls-socket.js +241 -91
- package/dist/net/tls-socket.js.map +1 -1
- package/package.json +4 -4
- package/dist/shell/escape-command-arg.d.ts +0 -9
- package/dist/shell/escape-command-arg.d.ts.map +0 -1
- package/dist/shell/escape-command-arg.js +0 -13
- package/dist/shell/escape-command-arg.js.map +0 -1
- package/dist/shell/escape-command.d.ts +0 -10
- package/dist/shell/escape-command.d.ts.map +0 -1
- package/dist/shell/escape-command.js +0 -12
- package/dist/shell/escape-command.js.map +0 -1
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# @ac-kit/node
|
|
2
|
+
|
|
3
|
+
## 0.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- a493b4a: **Breaking:** `escapeCommandArg` and `escapeCommand` are gone. They dispatched
|
|
8
|
+
over `process.platform` to helpers that now live in `@ac-kit/format-shell`, and
|
|
9
|
+
`node` may not depend on a `format-*` package (`ARCHITECTURE.md` §3).
|
|
10
|
+
|
|
11
|
+
Callers name the dialect instead, deriving it from the platform if that is what
|
|
12
|
+
they want:
|
|
13
|
+
|
|
14
|
+
```ts
|
|
15
|
+
import { escapeCommandArg, shellDialectForPlatform } from "@ac-kit/format-shell";
|
|
16
|
+
|
|
17
|
+
escapeCommandArg(value, shellDialectForPlatform(process.platform));
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
- 70c1269: Rework the `net` socket and server wrappers, and add `TlsServer` / `IpcServer`
|
|
21
|
+
|
|
22
|
+
- Connection helpers now always settle: a socket that closes before connecting
|
|
23
|
+
rejects with the new `ConnectionClosedError` instead of leaving the promise
|
|
24
|
+
pending, and `IpcSocket.connect` accepts an `AbortSignal` like its siblings.
|
|
25
|
+
- `TcpSocket` and `IpcSocket` no longer register their event forwarders twice,
|
|
26
|
+
which made every event dispatch to subscribers twice.
|
|
27
|
+
- New `InetSocket` base class: `TlsSocket` now exposes `remoteEndpoint`,
|
|
28
|
+
`localEndpoint`, `setNoDelay`, `setKeepAlive` and the connection-attempt and
|
|
29
|
+
`lookup` events, previously available on `TcpSocket` only.
|
|
30
|
+
- `TlsSocket.connect` destroys the transport when the handshake fails, so a
|
|
31
|
+
failed `STARTTLS` upgrade can no longer fall back to cleartext. It also
|
|
32
|
+
accepts a local endpoint path, for a TLS server behind a Unix domain socket.
|
|
33
|
+
- `TlsSocket` fixes: `TlsSocketOptions` keeps the secure-context options (`ca`,
|
|
34
|
+
`cert`, `key`, …) that were previously stripped, `getPeerCertificate` is
|
|
35
|
+
overloaded instead of taking an escapable return type parameter, empty
|
|
36
|
+
results are normalized to `null` consistently, `exportKeyingMaterial` takes an
|
|
37
|
+
optional context, `setKeyCert` accepts `SecureContextOptions`, `renegotiate`
|
|
38
|
+
takes its options optionally, and the `servername` and `secure` members are
|
|
39
|
+
exposed. `getTicket()` is renamed `getTLSTicket()` to match Node.js.
|
|
40
|
+
- New `StreamServer` base class with `TcpServer` rebuilt on top of it, plus
|
|
41
|
+
`IpcServer` and `TlsServer`.
|
|
42
|
+
- `IpcSocket.fromFd` adopts an already-open descriptor, such as a pipe
|
|
43
|
+
inherited from a parent process.
|
|
44
|
+
- `IpcSocketEvents` no longer declares the IP-only connection-attempt events,
|
|
45
|
+
which never fired.
|
|
46
|
+
|
|
47
|
+
### Patch Changes
|
|
48
|
+
|
|
49
|
+
- Updated dependencies [a493b4a]
|
|
50
|
+
- Updated dependencies [a493b4a]
|
|
51
|
+
- Updated dependencies [a493b4a]
|
|
52
|
+
- Updated dependencies [2ab5593]
|
|
53
|
+
- Updated dependencies [a493b4a]
|
|
54
|
+
- @ac-kit/core@0.2.0
|
|
55
|
+
- @ac-kit/async@0.1.1
|
package/README.md
CHANGED
|
@@ -23,6 +23,8 @@ await writeFileAtomic("config.json", JSON.stringify(config));
|
|
|
23
23
|
## What it covers
|
|
24
24
|
|
|
25
25
|
- **Sockets** — promise-based TCP, TLS, IPC and UDP classes.
|
|
26
|
+
- **Servers** — promise-based TCP, TLS and IPC listeners, dispatching typed
|
|
27
|
+
connection events.
|
|
26
28
|
- **Filesystem** — `walkPaths`, `writeFileAtomic`, `existsAsync`,
|
|
27
29
|
`isDirectoryAsync`, `fileContentEqual`, `compressFile`, `createTempDir`,
|
|
28
30
|
`escapePath`.
|
package/dist/index.d.ts
CHANGED
|
@@ -16,19 +16,22 @@ export * from "./fs/write-file-atomic.js";
|
|
|
16
16
|
export * from "./module/import-module.js";
|
|
17
17
|
export * from "./module/optional-import.js";
|
|
18
18
|
export * from "./module/resolve-module.js";
|
|
19
|
+
export * from "./net/connection-closed-error.js";
|
|
19
20
|
export * from "./net/dgram-socket.js";
|
|
21
|
+
export * from "./net/inet-socket.js";
|
|
22
|
+
export * from "./net/ipc-server.js";
|
|
20
23
|
export * from "./net/ipc-socket.js";
|
|
24
|
+
export * from "./net/stream-server.js";
|
|
21
25
|
export * from "./net/stream-socket.js";
|
|
22
26
|
export * from "./net/tcp-server.js";
|
|
23
27
|
export * from "./net/tcp-socket.js";
|
|
28
|
+
export * from "./net/tls-server.js";
|
|
24
29
|
export * from "./net/tls-socket.js";
|
|
25
30
|
export * from "./process/fork-process.js";
|
|
26
31
|
export * from "./process/guarded.js";
|
|
27
32
|
export * from "./process/spawn-process.js";
|
|
28
33
|
export * from "./process/spawned-process.js";
|
|
29
34
|
export * from "./process/start-process.js";
|
|
30
|
-
export * from "./shell/escape-command-arg.js";
|
|
31
|
-
export * from "./shell/escape-command.js";
|
|
32
35
|
export * from "./stream/non-closing-writable-stream.js";
|
|
33
36
|
export * from "./stream/write-async.js";
|
|
34
37
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC;AAC9C,cAAc,iCAAiC,CAAC;AAChD,cAAc,uBAAuB,CAAC;AACtC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC;AACnC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,wBAAwB,CAAC;AACvC,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC;AAC9C,cAAc,iCAAiC,CAAC;AAChD,cAAc,uBAAuB,CAAC;AACtC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC;AACnC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,kCAAkC,CAAC;AACjD,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC;AACvC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,sBAAsB,CAAC;AACrC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,yCAAyC,CAAC;AACxD,cAAc,yBAAyB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -16,19 +16,22 @@ export * from "./fs/write-file-atomic.js";
|
|
|
16
16
|
export * from "./module/import-module.js";
|
|
17
17
|
export * from "./module/optional-import.js";
|
|
18
18
|
export * from "./module/resolve-module.js";
|
|
19
|
+
export * from "./net/connection-closed-error.js";
|
|
19
20
|
export * from "./net/dgram-socket.js";
|
|
21
|
+
export * from "./net/inet-socket.js";
|
|
22
|
+
export * from "./net/ipc-server.js";
|
|
20
23
|
export * from "./net/ipc-socket.js";
|
|
24
|
+
export * from "./net/stream-server.js";
|
|
21
25
|
export * from "./net/stream-socket.js";
|
|
22
26
|
export * from "./net/tcp-server.js";
|
|
23
27
|
export * from "./net/tcp-socket.js";
|
|
28
|
+
export * from "./net/tls-server.js";
|
|
24
29
|
export * from "./net/tls-socket.js";
|
|
25
30
|
export * from "./process/fork-process.js";
|
|
26
31
|
export * from "./process/guarded.js";
|
|
27
32
|
export * from "./process/spawn-process.js";
|
|
28
33
|
export * from "./process/spawned-process.js";
|
|
29
34
|
export * from "./process/start-process.js";
|
|
30
|
-
export * from "./shell/escape-command-arg.js";
|
|
31
|
-
export * from "./shell/escape-command.js";
|
|
32
35
|
export * from "./stream/non-closing-writable-stream.js";
|
|
33
36
|
export * from "./stream/write-async.js";
|
|
34
37
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC;AAC9C,cAAc,iCAAiC,CAAC;AAChD,cAAc,uBAAuB,CAAC;AACtC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC;AACnC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,wBAAwB,CAAC;AACvC,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC;AAC9C,cAAc,iCAAiC,CAAC;AAChD,cAAc,uBAAuB,CAAC;AACtC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC;AACnC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,kCAAkC,CAAC;AACjD,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC;AACvC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,sBAAsB,CAAC;AACrC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,yCAAyC,CAAC;AACxD,cAAc,yBAAyB,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error thrown when a socket closes before the operation awaiting it could
|
|
3
|
+
* complete.
|
|
4
|
+
*
|
|
5
|
+
* Node.js usually reports a failed connection or handshake through an "error"
|
|
6
|
+
* event, but a peer that drops the transport can close it without one. This
|
|
7
|
+
* error makes that case observable instead of leaving the caller waiting.
|
|
8
|
+
*/
|
|
9
|
+
export declare class ConnectionClosedError extends Error {
|
|
10
|
+
constructor(message?: string, options?: ErrorOptions);
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=connection-closed-error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connection-closed-error.d.ts","sourceRoot":"","sources":["../../src/net/connection-closed-error.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,qBAAa,qBAAsB,SAAQ,KAAK;IAC/C,YAAY,OAAO,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY,EAInD;CACD"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error thrown when a socket closes before the operation awaiting it could
|
|
3
|
+
* complete.
|
|
4
|
+
*
|
|
5
|
+
* Node.js usually reports a failed connection or handshake through an "error"
|
|
6
|
+
* event, but a peer that drops the transport can close it without one. This
|
|
7
|
+
* error makes that case observable instead of leaving the caller waiting.
|
|
8
|
+
*/
|
|
9
|
+
export class ConnectionClosedError extends Error {
|
|
10
|
+
constructor(message, options) {
|
|
11
|
+
super(message, options);
|
|
12
|
+
this.name = "ConnectionClosedError";
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=connection-closed-error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connection-closed-error.js","sourceRoot":"","sources":["../../src/net/connection-closed-error.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,OAAO,qBAAsB,SAAQ,KAAK;IAC/C,YAAY,OAAgB,EAAE,OAAsB;QACnD,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAExB,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAC;IACrC,CAAC;CACD"}
|
|
@@ -58,7 +58,7 @@ export interface DgramSocketStat {
|
|
|
58
58
|
* ```
|
|
59
59
|
*/
|
|
60
60
|
export declare class DgramSocket extends EventDispatcherMapBase<DgramSocketEvents> implements IEventDispatcherMap<DgramSocketEvents> {
|
|
61
|
-
private readonly
|
|
61
|
+
private readonly socket;
|
|
62
62
|
/** Creates a new `DgramSocket` instance with the specified options. */
|
|
63
63
|
static from(options?: dgram.SocketOptions): DgramSocket;
|
|
64
64
|
private readonly handledErrorEvents;
|
|
@@ -66,7 +66,7 @@ export declare class DgramSocket extends EventDispatcherMapBase<DgramSocketEvent
|
|
|
66
66
|
* Constructs a new `DgramSocket` instance wrapping the provided
|
|
67
67
|
* `dgram.Socket`.
|
|
68
68
|
*/
|
|
69
|
-
constructor(
|
|
69
|
+
constructor(socket: dgram.Socket);
|
|
70
70
|
/**
|
|
71
71
|
* References the socket, preventing the process from exiting while the socket
|
|
72
72
|
* is active.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dgram-socket.d.ts","sourceRoot":"","sources":["../../src/net/dgram-socket.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AAGpC,OAAO,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAC5E,OAAO,EAAsB,YAAY,EAAE,KAAK,MAAM,EAAE,MAAM,cAAc,CAAC;AAC7E,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAIpD,wDAAwD;AACxD,MAAM,MAAM,iBAAiB,GAAG;IAC/B,yCAAyC;IACzC,KAAK,EAAE,EAAE,CAAC;IAEV,0DAA0D;IAC1D,OAAO,EAAE,EAAE,CAAC;IAEZ,oCAAoC;IACpC,KAAK,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IAEvB,wDAAwD;IACxD,SAAS,EAAE,EAAE,CAAC;IAEd;;;;;;OAMG;IACH,OAAO,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,YAAY,CAAC,CAAC;CAC5D,CAAC;AAEF,MAAM,WAAW,eAAe;IAC/B,4DAA4D;IAC5D,cAAc,EAAE,MAAM,CAAC;IAEvB,8DAA8D;IAC9D,aAAa,EAAE,MAAM,CAAC;CACtB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,qBAAa,WACZ,SAAQ,sBAAsB,CAAC,iBAAiB,CAChD,YAAW,mBAAmB,CAAC,iBAAiB,CAAC;IAarC,OAAO,CAAC,QAAQ,CAAC,
|
|
1
|
+
{"version":3,"file":"dgram-socket.d.ts","sourceRoot":"","sources":["../../src/net/dgram-socket.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AAGpC,OAAO,EAAE,s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AAO,CAAC,IAAI,CAAC,CAyBf;IAED;;;;OAIG;IACH,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAarB;IAED;;;;;OAKG;IACH,OAAO,IAAI,eAAe,CAKzB;IAED;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,IAAI,CACH,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,GAAG,EAAE,MAAM,GAAG,UAAU,GAAG,QAAQ,EACnC,MAAM,CAAC,EAAE,MAAM,EACf,MAAM,CAAC,EAAE,MAAM,GACb,OAAO,CAAC,MAAM,CAAC,CAiBjB;IAED,OAAO,CAAC,oBAAoB;CA6B5B"}
|
package/dist/net/dgram-socket.js
CHANGED
|
@@ -33,7 +33,7 @@ import { isNodeErrorWithCode } from "../error/node-error.js";
|
|
|
33
33
|
* ```
|
|
34
34
|
*/
|
|
35
35
|
export class DgramSocket extends EventDispatcherMapBase {
|
|
36
|
-
|
|
36
|
+
socket;
|
|
37
37
|
/** Creates a new `DgramSocket` instance with the specified options. */
|
|
38
38
|
static from(options) {
|
|
39
39
|
return new DgramSocket(dgram.createSocket(options || { type: "udp4" }));
|
|
@@ -43,9 +43,9 @@ export class DgramSocket extends EventDispatcherMapBase {
|
|
|
43
43
|
* Constructs a new `DgramSocket` instance wrapping the provided
|
|
44
44
|
* `dgram.Socket`.
|
|
45
45
|
*/
|
|
46
|
-
constructor(
|
|
46
|
+
constructor(socket) {
|
|
47
47
|
super();
|
|
48
|
-
this.
|
|
48
|
+
this.socket = socket;
|
|
49
49
|
this.setupEventForwarding();
|
|
50
50
|
}
|
|
51
51
|
/**
|
|
@@ -53,14 +53,14 @@ export class DgramSocket extends EventDispatcherMapBase {
|
|
|
53
53
|
* is active.
|
|
54
54
|
*/
|
|
55
55
|
ref() {
|
|
56
|
-
this.
|
|
56
|
+
this.socket.ref();
|
|
57
57
|
}
|
|
58
58
|
/**
|
|
59
59
|
* Unreferences the socket, allowing the process to exit even if the socket is
|
|
60
60
|
* active.
|
|
61
61
|
*/
|
|
62
62
|
unref() {
|
|
63
|
-
this.
|
|
63
|
+
this.socket.unref();
|
|
64
64
|
}
|
|
65
65
|
/**
|
|
66
66
|
* Enables or disables sending of broadcast datagrams.
|
|
@@ -72,7 +72,7 @@ export class DgramSocket extends EventDispatcherMapBase {
|
|
|
72
72
|
* @param flag Whether broadcast should be enabled.
|
|
73
73
|
*/
|
|
74
74
|
setBroadcast(flag) {
|
|
75
|
-
this.
|
|
75
|
+
this.socket.setBroadcast(flag);
|
|
76
76
|
}
|
|
77
77
|
/**
|
|
78
78
|
* Adds this socket to the given multicast group.
|
|
@@ -81,7 +81,7 @@ export class DgramSocket extends EventDispatcherMapBase {
|
|
|
81
81
|
* configures `IP_ADD_MEMBERSHIP` for the given multicast group.
|
|
82
82
|
*/
|
|
83
83
|
addMembership(multicastAddress, multicastInterface) {
|
|
84
|
-
this.
|
|
84
|
+
this.socket.addMembership(multicastAddress, multicastInterface);
|
|
85
85
|
}
|
|
86
86
|
/**
|
|
87
87
|
* Sets the size in bytes of the underlying receive buffer.
|
|
@@ -90,7 +90,7 @@ export class DgramSocket extends EventDispatcherMapBase {
|
|
|
90
90
|
* sets the `SO_RCVBUF` socket option.
|
|
91
91
|
*/
|
|
92
92
|
setRecvBufferSize(size) {
|
|
93
|
-
this.
|
|
93
|
+
this.socket.setRecvBufferSize(size);
|
|
94
94
|
}
|
|
95
95
|
/**
|
|
96
96
|
* Returns the size in bytes of the underlying receive buffer.
|
|
@@ -99,7 +99,7 @@ export class DgramSocket extends EventDispatcherMapBase {
|
|
|
99
99
|
* reads the `SO_RCVBUF` socket option.
|
|
100
100
|
*/
|
|
101
101
|
getRecvBufferSize() {
|
|
102
|
-
return this.
|
|
102
|
+
return this.socket.getRecvBufferSize();
|
|
103
103
|
}
|
|
104
104
|
/**
|
|
105
105
|
* Sets the size in bytes of the underlying send buffer.
|
|
@@ -108,7 +108,7 @@ export class DgramSocket extends EventDispatcherMapBase {
|
|
|
108
108
|
* sets the `SO_SNDBUF` socket option.
|
|
109
109
|
*/
|
|
110
110
|
setSendBufferSize(size) {
|
|
111
|
-
this.
|
|
111
|
+
this.socket.setSendBufferSize(size);
|
|
112
112
|
}
|
|
113
113
|
/**
|
|
114
114
|
* Returns the size in bytes of the underlying send buffer.
|
|
@@ -117,7 +117,7 @@ export class DgramSocket extends EventDispatcherMapBase {
|
|
|
117
117
|
* reads the `SO_SNDBUF` socket option.
|
|
118
118
|
*/
|
|
119
119
|
getSendBufferSize() {
|
|
120
|
-
return this.
|
|
120
|
+
return this.socket.getSendBufferSize();
|
|
121
121
|
}
|
|
122
122
|
/**
|
|
123
123
|
* Removes this socket from the given multicast group.
|
|
@@ -126,7 +126,7 @@ export class DgramSocket extends EventDispatcherMapBase {
|
|
|
126
126
|
* configures `IP_DROP_MEMBERSHIP` for the given multicast group.
|
|
127
127
|
*/
|
|
128
128
|
dropMembership(multicastAddress, multicastInterface) {
|
|
129
|
-
this.
|
|
129
|
+
this.socket.dropMembership(multicastAddress, multicastInterface);
|
|
130
130
|
}
|
|
131
131
|
/**
|
|
132
132
|
* Adds this socket to a source-specific multicast group.
|
|
@@ -136,7 +136,7 @@ export class DgramSocket extends EventDispatcherMapBase {
|
|
|
136
136
|
* source-specific multicast membership for the given source and group.
|
|
137
137
|
*/
|
|
138
138
|
addSourceMembership(sourceAddress, groupAddress, multicastInterface) {
|
|
139
|
-
this.
|
|
139
|
+
this.socket.addSourceSpecificMembership(sourceAddress, groupAddress, multicastInterface);
|
|
140
140
|
}
|
|
141
141
|
/**
|
|
142
142
|
* Removes this socket from a source-specific multicast group.
|
|
@@ -146,7 +146,7 @@ export class DgramSocket extends EventDispatcherMapBase {
|
|
|
146
146
|
* multicast membership for the given source and group.
|
|
147
147
|
*/
|
|
148
148
|
dropSourceMembership(sourceAddress, groupAddress, multicastInterface) {
|
|
149
|
-
this.
|
|
149
|
+
this.socket.dropSourceSpecificMembership(sourceAddress, groupAddress, multicastInterface);
|
|
150
150
|
}
|
|
151
151
|
/**
|
|
152
152
|
* Sets the outbound multicast interface.
|
|
@@ -155,7 +155,7 @@ export class DgramSocket extends EventDispatcherMapBase {
|
|
|
155
155
|
* which controls the default outgoing interface for multicast traffic.
|
|
156
156
|
*/
|
|
157
157
|
setMulticastInterface(multicastInterface) {
|
|
158
|
-
this.
|
|
158
|
+
this.socket.setMulticastInterface(multicastInterface);
|
|
159
159
|
}
|
|
160
160
|
/**
|
|
161
161
|
* Enables or disables loopback for multicast packets sent from this socket.
|
|
@@ -164,7 +164,7 @@ export class DgramSocket extends EventDispatcherMapBase {
|
|
|
164
164
|
* which toggles the `IP_MULTICAST_LOOP` socket option.
|
|
165
165
|
*/
|
|
166
166
|
setMulticastLoop(flag) {
|
|
167
|
-
this.
|
|
167
|
+
this.socket.setMulticastLoopback(flag);
|
|
168
168
|
}
|
|
169
169
|
/**
|
|
170
170
|
* Sets the time-to-live (TTL) value for multicast packets.
|
|
@@ -173,7 +173,7 @@ export class DgramSocket extends EventDispatcherMapBase {
|
|
|
173
173
|
* configures the `IP_MULTICAST_TTL` socket option.
|
|
174
174
|
*/
|
|
175
175
|
setMulticastTtl(ttl) {
|
|
176
|
-
this.
|
|
176
|
+
this.socket.setMulticastTTL(ttl);
|
|
177
177
|
}
|
|
178
178
|
/**
|
|
179
179
|
* Sets the unicast time-to-live (TTL) value for outgoing packets.
|
|
@@ -182,7 +182,7 @@ export class DgramSocket extends EventDispatcherMapBase {
|
|
|
182
182
|
* the `IP_TTL` socket option.
|
|
183
183
|
*/
|
|
184
184
|
setTtl(ttl) {
|
|
185
|
-
this.
|
|
185
|
+
this.socket.setTTL(ttl);
|
|
186
186
|
}
|
|
187
187
|
/**
|
|
188
188
|
* Gets the address information of the bound socket.
|
|
@@ -195,7 +195,7 @@ export class DgramSocket extends EventDispatcherMapBase {
|
|
|
195
195
|
address() {
|
|
196
196
|
let addr;
|
|
197
197
|
try {
|
|
198
|
-
addr = this.
|
|
198
|
+
addr = this.socket.address();
|
|
199
199
|
}
|
|
200
200
|
catch (error) {
|
|
201
201
|
// dgram throws "Not running" error when socket is not bound/closed
|
|
@@ -226,19 +226,19 @@ export class DgramSocket extends EventDispatcherMapBase {
|
|
|
226
226
|
this.handledErrorEvents.add(error);
|
|
227
227
|
reject(error);
|
|
228
228
|
};
|
|
229
|
-
this.
|
|
229
|
+
this.socket.prependOnceListener("error", handleError);
|
|
230
230
|
try {
|
|
231
|
-
this.
|
|
231
|
+
this.socket.bind({
|
|
232
232
|
...options,
|
|
233
233
|
address,
|
|
234
234
|
port,
|
|
235
235
|
}, () => {
|
|
236
|
-
this.
|
|
236
|
+
this.socket.removeListener("error", handleError);
|
|
237
237
|
resolve();
|
|
238
238
|
});
|
|
239
239
|
}
|
|
240
240
|
catch (error) {
|
|
241
|
-
this.
|
|
241
|
+
this.socket.removeListener("error", handleError);
|
|
242
242
|
reject(error);
|
|
243
243
|
}
|
|
244
244
|
});
|
|
@@ -254,9 +254,9 @@ export class DgramSocket extends EventDispatcherMapBase {
|
|
|
254
254
|
this.handledErrorEvents.add(error);
|
|
255
255
|
reject(error);
|
|
256
256
|
};
|
|
257
|
-
this.
|
|
258
|
-
this.
|
|
259
|
-
this.
|
|
257
|
+
this.socket.prependOnceListener("error", handleError);
|
|
258
|
+
this.socket.close(() => {
|
|
259
|
+
this.socket.removeListener("error", handleError);
|
|
260
260
|
resolve();
|
|
261
261
|
});
|
|
262
262
|
});
|
|
@@ -269,8 +269,8 @@ export class DgramSocket extends EventDispatcherMapBase {
|
|
|
269
269
|
*/
|
|
270
270
|
getStat() {
|
|
271
271
|
return {
|
|
272
|
-
sendQueueCount: this.
|
|
273
|
-
sendQueueSize: this.
|
|
272
|
+
sendQueueCount: this.socket.getSendQueueCount(),
|
|
273
|
+
sendQueueSize: this.socket.getSendQueueSize(),
|
|
274
274
|
};
|
|
275
275
|
}
|
|
276
276
|
/**
|
|
@@ -306,30 +306,30 @@ export class DgramSocket extends EventDispatcherMapBase {
|
|
|
306
306
|
resolve(bytes);
|
|
307
307
|
};
|
|
308
308
|
if (offset === undefined || length === undefined) {
|
|
309
|
-
this.
|
|
309
|
+
this.socket.send(msg, port, address, callback);
|
|
310
310
|
return;
|
|
311
311
|
}
|
|
312
|
-
this.
|
|
312
|
+
this.socket.send(msg, offset, length, port, address, callback);
|
|
313
313
|
});
|
|
314
314
|
}
|
|
315
315
|
setupEventForwarding() {
|
|
316
|
-
this.
|
|
316
|
+
this.socket.on("close", () => {
|
|
317
317
|
this.dispatch("close", []);
|
|
318
318
|
});
|
|
319
|
-
this.
|
|
319
|
+
this.socket.on("connect", () => {
|
|
320
320
|
this.dispatch("connect", []);
|
|
321
321
|
});
|
|
322
|
-
this.
|
|
322
|
+
this.socket.on("error", (err) => {
|
|
323
323
|
if (this.handledErrorEvents.has(err)) {
|
|
324
324
|
this.handledErrorEvents.delete(err);
|
|
325
325
|
return;
|
|
326
326
|
}
|
|
327
327
|
this.dispatch("error", [err]);
|
|
328
328
|
});
|
|
329
|
-
this.
|
|
329
|
+
this.socket.on("listening", () => {
|
|
330
330
|
this.dispatch("listening", []);
|
|
331
331
|
});
|
|
332
|
-
this.
|
|
332
|
+
this.socket.on("message", (msg, rinfo) => {
|
|
333
333
|
const from = {
|
|
334
334
|
...composeInetAddress(rinfo.family, rinfo.address),
|
|
335
335
|
port: rinfo.port,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dgram-socket.js","sourceRoot":"","sources":["../../src/net/dgram-socket.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AAGpC,OAAO,EAAE,sBAAsB,EAAuB,MAAM,eAAe,CAAC;AAC5E,OAAO,EAAE,kBAAkB,EAA6B,MAAM,cAAc,CAAC;AAG7E,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAkC7D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,OAAO,WACZ,SAAQ,sBAAyC;IAcpB,
|
|
1
|
+
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,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,SAAS,EAAE,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE;YACxC,MAAM,IAAI,GAAiB;gBAC1B,GAAG,kBAAkB,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,OAAO,CAAC;gBAClD,IAAI,EAAE,KAAK,CAAC,IAAI;aAChB,CAAC;YACF,IAAI,CAAC,QAAQ,CAAC,SAAS,EAAE,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;QACnD,CAAC,CAAC,CAAC;IACJ,CAAC;CACD"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import * as net from "node:net";
|
|
2
|
+
import { type InetAddress, type InetEndpoint } from "@ac-kit/core";
|
|
3
|
+
import { StreamSocket, type StreamSocketEvents } from "./stream-socket.js";
|
|
4
|
+
/** Event map for sockets running over an IP transport. */
|
|
5
|
+
export type InetSocketEvents = StreamSocketEvents & {
|
|
6
|
+
/**
|
|
7
|
+
* Emitted when a new connection attempt is started. May be emitted multiple
|
|
8
|
+
* times if family autoselection is enabled.
|
|
9
|
+
*/
|
|
10
|
+
connectionAttempt: [endpoint: InetEndpoint];
|
|
11
|
+
/**
|
|
12
|
+
* Emitted when a connection attempt failed. May be emitted multiple times if
|
|
13
|
+
* family autoselection is enabled.
|
|
14
|
+
*/
|
|
15
|
+
connectionAttemptFailed: [endpoint: InetEndpoint, error: Error];
|
|
16
|
+
/**
|
|
17
|
+
* Emitted when a connection attempt timed out. May be emitted multiple times
|
|
18
|
+
* if family autoselection is enabled.
|
|
19
|
+
*/
|
|
20
|
+
connectionAttemptTimeout: [endpoint: InetEndpoint];
|
|
21
|
+
/** Emitted after resolving the host name but before connecting. */
|
|
22
|
+
lookup: [error: Error | null, address: InetAddress, host: string];
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Base class for sockets whose transport is an IP connection.
|
|
26
|
+
*
|
|
27
|
+
* On top of {@link StreamSocket} it exposes the endpoint accessors and the
|
|
28
|
+
* socket options that only make sense over IP, plus the connection-attempt and
|
|
29
|
+
* name-resolution events Node.js emits while dialling.
|
|
30
|
+
*
|
|
31
|
+
* It is shared by {@link TcpSocket} and {@link TlsSocket}: both run over IP, but
|
|
32
|
+
* they establish their connection differently, so neither can be expressed as a
|
|
33
|
+
* subclass of the other.
|
|
34
|
+
*/
|
|
35
|
+
export declare class InetSocket<TSocket extends net.Socket = net.Socket, TEvents extends InetSocketEvents = InetSocketEvents> extends StreamSocket<TSocket, TEvents> {
|
|
36
|
+
/**
|
|
37
|
+
* Remote endpoint of the socket, or `null` while it is not connected.
|
|
38
|
+
*
|
|
39
|
+
* @throws {UnsupportedError} If the socket family is not IPv4 or IPv6.
|
|
40
|
+
*/
|
|
41
|
+
get remoteEndpoint(): InetEndpoint | null;
|
|
42
|
+
/**
|
|
43
|
+
* Local endpoint of the socket, or `null` while it is not connected.
|
|
44
|
+
*
|
|
45
|
+
* @throws {UnsupportedError} If the socket family is not IPv4 or IPv6.
|
|
46
|
+
*/
|
|
47
|
+
get localEndpoint(): InetEndpoint | null;
|
|
48
|
+
/**
|
|
49
|
+
* Sets the keep-alive option for the socket.
|
|
50
|
+
*
|
|
51
|
+
* @param enable Whether to enable keep-alive.
|
|
52
|
+
* @param initialDelay The initial delay in milliseconds before the first
|
|
53
|
+
* keep-alive probe.
|
|
54
|
+
*/
|
|
55
|
+
setKeepAlive(enable: boolean, initialDelay?: number): void;
|
|
56
|
+
/**
|
|
57
|
+
* Enables or disables the Nagle algorithm for the socket.
|
|
58
|
+
*
|
|
59
|
+
* @param noDelay Whether to disable the Nagle algorithm.
|
|
60
|
+
*/
|
|
61
|
+
setNoDelay(noDelay: boolean): void;
|
|
62
|
+
protected setupEventForwarding(): void;
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=inet-socket.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inet-socket.d.ts","sourceRo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
|
|
|
1
|
+
import { composeInetAddress, } from "@ac-kit/core";
|
|
2
|
+
import { StreamSocket } from "./stream-socket.js";
|
|
3
|
+
/**
|
|
4
|
+
* Base class for sockets whose transport is an IP connection.
|
|
5
|
+
*
|
|
6
|
+
* On top of {@link StreamSocket} it exposes the endpoint accessors and the
|
|
7
|
+
* socket options that only make sense over IP, plus the connection-attempt and
|
|
8
|
+
* name-resolution events Node.js emits while dialling.
|
|
9
|
+
*
|
|
10
|
+
* It is shared by {@link TcpSocket} and {@link TlsSocket}: both run over IP, but
|
|
11
|
+
* they establish their connection differently, so neither can be expressed as a
|
|
12
|
+
* subclass of the other.
|
|
13
|
+
*/
|
|
14
|
+
export class InetSocket extends StreamSocket {
|
|
15
|
+
/**
|
|
16
|
+
* Remote endpoint of the socket, or `null` while it is not connected.
|
|
17
|
+
*
|
|
18
|
+
* @throws {UnsupportedError} If the socket family is not IPv4 or IPv6.
|
|
19
|
+
*/
|
|
20
|
+
get remoteEndpoint() {
|
|
21
|
+
const address = this.socket.remoteAddress;
|
|
22
|
+
const port = this.socket.remotePort;
|
|
23
|
+
const family = this.socket.remoteFamily;
|
|
24
|
+
if (address === undefined || port === undefined || family === undefined) {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
...composeInetAddress(family, address),
|
|
29
|
+
port,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Local endpoint of the socket, or `null` while it is not connected.
|
|
34
|
+
*
|
|
35
|
+
* @throws {UnsupportedError} If the socket family is not IPv4 or IPv6.
|
|
36
|
+
*/
|
|
37
|
+
get localEndpoint() {
|
|
38
|
+
const address = this.socket.localAddress;
|
|
39
|
+
const port = this.socket.localPort;
|
|
40
|
+
const family = this.socket.localFamily;
|
|
41
|
+
if (address === undefined || port === undefined || family === undefined) {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
...composeInetAddress(family, address),
|
|
46
|
+
port,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Sets the keep-alive option for the socket.
|
|
51
|
+
*
|
|
52
|
+
* @param enable Whether to enable keep-alive.
|
|
53
|
+
* @param initialDelay The initial delay in milliseconds before the first
|
|
54
|
+
* keep-alive probe.
|
|
55
|
+
*/
|
|
56
|
+
setKeepAlive(enable, initialDelay) {
|
|
57
|
+
this.socket.setKeepAlive(enable, initialDelay);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Enables or disables the Nagle algorithm for the socket.
|
|
61
|
+
*
|
|
62
|
+
* @param noDelay Whether to disable the Nagle algorithm.
|
|
63
|
+
*/
|
|
64
|
+
setNoDelay(noDelay) {
|
|
65
|
+
this.socket.setNoDelay(noDelay);
|
|
66
|
+
}
|
|
67
|
+
setupEventForwarding() {
|
|
68
|
+
super.setupEventForwarding();
|
|
69
|
+
this.socket.on("connectionAttempt", (ip, port, family) => {
|
|
70
|
+
this.dispatch("connectionAttempt", [
|
|
71
|
+
{
|
|
72
|
+
...composeInetAddress(family, ip),
|
|
73
|
+
port,
|
|
74
|
+
},
|
|
75
|
+
]);
|
|
76
|
+
});
|
|
77
|
+
this.socket.on("connectionAttemptFailed", (ip, port, family, error) => {
|
|
78
|
+
this.dispatch("connectionAttemptFailed", [
|
|
79
|
+
{
|
|
80
|
+
...composeInetAddress(family, ip),
|
|
81
|
+
port,
|
|
82
|
+
},
|
|
83
|
+
error,
|
|
84
|
+
]);
|
|
85
|
+
});
|
|
86
|
+
this.socket.on("connectionAttemptTimeout", (ip, port, family) => {
|
|
87
|
+
this.dispatch("connectionAttemptTimeout", [
|
|
88
|
+
{
|
|
89
|
+
...composeInetAddress(family, ip),
|
|
90
|
+
port,
|
|
91
|
+
},
|
|
92
|
+
]);
|
|
93
|
+
});
|
|
94
|
+
this.socket.on("lookup", (error, address, family, host) => {
|
|
95
|
+
this.dispatch("lookup", [
|
|
96
|
+
error,
|
|
97
|
+
composeInetAddress(family, address),
|
|
98
|
+
host,
|
|
99
|
+
]);
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=inet-socket.js.map
|