@ac-kit/node 0.1.0 → 0.3.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 +94 -0
- package/README.md +7 -2
- package/dist/error/process-exit-error.d.ts +16 -3
- package/dist/error/process-exit-error.d.ts.map +1 -1
- package/dist/error/process-exit-error.js +51 -7
- package/dist/error/process-exit-error.js.map +1 -1
- package/dist/fs/path-escape-error.d.ts +20 -0
- package/dist/fs/path-escape-error.d.ts.map +1 -0
- package/dist/fs/path-escape-error.js +23 -0
- package/dist/fs/path-escape-error.js.map +1 -0
- package/dist/fs/path-within.d.ts +121 -0
- package/dist/fs/path-within.d.ts.map +1 -0
- package/dist/fs/path-within.js +196 -0
- package/dist/fs/path-within.js.map +1 -0
- package/dist/index.d.ts +9 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -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 +4 -3
- package/dist/net/dgram-socket.d.ts.map +1 -1
- package/dist/net/dgram-socket.js +38 -38
- package/dist/net/dgram-socket.js.map +1 -1
- package/dist/net/inet-address.d.ts +20 -0
- package/dist/net/inet-address.d.ts.map +1 -0
- package/dist/net/inet-address.js +42 -0
- package/dist/net/inet-address.js.map +1 -0
- package/dist/net/inet-endpoint.d.ts +7 -0
- package/dist/net/inet-endpoint.d.ts.map +1 -0
- package/dist/net/inet-endpoint.js +2 -0
- package/dist/net/inet-endpoint.js.map +1 -0
- package/dist/net/inet-socket.d.ts +65 -0
- package/dist/net/inet-socket.d.ts.map +1 -0
- package/dist/net/inet-socket.js +99 -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 +45 -150
- 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/dist/index.d.ts
CHANGED
|
@@ -10,25 +10,32 @@ export * from "./fs/escape-path.js";
|
|
|
10
10
|
export * from "./fs/exists-async.js";
|
|
11
11
|
export * from "./fs/file-content-equal.js";
|
|
12
12
|
export * from "./fs/is-directory-async.js";
|
|
13
|
+
export * from "./fs/path-escape-error.js";
|
|
14
|
+
export * from "./fs/path-within.js";
|
|
13
15
|
export * from "./fs/types.js";
|
|
14
16
|
export * from "./fs/walk-paths.js";
|
|
15
17
|
export * from "./fs/write-file-atomic.js";
|
|
16
18
|
export * from "./module/import-module.js";
|
|
17
19
|
export * from "./module/optional-import.js";
|
|
18
20
|
export * from "./module/resolve-module.js";
|
|
21
|
+
export * from "./net/connection-closed-error.js";
|
|
19
22
|
export * from "./net/dgram-socket.js";
|
|
23
|
+
export * from "./net/inet-address.js";
|
|
24
|
+
export * from "./net/inet-endpoint.js";
|
|
25
|
+
export * from "./net/inet-socket.js";
|
|
26
|
+
export * from "./net/ipc-server.js";
|
|
20
27
|
export * from "./net/ipc-socket.js";
|
|
28
|
+
export * from "./net/stream-server.js";
|
|
21
29
|
export * from "./net/stream-socket.js";
|
|
22
30
|
export * from "./net/tcp-server.js";
|
|
23
31
|
export * from "./net/tcp-socket.js";
|
|
32
|
+
export * from "./net/tls-server.js";
|
|
24
33
|
export * from "./net/tls-socket.js";
|
|
25
34
|
export * from "./process/fork-process.js";
|
|
26
35
|
export * from "./process/guarded.js";
|
|
27
36
|
export * from "./process/spawn-process.js";
|
|
28
37
|
export * from "./process/spawned-process.js";
|
|
29
38
|
export * from "./process/start-process.js";
|
|
30
|
-
export * from "./shell/escape-command-arg.js";
|
|
31
|
-
export * from "./shell/escape-command.js";
|
|
32
39
|
export * from "./stream/non-closing-writable-stream.js";
|
|
33
40
|
export * from "./stream/write-async.js";
|
|
34
41
|
//# 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;A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AAwB,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
|
@@ -10,25 +10,32 @@ export * from "./fs/escape-path.js";
|
|
|
10
10
|
export * from "./fs/exists-async.js";
|
|
11
11
|
export * from "./fs/file-content-equal.js";
|
|
12
12
|
export * from "./fs/is-directory-async.js";
|
|
13
|
+
export * from "./fs/path-escape-error.js";
|
|
14
|
+
export * from "./fs/path-within.js";
|
|
13
15
|
export * from "./fs/types.js";
|
|
14
16
|
export * from "./fs/walk-paths.js";
|
|
15
17
|
export * from "./fs/write-file-atomic.js";
|
|
16
18
|
export * from "./module/import-module.js";
|
|
17
19
|
export * from "./module/optional-import.js";
|
|
18
20
|
export * from "./module/resolve-module.js";
|
|
21
|
+
export * from "./net/connection-closed-error.js";
|
|
19
22
|
export * from "./net/dgram-socket.js";
|
|
23
|
+
export * from "./net/inet-address.js";
|
|
24
|
+
export * from "./net/inet-endpoint.js";
|
|
25
|
+
export * from "./net/inet-socket.js";
|
|
26
|
+
export * from "./net/ipc-server.js";
|
|
20
27
|
export * from "./net/ipc-socket.js";
|
|
28
|
+
export * from "./net/stream-server.js";
|
|
21
29
|
export * from "./net/stream-socket.js";
|
|
22
30
|
export * from "./net/tcp-server.js";
|
|
23
31
|
export * from "./net/tcp-socket.js";
|
|
32
|
+
export * from "./net/tls-server.js";
|
|
24
33
|
export * from "./net/tls-socket.js";
|
|
25
34
|
export * from "./process/fork-process.js";
|
|
26
35
|
export * from "./process/guarded.js";
|
|
27
36
|
export * from "./process/spawn-process.js";
|
|
28
37
|
export * from "./process/spawned-process.js";
|
|
29
38
|
export * from "./process/start-process.js";
|
|
30
|
-
export * from "./shell/escape-command-arg.js";
|
|
31
|
-
export * from "./shell/escape-command.js";
|
|
32
39
|
export * from "./stream/non-closing-writable-stream.js";
|
|
33
40
|
export * from "./stream/write-async.js";
|
|
34
41
|
//# 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,
|
|
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,2BAA2B,CAAC;AAC1C,cAAc,qBAAqB,CAAC;AACpC,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,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC;AACvC,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"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import * as dgram from "node:dgram";
|
|
2
2
|
import { EventDispatcherMapBase, IEventDispatcherMap } from "@ac-kit/async";
|
|
3
|
-
import {
|
|
3
|
+
import type { IError } from "@ac-kit/core";
|
|
4
4
|
import type { Except, TypedArray } from "type-fest";
|
|
5
|
+
import type { InetEndpoint } from "./inet-endpoint.js";
|
|
5
6
|
/** Event map for DgramSocket socket-specific events. */
|
|
6
7
|
export type DgramSocketEvents = {
|
|
7
8
|
/** Emitted when the socket is closed. */
|
|
@@ -58,7 +59,7 @@ export interface DgramSocketStat {
|
|
|
58
59
|
* ```
|
|
59
60
|
*/
|
|
60
61
|
export declare class DgramSocket extends EventDispatcherMapBase<DgramSocketEvents> implements IEventDispatcherMap<DgramSocketEvents> {
|
|
61
|
-
private readonly
|
|
62
|
+
private readonly socket;
|
|
62
63
|
/** Creates a new `DgramSocket` instance with the specified options. */
|
|
63
64
|
static from(options?: dgram.SocketOptions): DgramSocket;
|
|
64
65
|
private readonly handledErrorEvents;
|
|
@@ -66,7 +67,7 @@ export declare class DgramSocket extends EventDispatcherMapBase<DgramSocketEvent
|
|
|
66
67
|
* Constructs a new `DgramSocket` instance wrapping the provided
|
|
67
68
|
* `dgram.Socket`.
|
|
68
69
|
*/
|
|
69
|
-
constructor(
|
|
70
|
+
constructor(socket: dgram.Socket);
|
|
70
71
|
/**
|
|
71
72
|
* References the socket, preventing the process from exiting while the socket
|
|
72
73
|
* 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,
|
|
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,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAIpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEvD,w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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
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as dgram from "node:dgram";
|
|
2
2
|
import { EventDispatcherMapBase } from "@ac-kit/async";
|
|
3
|
-
import { composeInetAddress } from "@ac-kit/core";
|
|
4
3
|
import { isNodeErrorWithCode } from "../error/node-error.js";
|
|
4
|
+
import { toInetAddress } from "./inet-address.js";
|
|
5
5
|
/**
|
|
6
6
|
* High-level wrapper around Node.js
|
|
7
7
|
* {@link dgram.Socket | UDP datagram sockets}.
|
|
@@ -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
|
|
@@ -206,7 +206,7 @@ export class DgramSocket extends EventDispatcherMapBase {
|
|
|
206
206
|
throw error;
|
|
207
207
|
}
|
|
208
208
|
return {
|
|
209
|
-
...
|
|
209
|
+
...toInetAddress(addr.family, addr.address),
|
|
210
210
|
port: addr.port,
|
|
211
211
|
};
|
|
212
212
|
}
|
|
@@ -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,32 +306,32 @@ 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
|
+
...toInetAddress(rinfo.family, rinfo.address),
|
|
335
335
|
port: rinfo.port,
|
|
336
336
|
};
|
|
337
337
|
this.dispatch("message", [msg, rinfo.size, from]);
|
|
@@ -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;
|
|
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;AAI5E,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAmClD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,OAAO,WACZ,SAAQ,sBAAyC;IAcpB,MAAM;IAXnC,uEAAuE;IACvE,MAAM,CAAC,IAAI,CAAC,OAA6B;QACxC,OAAO,IAAI,WAAW,CAAC,KAAK,CAAC,YAAY,CAAC,OAAO,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC;IACzE,CAAC;IAEgB,kBAAkB,GAAgB,IAAI,GAAG,EAAE,CAAC;IAE7D;;;OAGG;IACH,YAA6B,MAAoB;QAChD,KAAK,EAAE,CAAC;sBADoB,MAAM;QAElC,IAAI,CAAC,oBAAoB,EAAE,CAAC;IAC7B,CAAC;IAED;;;OAGG;IACH,GAAG;QACF,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC;IACnB,CAAC;IAED;;;OAGG;IACH,KAAK;QACJ,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IACrB,CAAC;IAED;;;;;;;;OAQG;IACH,YAAY,CAAC,IAAa;QACzB,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;IAChC,CAAC;IAED;;;;;OAKG;IACH,aAAa,CAAC,gBAAwB,EAAE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/B,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,WAAW,EAAE,GAAG,EAAE;YAChC,IAAI,CAAC,QAAQ,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;QAChC,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,SAAS,EAAE,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE;YACxC,MAAM,IAAI,GAAiB;gBAC1B,GAAG,aAAa,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,OAAO,CAAC;gBAC7C,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,20 @@
|
|
|
1
|
+
/** Represents an Internet address with IP family and address. */
|
|
2
|
+
export type InetAddress = {
|
|
3
|
+
/** IP family: 4 for IPv4, 6 for IPv6, or null for unknown family. */
|
|
4
|
+
family: 4 | 6 | null;
|
|
5
|
+
/** IP address string. */
|
|
6
|
+
address: string;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Normalizes a family and address into an InetAddress. Validates and converts
|
|
10
|
+
* the family to ensure it is 4, 6, or null.
|
|
11
|
+
*
|
|
12
|
+
* @param family The IP family, either as a string ('IPv4', 'IPv6'), number (4,
|
|
13
|
+
* 6), or null for unknown.
|
|
14
|
+
* @param address The IP address string.
|
|
15
|
+
* @returns An InetAddress object.
|
|
16
|
+
* @throws {UnsupportedError} If the family is not valid (not 'IPv4'/'IPv6' or
|
|
17
|
+
* 4/6 or null).
|
|
18
|
+
*/
|
|
19
|
+
export declare function toInetAddress(family: string | number | null, address: string): InetAddress;
|
|
20
|
+
//# sourceMappingURL=inet-address.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inet-address.d.ts","sourceRoot":"","sources":["../../src/net/inet-address.ts"],"names":[],"mappings":"AAEA,iEAAiE;AACjE,MAAM,MAAM,WAAW,GAAG;IACzB,qEAAqE;IACrE,MAAM,EAAE,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;IACrB,yBAAyB;IACzB,OAAO,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF;;;;;;;;;;GAUG;AACH,wBAAgB,aAAa,CAC5B,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,EAC9B,OAAO,EAAE,MAAM,GACb,WAAW,CA6Bb"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { UnsupportedError } from "@ac-kit/core";
|
|
2
|
+
/**
|
|
3
|
+
* Normalizes a family and address into an InetAddress. Validates and converts
|
|
4
|
+
* the family to ensure it is 4, 6, or null.
|
|
5
|
+
*
|
|
6
|
+
* @param family The IP family, either as a string ('IPv4', 'IPv6'), number (4,
|
|
7
|
+
* 6), or null for unknown.
|
|
8
|
+
* @param address The IP address string.
|
|
9
|
+
* @returns An InetAddress object.
|
|
10
|
+
* @throws {UnsupportedError} If the family is not valid (not 'IPv4'/'IPv6' or
|
|
11
|
+
* 4/6 or null).
|
|
12
|
+
*/
|
|
13
|
+
export function toInetAddress(family, address) {
|
|
14
|
+
let validatedFamily;
|
|
15
|
+
if (typeof family === "string") {
|
|
16
|
+
if (family === "IPv4") {
|
|
17
|
+
validatedFamily = 4;
|
|
18
|
+
}
|
|
19
|
+
else if (family === "IPv6") {
|
|
20
|
+
validatedFamily = 6;
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
throw new UnsupportedError(`Unsupported IP family: ${family}. Expected 'IPv4' or 'IPv6'.`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
else if (typeof family === "number") {
|
|
27
|
+
if (family === 4 || family === 6) {
|
|
28
|
+
validatedFamily = family;
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
throw new UnsupportedError(`Unsupported IP family: ${family}. Expected 4 (IPv4) or 6 (IPv6).`);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
validatedFamily = null;
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
family: validatedFamily,
|
|
39
|
+
address,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=inet-address.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inet-address.js","sourceRoot":"","sources":["../../src/net/inet-address.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAUhD;;;;;;;;;;GAUG;AACH,MAAM,UAAU,aAAa,CAC5B,MAA8B,EAC9B,OAAe;IAEf,IAAI,eAA6B,CAAC;IAElC,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;QAChC,IAAI,MAAM,KAAK,MAAM,EAAE,CAAC;YACvB,eAAe,GAAG,CAAC,CAAC;QACrB,CAAC;aAAM,IAAI,MAAM,KAAK,MAAM,EAAE,CAAC;YAC9B,eAAe,GAAG,CAAC,CAAC;QACrB,CAAC;aAAM,CAAC;YACP,MAAM,IAAI,gBAAgB,CACzB,0BAA0B,MAAM,8BAA8B,CAC9D,CAAC;QACH,CAAC;IACF,CAAC;SAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;QACvC,IAAI,MAAM,KAAK,CAAC,IAAI,MAAM,KAAK,CAAC,EAAE,CAAC;YAClC,eAAe,GAAG,MAAM,CAAC;QAC1B,CAAC;aAAM,CAAC;YACP,MAAM,IAAI,gBAAgB,CACzB,0BAA0B,MAAM,kCAAkC,CAClE,CAAC;QACH,CAAC;IACF,CAAC;SAAM,CAAC;QACP,eAAe,GAAG,IAAI,CAAC;IACxB,CAAC;IAED,OAAO;QACN,MAAM,EAAE,eAAe;QACvB,OAAO;KACP,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inet-endpoint.d.ts","sourceRoot":"","sources":["../../src/net/inet-endpoint.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,yEAAyE;AACzE,MAAM,MAAM,YAAY,GAAG,WAAW,GAAG;IACxC,mBAAmB;IACnB,IAAI,EAAE,MAAM,CAAC;CACb,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inet-endpoint.js","sourceRoot":"","sources":["../../src/net/inet-endpoint.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import * as net from "node:net";
|
|
2
|
+
import { type InetAddress } from "./inet-address.js";
|
|
3
|
+
import type { InetEndpoint } from "./inet-endpoint.js";
|
|
4
|
+
import { StreamSocket, type StreamSocketEvents } from "./stream-socket.js";
|
|
5
|
+
/** Event map for sockets running over an IP transport. */
|
|
6
|
+
export type InetSocketEvents = StreamSocketEvents & {
|
|
7
|
+
/**
|
|
8
|
+
* Emitted when a new connection attempt is started. May be emitted multiple
|
|
9
|
+
* times if family autoselection is enabled.
|
|
10
|
+
*/
|
|
11
|
+
connectionAttempt: [endpoint: InetEndpoint];
|
|
12
|
+
/**
|
|
13
|
+
* Emitted when a connection attempt failed. May be emitted multiple times if
|
|
14
|
+
* family autoselection is enabled.
|
|
15
|
+
*/
|
|
16
|
+
connectionAttemptFailed: [endpoint: InetEndpoint, error: Error];
|
|
17
|
+
/**
|
|
18
|
+
* Emitted when a connection attempt timed out. May be emitted multiple times
|
|
19
|
+
* if family autoselection is enabled.
|
|
20
|
+
*/
|
|
21
|
+
connectionAttemptTimeout: [endpoint: InetEndpoint];
|
|
22
|
+
/** Emitted after resolving the host name but before connecting. */
|
|
23
|
+
lookup: [error: Error | null, address: InetAddress, host: string];
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Base class for sockets whose transport is an IP connection.
|
|
27
|
+
*
|
|
28
|
+
* On top of {@link StreamSocket} it exposes the endpoint accessors and the
|
|
29
|
+
* socket options that only make sense over IP, plus the connection-attempt and
|
|
30
|
+
* name-resolution events Node.js emits while dialling.
|
|
31
|
+
*
|
|
32
|
+
* It is shared by {@link TcpSocket} and {@link TlsSocket}: both run over IP, but
|
|
33
|
+
* they establish their connection differently, so neither can be expressed as a
|
|
34
|
+
* subclass of the other.
|
|
35
|
+
*/
|
|
36
|
+
export declare class InetSocket<TSocket extends net.Socket = net.Socket, TEvents extends InetSocketEvents = InetSocketEvents> extends StreamSocket<TSocket, TEvents> {
|
|
37
|
+
/**
|
|
38
|
+
* Remote endpoint of the socket, or `null` while it is not connected.
|
|
39
|
+
*
|
|
40
|
+
* @throws {UnsupportedError} If the socket family is not IPv4 or IPv6.
|
|
41
|
+
*/
|
|
42
|
+
get remoteEndpoint(): InetEndpoint | null;
|
|
43
|
+
/**
|
|
44
|
+
* Local endpoint of the socket, or `null` while it is not connected.
|
|
45
|
+
*
|
|
46
|
+
* @throws {UnsupportedError} If the socket family is not IPv4 or IPv6.
|
|
47
|
+
*/
|
|
48
|
+
get localEndpoint(): InetEndpoint | null;
|
|
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: boolean, initialDelay?: number): void;
|
|
57
|
+
/**
|
|
58
|
+
* Enables or disables the Nagle algorithm for the socket.
|
|
59
|
+
*
|
|
60
|
+
* @param noDelay Whether to disable the Nagle algorithm.
|
|
61
|
+
*/
|
|
62
|
+
setNoDelay(noDelay: boolean): void;
|
|
63
|
+
protected setupEventForwarding(): void;
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=inet-socket.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
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