@zukhruf/net 0.8.243 → 0.8.244
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 +53 -21
- package/dist/endpoint.d.ts +8 -1
- package/dist/endpoint.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/server.d.ts +4 -3
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +4 -2
- package/dist/server.js.map +1 -1
- package/dist/tcp-endpoint.d.ts +2 -2
- package/dist/tcp-endpoint.d.ts.map +1 -1
- package/dist/tcp-endpoint.js +2 -2
- package/dist/tcp-endpoint.js.map +1 -1
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -52,12 +52,29 @@ const peer = await serving.address.connect();
|
|
|
52
52
|
|
|
53
53
|
`new Server(handler, options)` holds the handler and listens on nothing. `handler(socket)` gets each accepted `net.Socket`. A server can serve more than once, also on two endpoints at once ([ADR 0004](./docs/adr/0004-a-server-is-a-value-and-serve-gives-a-serving-that-owns-each-socket-that-it-accepted.md)).
|
|
54
54
|
|
|
55
|
-
|
|
|
56
|
-
|
|
|
57
|
-
|
|
|
58
|
-
|
|
|
59
|
-
|
|
|
60
|
-
|
|
55
|
+
| Option | What it does |
|
|
56
|
+
| ---------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
57
|
+
| `allowHalfOpen` | Set on each accepted socket before the handler gets it, so the handler can answer after the client's end. Default false, as `node:net`. |
|
|
58
|
+
| `pauseOnConnect` | The endpoint accepts each socket paused, so a handler that gives it to a child process, also after an async step, loses none of the client's first bytes. Default false, as `node:net`. |
|
|
59
|
+
| `highWaterMark` | The readable and writable high-water mark of each accepted socket. Default Node's. |
|
|
60
|
+
|
|
61
|
+
`pauseOnConnect` and `highWaterMark` go to the endpoint's `listen(handler, options)`, because a socket has them from its creation ([ADR 0008](./docs/adr/0008-an-endpoint-takes-the-socket-options-that-exist-only-from-the-accept.md)).
|
|
62
|
+
|
|
63
|
+
```ts
|
|
64
|
+
const sshd = new Server(
|
|
65
|
+
(socket) => {
|
|
66
|
+
void inetd.start({ stdin: socket, stdout: socket });
|
|
67
|
+
},
|
|
68
|
+
{ pauseOnConnect: true },
|
|
69
|
+
);
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
| A copy in the tests | With the package |
|
|
73
|
+
| ----------------------------------------------------------------- | -------------------------------------------------------------- |
|
|
74
|
+
| ssh `startSilentServer()`, gone in 3c65b386 | `new Server(() => {}).serve(new TcpEndpoint())` |
|
|
75
|
+
| mutex `standInServer(path, onPeer)` | `new Server(onPeer).serve(new PipeEndpoint(path, { prefix }))` |
|
|
76
|
+
| ssh `listen(path, accepted, { allowHalfOpen })`, gone in 3c65b386 | `new Server(accepted, { allowHalfOpen }).serve(endpoint)` |
|
|
77
|
+
| `portOf(server)` | `serving.address.port` |
|
|
61
78
|
|
|
62
79
|
## End a serving
|
|
63
80
|
|
|
@@ -86,7 +103,8 @@ const answer = await fetch(`${site.origin}/`);
|
|
|
86
103
|
|
|
87
104
|
- The close destroys each accepted socket, also a socket that an `upgrade` took. Then it destroys each client socket of this process that belonged to a destroyed connection, and waits for its `close`, so the timers of `fetch` are cleared before the next test (testing ADR 0030).
|
|
88
105
|
- `shutdown(signal)` ends each idle connection at once, and each other connection after its response, as Go's `Shutdown`.
|
|
89
|
-
- `options` are those of `http.createServer` (`keepAliveTimeout`,
|
|
106
|
+
- `options` are those of `http.createServer` (`keepAliveTimeout`, ...) and `upgrade`, a listener of the `upgrade` event.
|
|
107
|
+
- The endpoint accepts each socket, and the `http.Server` gets it by `emit('connection')`. So the options that `http.Server` gives its own `net.Server` for the accept have no effect here: each socket keeps Node's default `highWaterMark`, `noDelay` false, no keep-alive, and `allowHalfOpen` false ([ADR 0008](./docs/adr/0008-an-endpoint-takes-the-socket-options-that-exist-only-from-the-accept.md), decision 3).
|
|
90
108
|
|
|
91
109
|
| `@zukhruf/testing/http`, removed (#6078) | `@zukhruf/net/http` |
|
|
92
110
|
| -------------------------------------------- | ---------------------------------------------------------- |
|
|
@@ -115,17 +133,16 @@ The package has no error class of its own. A caller does not do a different next
|
|
|
115
133
|
|
|
116
134
|
## Who uses it
|
|
117
135
|
|
|
118
|
-
| Consumer | How
|
|
119
|
-
| ------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
120
|
-
| 106 test files of elt (49), text2sql (20), sdk-it (18), finetuning (9), mteb (6), deepagents (2), context-compiler (1) and offers-evals (1) | `HttpServer` on a `TcpEndpoint`
|
|
121
|
-
|
|
|
122
|
-
|
|
|
123
|
-
|
|
|
124
|
-
| ssh `
|
|
125
|
-
|
|
|
126
|
-
|
|
|
127
|
-
|
|
|
128
|
-
| `@zukhruf/chaos` | `Proxy` is a handler that a `Server` serves | backlog #6078 |
|
|
136
|
+
| Consumer | How | Record |
|
|
137
|
+
| ------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------- |
|
|
138
|
+
| 106 test files of elt (49), text2sql (20), sdk-it (18), finetuning (9), mteb (6), deepagents (2), context-compiler (1) and offers-evals (1) | `HttpServer` on a `TcpEndpoint` | backlog #6078 |
|
|
139
|
+
| ssh's `client`, `config-dial-route` and `config-dial` tests | `Server` whose handler only notes the accept, in place of `startSilentServer` | backlog #6078 |
|
|
140
|
+
| 6 mutex and 3 single-flight test files | `Server` on a `PipeEndpoint`, today `standInServer` | backlog #6078 |
|
|
141
|
+
| ssh `control.test.ts`, `owner-death.test.ts` and `channels.test.ts` | `Server` on a `TcpEndpoint` or a `PipeEndpoint`, with `allowHalfOpen` where the test answers after the end, in place of `listen` | backlog #6078 |
|
|
142
|
+
| ssh `client-ref.test.ts`, `src/testing/reports.ts` and `src/testing/ssh-client.ts` | `Server` on a `TcpEndpoint`; `ssh-client.ts` ends with `shutdown(signal)` | backlog #6078 |
|
|
143
|
+
| 9 files of ssh, and tools/eslint-rules `repoint.test.ts` | `serving.address.port`, in place of `portOf` | backlog #5947 |
|
|
144
|
+
| the `sshd.ts` of ssh, docker and testing | `serving.address.port`, today `portOf`; each `sshd.ts` hands the socket to a child and needs `pauseOnConnect`, which `Server` has since 2026-11-30 (ADR 0008); ssh's `sshd.ts` moves next | backlog #5947 |
|
|
145
|
+
| `@zukhruf/chaos` | `Proxy` is a handler that a `Server` serves | backlog #6078 |
|
|
129
146
|
|
|
130
147
|
## The same concepts in other systems
|
|
131
148
|
|
|
@@ -164,7 +181,15 @@ export interface Listener<A> extends AsyncDisposable {
|
|
|
164
181
|
|
|
165
182
|
/** Where a server listens. PipeEndpoint of @zukhruf/pipes is one. */
|
|
166
183
|
export interface Endpoint<A> {
|
|
167
|
-
listen(handler: Handler): Promise<Listener<A>>;
|
|
184
|
+
listen(handler: Handler, options?: ListenOptions): Promise<Listener<A>>;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/** How the listener accepts each socket, as the options of net.createServer. */
|
|
188
|
+
export interface ListenOptions {
|
|
189
|
+
/** Each accepted socket reads nothing until resumed. Default false, as node:net. */
|
|
190
|
+
readonly pauseOnConnect?: boolean;
|
|
191
|
+
/** The readable and writable high-water mark of each accepted socket. Default node's. */
|
|
192
|
+
readonly highWaterMark?: number;
|
|
168
193
|
}
|
|
169
194
|
|
|
170
195
|
export interface TcpEndpointOptions {
|
|
@@ -176,10 +201,14 @@ export interface TcpEndpointOptions {
|
|
|
176
201
|
|
|
177
202
|
export class TcpEndpoint implements Endpoint<SocketAddress> {
|
|
178
203
|
constructor(options?: TcpEndpointOptions);
|
|
179
|
-
listen(
|
|
204
|
+
listen(
|
|
205
|
+
handler: Handler,
|
|
206
|
+
options?: ListenOptions,
|
|
207
|
+
): Promise<Listener<SocketAddress>>;
|
|
180
208
|
}
|
|
181
209
|
|
|
182
|
-
|
|
210
|
+
/** pauseOnConnect and highWaterMark go to the endpoint's listen. */
|
|
211
|
+
export interface ServerOptions extends ListenOptions {
|
|
183
212
|
/** Set on each accepted socket before the handler gets it. Default false, as node:net. */
|
|
184
213
|
readonly allowHalfOpen?: boolean;
|
|
185
214
|
}
|
|
@@ -238,9 +267,11 @@ Each item is a detail that a caller sees. Ezz approved each proposal on 2026-11-
|
|
|
238
267
|
1. **The type of `serving.address`.** The record says `net.SocketAddress`. It cannot hold a pipe's path. Proposal: `Endpoint<A>` and `Serving<A>`, so the address is a `net.SocketAddress` for TCP and a `PipeAddress` for a pipe (.NET's `IConnectionListener.EndPoint`, typed by the endpoint) ([ADR 0003](./docs/adr/0003-an-endpoint-listens-and-gives-a-listener-that-never-ends-an-accepted-socket.md)).
|
|
239
268
|
2. **`address` on `PipeServer`.** Ezz: "Add address". `PipeServer.address` is the address of its endpoint, after Go's `Listener.Addr()`, since 663e84b0, so a `PipeEndpoint` meets `Endpoint`.
|
|
240
269
|
3. **`allowHalfOpen` is an option of `Server`, not of `TcpEndpoint`.** `Endpoint#listen(handler)` takes no options, so the serving sets `socket.allowHalfOpen = true` on each accepted socket before the handler (probe of 2026-11-28: a server that sets it after the accept answers after the client's end). Node.js has it as an option of `net.createServer`. ssh's `listen` and testing's `slowProxy` use it.
|
|
270
|
+
Amended 2026-11-30 (#6078, decisions 156 and 157): `Endpoint#listen(handler, options?)` takes `pauseOnConnect` and `highWaterMark`, which a socket has only from its creation; `allowHalfOpen` stays on the socket ([ADR 0008](./docs/adr/0008-an-endpoint-takes-the-socket-options-that-exist-only-from-the-accept.md)).
|
|
241
271
|
4. **The serving ignores the `error` event of each accepted socket.** Each copy adds `socket.on('error', () => {})`, because a reset of the peer is normal in a test and an `error` with no listener ends the process. The handler still sees each error in its reads and writes, as a Go `Read` and `Write` return it. Proposal: yes.
|
|
242
272
|
5. **`serving.connections`.** docker's `fakeEngine` has `openConnections`, and `slowProxy` has `connections()`, which 3 database tests of testing read. Proposal: `connections`, the accepted sockets that are open now. Go httptest and Kestrel expose no count; Toxiproxy lists the connections of a proxy.
|
|
243
273
|
6. **docker's `allConnectionsClosed`.** It waits until each connection has closed, and the engine still listens. Proposal: no member; those tests call `shutdown(t.signal)`, which waits for the same thing and stops the accepts.
|
|
274
|
+
Amended 2026-11-30 (#6078, decision 158): `shutdown(t.signal)` of an `HttpServing` ends each idle connection first, so it is not the same wait. docker's fake engine stays on its own `createServer`, with its `allConnectionsClosed`, since its tests need sockets with a high-water mark of one byte, which an `HttpServer` does not give (ADR 0008, decision 3).
|
|
244
275
|
7. **What `shutdown(signal)` gives after an abort.** Go's `Shutdown` returns the error of the context. Proposal: it closes the rest, then rejects with `signal.reason`, so a caller knows that the end was not graceful; this is also how `Command#run` of `@zukhruf/process` rejects at the abort of its signal.
|
|
245
276
|
8. **No fallback to `[::1]`.** httptest and nettest try `[::1]:0` when `127.0.0.1:0` fails. Proposal: no fallback; the default host is a ruling, and a caller gives `host: '::1'`.
|
|
246
277
|
9. **The type of `Handler`.** Proposal: `(socket: Socket) => void`, as the `connectionListener` of `net.createServer` and of `PipeEndpoint#listen`.
|
|
@@ -264,3 +295,4 @@ Each item is a detail that a caller sees. Ezz approved each proposal on 2026-11-
|
|
|
264
295
|
- [ADR 0005](./docs/adr/0005-close-ends-each-accepted-socket-and-waits-for-its-close-and-shutdown-waits-for-the-sockets-until-its-signal-aborts.md): close ends each accepted socket and waits for its close, and shutdown waits for the sockets until its signal aborts.
|
|
265
296
|
- [ADR 0006](./docs/adr/0006-the-http-view-is-a-server-whose-handler-gives-each-socket-to-an-http-server.md): the HTTP view is a server whose handler gives each socket to an http.Server.
|
|
266
297
|
- [ADR 0007](./docs/adr/0007-the-tests-move-first-and-each-shipped-server-moves-when-close-or-shutdown-is-its-kind-of-end.md): the tests move first, and each shipped server moves when close or shutdown is its kind of end.
|
|
298
|
+
- [ADR 0008](./docs/adr/0008-an-endpoint-takes-the-socket-options-that-exist-only-from-the-accept.md): an endpoint takes the socket options that exist only from the accept.
|
package/dist/endpoint.d.ts
CHANGED
|
@@ -8,9 +8,16 @@ export interface Listener<A> extends AsyncDisposable {
|
|
|
8
8
|
/** Stops the accepts; resolves when the listener has closed. */
|
|
9
9
|
close(): Promise<void>;
|
|
10
10
|
}
|
|
11
|
+
/** How the listener accepts each socket, as the options of `net.createServer`. */
|
|
12
|
+
export interface ListenOptions {
|
|
13
|
+
/** Each accepted socket reads nothing until resumed, so a child process that gets it reads the client's first bytes. Default false, as node:net (ADR 0008). */
|
|
14
|
+
readonly pauseOnConnect?: boolean;
|
|
15
|
+
/** The `readableHighWaterMark` and `writableHighWaterMark` of each accepted socket, which exist only from its creation. Default node's (ADR 0008). */
|
|
16
|
+
readonly highWaterMark?: number;
|
|
17
|
+
}
|
|
11
18
|
/** Where a server listens. `PipeEndpoint` of `@zukhruf/pipes` is one. */
|
|
12
19
|
export interface Endpoint<A> {
|
|
13
20
|
/** Resolves with a listener when it listens. */
|
|
14
|
-
listen(handler: Handler): Promise<Listener<A>>;
|
|
21
|
+
listen(handler: Handler, options?: ListenOptions): Promise<Listener<A>>;
|
|
15
22
|
}
|
|
16
23
|
//# sourceMappingURL=endpoint.d.ts.map
|
package/dist/endpoint.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"endpoint.d.ts","sourceRoot":"","sources":["../src/endpoint.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAEvC,oFAAoF;AACpF,MAAM,MAAM,OAAO,GAAG,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;AAE/C,0HAA0H;AAC1H,MAAM,WAAW,QAAQ,CAAC,CAAC,CAAE,SAAQ,eAAe;IAClD,uDAAuD;IACvD,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC;IACpB,gEAAgE;IAChE,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB;AAED,yEAAyE;AACzE,MAAM,WAAW,QAAQ,CAAC,CAAC;IACzB,gDAAgD;IAChD,MAAM,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"endpoint.d.ts","sourceRoot":"","sources":["../src/endpoint.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAEvC,oFAAoF;AACpF,MAAM,MAAM,OAAO,GAAG,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;AAE/C,0HAA0H;AAC1H,MAAM,WAAW,QAAQ,CAAC,CAAC,CAAE,SAAQ,eAAe;IAClD,uDAAuD;IACvD,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC;IACpB,gEAAgE;IAChE,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB;AAED,kFAAkF;AAClF,MAAM,WAAW,aAAa;IAC5B,+JAA+J;IAC/J,QAAQ,CAAC,cAAc,CAAC,EAAE,OAAO,CAAC;IAClC,sJAAsJ;IACtJ,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;CACjC;AAED,yEAAyE;AACzE,MAAM,WAAW,QAAQ,CAAC,CAAC;IACzB,gDAAgD;IAChD,MAAM,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;CACzE"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type { Endpoint, Handler, Listener } from './endpoint.ts';
|
|
1
|
+
export type { Endpoint, Handler, ListenOptions, Listener } from './endpoint.ts';
|
|
2
2
|
export { Server, type ServerOptions, type Serving } from './server.ts';
|
|
3
3
|
export { TcpEndpoint, type TcpEndpointOptions } from './tcp-endpoint.ts';
|
|
4
4
|
//# 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,YAAY,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,QAAQ,EAAE,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAChF,OAAO,EAAE,MAAM,EAAE,KAAK,aAAa,EAAE,KAAK,OAAO,EAAE,MAAM,aAAa,CAAC;AACvE,OAAO,EAAE,WAAW,EAAE,KAAK,kBAAkB,EAAE,MAAM,mBAAmB,CAAC"}
|
package/dist/server.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type { Endpoint, Handler } from './endpoint.ts';
|
|
2
|
-
|
|
1
|
+
import type { Endpoint, Handler, ListenOptions } from './endpoint.ts';
|
|
2
|
+
/** `pauseOnConnect` and `highWaterMark` go to the endpoint's listen, since a socket has them from its creation (ADR 0008). */
|
|
3
|
+
export interface ServerOptions extends ListenOptions {
|
|
3
4
|
/** Set on each accepted socket before the handler gets it. Default false, as node:net. */
|
|
4
5
|
readonly allowHalfOpen?: boolean;
|
|
5
6
|
}
|
|
@@ -22,7 +23,7 @@ export interface Serving<A> extends AsyncDisposable {
|
|
|
22
23
|
/** What to do with each connection. It listens on nothing until `serve()`. */
|
|
23
24
|
export declare class Server {
|
|
24
25
|
#private;
|
|
25
|
-
constructor(handler: Handler, { allowHalfOpen }?: ServerOptions);
|
|
26
|
+
constructor(handler: Handler, { allowHalfOpen, ...listen }?: ServerOptions);
|
|
26
27
|
/** Listens on `endpoint`; resolves when it listens. */
|
|
27
28
|
serve<A>(endpoint: Endpoint<A>): Promise<Serving<A>>;
|
|
28
29
|
}
|
package/dist/server.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAY,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,aAAa,EAAY,MAAM,eAAe,CAAC;AAEhF,8HAA8H;AAC9H,MAAM,WAAW,aAAc,SAAQ,aAAa;IAClD,0FAA0F;IAC1F,QAAQ,CAAC,aAAa,CAAC,EAAE,OAAO,CAAC;CAClC;AAED,gFAAgF;AAChF,MAAM,WAAW,OAAO,CAAC,CAAC,CAAE,SAAQ,eAAe;IACjD,uEAAuE;IACvE,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC;IACpB,8CAA8C;IAC9C,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,8EAA8E;IAC9E,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACvB;;;;OAIG;IACH,QAAQ,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7C,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxC;AAED,8EAA8E;AAC9E,qBAAa,MAAM;;IAKjB,YACE,OAAO,EAAE,OAAO,EAChB,EAAE,aAAqB,EAAE,GAAG,MAAM,EAAE,GAAE,aAAkB,EAKzD;IAED,uDAAuD;IACjD,KAAK,CAAC,CAAC,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAQzD;CACF"}
|
package/dist/server.js
CHANGED
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
export class Server {
|
|
3
3
|
#handler;
|
|
4
4
|
#allowHalfOpen;
|
|
5
|
-
|
|
5
|
+
#listen;
|
|
6
|
+
constructor(handler, { allowHalfOpen = false, ...listen } = {}) {
|
|
6
7
|
this.#handler = handler;
|
|
7
8
|
this.#allowHalfOpen = allowHalfOpen;
|
|
9
|
+
this.#listen = listen;
|
|
8
10
|
}
|
|
9
11
|
/** Listens on `endpoint`; resolves when it listens. */
|
|
10
12
|
async serve(endpoint) {
|
|
@@ -13,7 +15,7 @@ export class Server {
|
|
|
13
15
|
socket.allowHalfOpen = this.#allowHalfOpen;
|
|
14
16
|
sockets.add(socket);
|
|
15
17
|
this.#handler(socket);
|
|
16
|
-
});
|
|
18
|
+
}, this.#listen);
|
|
17
19
|
return new ListeningServing(listener, sockets);
|
|
18
20
|
}
|
|
19
21
|
}
|
package/dist/server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AA2BA,8EAA8E;AAC9E,MAAM,OAAO,MAAM;IACR,QAAQ,CAAU;IAClB,cAAc,CAAU;IACxB,OAAO,CAAgB;IAEhC,YACE,OAAgB,EAChB,EAAE,aAAa,GAAG,KAAK,EAAE,GAAG,MAAM,EAAE,GAAkB,EAAE;QAExD,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;QACxB,IAAI,CAAC,cAAc,GAAG,aAAa,CAAC;QACpC,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;IACxB,CAAC;IAED,uDAAuD;IACvD,KAAK,CAAC,KAAK,CAAI,QAAqB;QAClC,MAAM,OAAO,GAAG,IAAI,eAAe,EAAE,CAAC;QACtC,MAAM,QAAQ,GAAG,MAAM,QAAQ,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE;YAChD,MAAM,CAAC,aAAa,GAAG,IAAI,CAAC,cAAc,CAAC;YAC3C,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;YACpB,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;QACxB,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;QACjB,OAAO,IAAI,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ress } from 'node:net';
|
|
2
|
-
import type { Endpoint, Handler, Listener } from './endpoint.ts';
|
|
2
|
+
import type { Endpoint, Handler, ListenOptions, Listener } from './endpoint.ts';
|
|
3
3
|
export interface TcpEndpointOptions {
|
|
4
4
|
/** An IP address. Default '127.0.0.1'. */
|
|
5
5
|
readonly host?: string;
|
|
@@ -10,6 +10,6 @@ export interface TcpEndpointOptions {
|
|
|
10
10
|
export declare class TcpEndpoint implements Endpoint<SocketAddress> {
|
|
11
11
|
#private;
|
|
12
12
|
constructor({ host, port }?: TcpEndpointOptions);
|
|
13
|
-
listen(handler: Handler): Promise<Listener<SocketAddress>>;
|
|
13
|
+
listen(handler: Handler, { pauseOnConnect, highWaterMark }?: ListenOptions): Promise<Listener<SocketAddress>>;
|
|
14
14
|
}
|
|
15
15
|
//# sourceMappingURL=tcp-endpoint.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tcp-endpoint.d.ts","sourceRoot":"","sources":["../src/tcp-endpoint.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,aAAa,EAEd,MAAM,UAAU,CAAC;AAElB,OAAO,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"tcp-endpoint.d.ts","sourceRoot":"","sources":["../src/tcp-endpoint.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,aAAa,EAEd,MAAM,UAAU,CAAC;AAElB,OAAO,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEhF,MAAM,WAAW,kBAAkB;IACjC,0CAA0C;IAC1C,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,sDAAsD;IACtD,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,mGAAmG;AACnG,qBAAa,WAAY,YAAW,QAAQ,CAAC,aAAa,CAAC;;IAIzD,YAAY,EAAE,IAAkB,EAAE,IAAQ,EAAE,GAAE,kBAAuB,EAGpE;IAEK,MAAM,CACV,OAAO,EAAE,OAAO,EAChB,EAAE,cAAc,EAAE,aAAa,EAAE,GAAE,aAAkB,GACpD,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC,CAUlC;CACF"}
|
package/dist/tcp-endpoint.js
CHANGED
|
@@ -9,8 +9,8 @@ export class TcpEndpoint {
|
|
|
9
9
|
this.#host = host;
|
|
10
10
|
this.#port = port;
|
|
11
11
|
}
|
|
12
|
-
async listen(handler) {
|
|
13
|
-
const server = createServer(handler);
|
|
12
|
+
async listen(handler, { pauseOnConnect, highWaterMark } = {}) {
|
|
13
|
+
const server = createServer({ pauseOnConnect, highWaterMark }, handler);
|
|
14
14
|
try {
|
|
15
15
|
server.listen(this.#port, this.#host);
|
|
16
16
|
await once(server, 'listening');
|
package/dist/tcp-endpoint.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tcp-endpoint.js","sourceRoot":"","sources":["../src/tcp-endpoint.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,oBAAoB,CAAC;AACxC,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACnC,OAAO,EAEL,aAAa,EACb,YAAY,GACb,MAAM,UAAU,CAAC;AAWlB,mGAAmG;AACnG,MAAM,OAAO,WAAW;IACb,KAAK,CAAS;IACd,KAAK,CAAS;IAEvB,YAAY,EAAE,IAAI,GAAG,WAAW,EAAE,IAAI,GAAG,CAAC,EAAE,GAAuB,EAAE;QACnE,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;IACpB,CAAC;IAED,KAAK,CAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"tcp-endpoint.js","sourceRoot":"","sources":["../src/tcp-endpoint.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,oBAAoB,CAAC;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aAAa,CAAC;YAC/B,OAAO;YACP,IAAI;YACJ,MAAM,EAAE,MAAM,KAAK,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM;SAC5C,CAAC,CAAC;IACL,CAAC;IAED,+HAA+H;IAC/H,KAAK;QACH,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACrC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,CAC3B,KAAK,IAAI,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,KAAK,wBAAwB;gBAC9D,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;gBACf,CAAC,CAAC,OAAO,EAAE,CACd,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;IAED,CAAC,MAAM,CAAC,YAAY,CAAC;QACnB,OAAO,IAAI,CAAC,KAAK,EAAE,CAAC;IACtB,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zukhruf/net",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.244",
|
|
4
4
|
"description": "A server that accepts connections on a TCP port or a pipe and owns each socket: close destroys each one and waits for its close, shutdown waits until its signal aborts; @zukhruf/net/http serves HTTP the same way. After Go's net and net/http.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -49,9 +49,9 @@
|
|
|
49
49
|
"access": "public"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"@zukhruf/fs": "^0.8.
|
|
53
|
-
"@zukhruf/parameterized-test": "^0.8.
|
|
54
|
-
"@zukhruf/pipes": "^0.8.
|
|
55
|
-
"@zukhruf/process": "^0.8.
|
|
52
|
+
"@zukhruf/fs": "^0.8.244",
|
|
53
|
+
"@zukhruf/parameterized-test": "^0.8.244",
|
|
54
|
+
"@zukhruf/pipes": "^0.8.244",
|
|
55
|
+
"@zukhruf/process": "^0.8.244"
|
|
56
56
|
}
|
|
57
57
|
}
|