nish 0.44.0 → 0.45.1
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 +1 -1
- package/docs/AI.md +18 -16
- package/package.json +5 -5
- package/runtime/core/numbers.mjs +3 -1
- package/runtime/core/strings.mjs +90 -38
- package/runtime/core.d.ts +8 -0
- package/runtime/core.mjs +16 -0
- package/runtime/nish.d.ts +47 -5
- package/runtime/nish.mjs +4 -0
- package/std/README.md +3 -3
- package/std/array.ts +10 -2
- package/std/bytes.ts +239 -26
- package/std/cli-args.ts +1072 -606
- package/std/cli-flags.ts +180 -98
- package/std/cli.ts +21 -13
- package/std/collections.ts +245 -127
- package/std/compress/checksum.ts +32 -37
- package/std/compress/deflate.ts +1102 -542
- package/std/compress/gzip.ts +290 -145
- package/std/compress/zlib.ts +57 -21
- package/std/crypto/aes.ts +153 -75
- package/std/crypto/base64url.ts +84 -61
- package/std/crypto/bcrypt-batch.ts +164 -90
- package/std/crypto/bcrypt.ts +185 -107
- package/std/crypto/chacha20poly1305.ts +84 -68
- package/std/crypto/ct.ts +9 -7
- package/std/crypto/ed25519.ts +64 -27
- package/std/crypto/hkdf.ts +105 -63
- package/std/crypto/hmac.ts +95 -89
- package/std/crypto/jwt.ts +248 -126
- package/std/crypto/p256.ts +758 -444
- package/std/crypto/p384.ts +20 -13
- package/std/crypto/pki-roots.ts +95 -38
- package/std/crypto/pki.ts +164 -60
- package/std/crypto/rsa.ts +266 -223
- package/std/crypto/scram.ts +3 -4
- package/std/crypto/sha1.ts +107 -65
- package/std/crypto/sha256.ts +502 -422
- package/std/crypto/sha512.ts +204 -135
- package/std/crypto/x509-random.ts +9 -3
- package/std/crypto/x509.ts +331 -171
- package/std/json-equal.ts +35 -19
- package/std/json-format.ts +215 -108
- package/std/json-number.ts +126 -72
- package/std/json-pointer.ts +42 -13
- package/std/json-tokenizer.ts +498 -307
- package/std/json-typed.ts +115 -36
- package/std/json-value.ts +341 -152
- package/std/json.ts +300 -158
- package/std/net/buffer-pool.ts +17 -7
- package/std/net/dns-config.ts +427 -236
- package/std/net/dns-message.ts +114 -47
- package/std/net/dns-resolver.ts +736 -237
- package/std/net/dns.ts +205 -52
- package/std/net/fetch.ts +320 -184
- package/std/net/grpc.ts +948 -0
- package/std/net/handler.ts +1275 -217
- package/std/net/hpack.ts +395 -180
- package/std/net/http-compress.ts +502 -65
- package/std/net/http-fields.ts +85 -49
- package/std/net/http-server.ts +1764 -602
- package/std/net/http1-client-codec.ts +372 -161
- package/std/net/http1-codec.ts +665 -331
- package/std/net/http1-server.ts +660 -278
- package/std/net/http2-cleartext.ts +165 -95
- package/std/net/http2-frame.ts +232 -89
- package/std/net/http2-tls.ts +42 -12
- package/std/net/http2.ts +327 -101
- package/std/net/http3-frame.ts +68 -33
- package/std/net/http3-server.ts +647 -192
- package/std/net/http3.ts +667 -189
- package/std/net/oidc.ts +63 -24
- package/std/net/outbound.ts +207 -142
- package/std/net/postgres-async.ts +1165 -443
- package/std/net/postgres-carrier.ts +575 -372
- package/std/net/postgres.ts +1459 -559
- package/std/net/prefork.ts +254 -98
- package/std/net/protobuf.ts +1017 -0
- package/std/net/qpack.ts +143 -92
- package/std/net/quic-conn-ack.ts +50 -18
- package/std/net/quic-conn-cid.ts +66 -26
- package/std/net/quic-conn-params.ts +13 -7
- package/std/net/quic-datagram.ts +90 -27
- package/std/net/quic-frame.ts +225 -124
- package/std/net/quic-listener.ts +197 -89
- package/std/net/quic-packet.ts +289 -163
- package/std/net/quic-recovery.ts +279 -128
- package/std/net/quic-stream.ts +466 -167
- package/std/net/quic.ts +568 -257
- package/std/net/router.ts +450 -99
- package/std/net/serve.ts +651 -232
- package/std/net/static.ts +1458 -0
- package/std/net/tls/client.ts +140 -45
- package/std/net/tls/codec.ts +510 -260
- package/std/net/tls/record-client.ts +268 -76
- package/std/net/tls/record-server.ts +236 -79
- package/std/net/tls/record.ts +173 -47
- package/std/net/tls/schedule.ts +58 -39
- package/std/net/tls/ticket.ts +295 -103
- package/std/net/tls/verify.ts +1 -1
- package/std/net/tls-tcp.ts +218 -75
- package/std/net/tls.ts +260 -152
- package/std/net/upstream.ts +283 -86
- package/std/net/url.ts +277 -102
- package/std/net/websocket.ts +370 -186
- package/std/net/webtransport.ts +755 -436
- package/std/regex.ts +1659 -829
- package/std/sync/ring.ts +320 -156
- package/std/sync/shm.ts +53 -6
- package/std/text.ts +205 -124
- package/std/threads.ts +22 -2
|
@@ -103,6 +103,33 @@ const H2C_NANOS_PER_MS: i64 = 1000000
|
|
|
103
103
|
/** The client connection preface, `PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n` (RFC 9113 §3.4). */
|
|
104
104
|
const H2C_PREFACE: string = "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n"
|
|
105
105
|
|
|
106
|
+
/**
|
|
107
|
+
* One slot's socket and preface: what `accept` sets and `close` clears. The
|
|
108
|
+
* slot is made by the first accept into it and kept, with its connection.
|
|
109
|
+
*/
|
|
110
|
+
class H2cSlot {
|
|
111
|
+
/** When the slot was accepted, in `monotonicNanos`: its preface deadline's start. */
|
|
112
|
+
since: i64 = 0
|
|
113
|
+
/** The slot's 24 preface bytes, read here until they are whole. */
|
|
114
|
+
preface: u8[]
|
|
115
|
+
/** The slot's HTTP/2 connection, the one `connections` holds at `at`. */
|
|
116
|
+
conn: Http2Connection
|
|
117
|
+
/** The slot's number, its place in `held` and in `connections`. */
|
|
118
|
+
at: i32 = 0
|
|
119
|
+
/** The slot's socket, -1 while the slot is free. */
|
|
120
|
+
fd: i32 = -1
|
|
121
|
+
/** How many preface bytes the slot has read; 24 once the preface is whole and fed. */
|
|
122
|
+
got: i32 = 0
|
|
123
|
+
/** Whether the slot's socket has ended and `endInput` was called for it. */
|
|
124
|
+
ended: boolean = false
|
|
125
|
+
|
|
126
|
+
constructor(at: i32, conn: Http2Connection) {
|
|
127
|
+
this.at = at
|
|
128
|
+
this.conn = conn
|
|
129
|
+
this.preface = new Array<u8>(H2C_PREFACE_SIZE)
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
106
133
|
/**
|
|
107
134
|
* A pool of HTTP/2 connections over plain TCP, with prior knowledge, on one
|
|
108
135
|
* listening socket. `connection(slot)` is the HTTP/2 side of each slot.
|
|
@@ -123,18 +150,10 @@ export class Http2CleartextServer {
|
|
|
123
150
|
date: HttpDate
|
|
124
151
|
/** The frame buffers every slot's connection borrows: one of each per slot at most, none made up front. */
|
|
125
152
|
readonly pools: Http2Pools
|
|
126
|
-
/**
|
|
127
|
-
private
|
|
128
|
-
/** The slots closed since they were used, a stack `accept` takes from before it
|
|
129
|
-
private free:
|
|
130
|
-
/** Every slot's 24 preface bytes, slot `k`'s at `24 * k`; made whole by the constructor. */
|
|
131
|
-
private prefaces: u8[]
|
|
132
|
-
/** How many preface bytes each slot has read; 24 once the preface is whole and fed. */
|
|
133
|
-
private got: i32[]
|
|
134
|
-
/** When each slot was accepted, in `monotonicNanos`: its preface deadline's start. */
|
|
135
|
-
private since: i64[]
|
|
136
|
-
/** Whether each slot's socket has ended and `endInput` was called for it. */
|
|
137
|
-
private ended: boolean[]
|
|
153
|
+
/** The slots accepted into so far, slot `k` at `k`; a free one keeps its socket at -1. */
|
|
154
|
+
private held: H2cSlot[]
|
|
155
|
+
/** The slots closed since they were used, a stack `accept` takes from before it makes a new one. */
|
|
156
|
+
private free: H2cSlot[]
|
|
138
157
|
/** The last accepted peer's address, in `nish:net`'s 18-byte form. */
|
|
139
158
|
private peer: u8[]
|
|
140
159
|
/** How many slots the pool may hold. */
|
|
@@ -143,14 +162,18 @@ export class Http2CleartextServer {
|
|
|
143
162
|
private listener: i32 = -1
|
|
144
163
|
/** Nanoseconds a slot may wait for its whole preface before `expire` closes it. */
|
|
145
164
|
private prefaceNanos: i64 = 0
|
|
146
|
-
/**
|
|
147
|
-
|
|
165
|
+
/**
|
|
166
|
+
* How many held slots have not read their whole preface: `expire` walks none
|
|
167
|
+
* while this is 0. At most one per slot, and `accept` and `close` keep it
|
|
168
|
+
* exact, so the unsigned count neither wraps up nor goes below 0.
|
|
169
|
+
*/
|
|
170
|
+
private waiting: u32 = 0
|
|
148
171
|
|
|
149
172
|
/**
|
|
150
173
|
* A pool of `size` slots serving HTTP/2 under `config` on `listener`. Only
|
|
151
174
|
* slot 0's connection is made here, so a config it refuses panics now, with
|
|
152
175
|
* its words; every other slot's is made by the first `accept` into it and
|
|
153
|
-
* kept
|
|
176
|
+
* kept, with the slot's 24-byte preface array.
|
|
154
177
|
*
|
|
155
178
|
* @param config The caps every slot's connection is made under; kept, and shared by every slot.
|
|
156
179
|
* @param listener The listening socket from `tcpListen`; the program still owns it and closes it.
|
|
@@ -170,12 +193,8 @@ export class Http2CleartextServer {
|
|
|
170
193
|
this.slots = size
|
|
171
194
|
this.prefaceNanos = toI64(prefaceTimeout) * H2C_NANOS_PER_MS
|
|
172
195
|
this.connections = []
|
|
173
|
-
this.
|
|
196
|
+
this.held = []
|
|
174
197
|
this.free = []
|
|
175
|
-
this.got = []
|
|
176
|
-
this.since = []
|
|
177
|
-
this.ended = []
|
|
178
|
-
this.prefaces = new Array<u8>(size * H2C_PREFACE_SIZE)
|
|
179
198
|
this.peer = new Array<u8>(H2C_ADDRESS_SIZE)
|
|
180
199
|
this.date = new HttpDate()
|
|
181
200
|
// Formatted once now, so no slot ever sends the bytes before a first format.
|
|
@@ -187,17 +206,30 @@ export class Http2CleartextServer {
|
|
|
187
206
|
first.pools = this.pools
|
|
188
207
|
}
|
|
189
208
|
|
|
190
|
-
/** Makes the next slot's connection, on this pool's buffers and `date
|
|
191
|
-
private build():
|
|
209
|
+
/** Makes the next slot's connection, on this pool's buffers and `date`, and answers it. */
|
|
210
|
+
private build(): Http2Connection {
|
|
192
211
|
const conn: Http2Connection = new Http2Connection(this.config)
|
|
193
212
|
conn.date = this.date.current()
|
|
194
213
|
conn.pools = this.pools
|
|
195
214
|
this.connections.push(conn)
|
|
215
|
+
return conn
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/** The slot `slot` names, or null when it is out of range or never accepted into. */
|
|
219
|
+
private at(slot: i32): H2cSlot | null {
|
|
220
|
+
return slot >= 0 && slot < toI32(this.held.length) ? this.held[slot] : null
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/** The slot `slot` names when it holds a socket, or null. */
|
|
224
|
+
private open(slot: i32): H2cSlot | null {
|
|
225
|
+
const s: H2cSlot | null = this.at(slot)
|
|
226
|
+
return s !== null && s.fd >= 0 ? s : null
|
|
196
227
|
}
|
|
197
228
|
|
|
198
229
|
/** Whether `slot` holds a socket and has read its whole preface. */
|
|
199
230
|
private live(slot: i32): boolean {
|
|
200
|
-
|
|
231
|
+
const s: H2cSlot | null = this.open(slot)
|
|
232
|
+
return s !== null && s.got === H2C_PREFACE_SIZE
|
|
201
233
|
}
|
|
202
234
|
|
|
203
235
|
/**
|
|
@@ -215,13 +247,14 @@ export class Http2CleartextServer {
|
|
|
215
247
|
* @returns Slots with an open socket, whether their preface is whole or not; 0 to `size()`.
|
|
216
248
|
*/
|
|
217
249
|
busy(): i32 {
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
250
|
+
// At most one per slot, so the unsigned count cannot wrap.
|
|
251
|
+
let n: u32 = 0
|
|
252
|
+
for (const s of this.held) {
|
|
253
|
+
if (s.fd >= 0) {
|
|
254
|
+
n += 1
|
|
222
255
|
}
|
|
223
256
|
}
|
|
224
|
-
return n
|
|
257
|
+
return toI32(n)
|
|
225
258
|
}
|
|
226
259
|
|
|
227
260
|
/**
|
|
@@ -231,7 +264,7 @@ export class Http2CleartextServer {
|
|
|
231
264
|
* @returns True when `slot` is in range and holds a socket.
|
|
232
265
|
*/
|
|
233
266
|
holds(slot: i32): boolean {
|
|
234
|
-
return
|
|
267
|
+
return this.open(slot) !== null
|
|
235
268
|
}
|
|
236
269
|
|
|
237
270
|
/**
|
|
@@ -242,7 +275,8 @@ export class Http2CleartextServer {
|
|
|
242
275
|
* none.
|
|
243
276
|
*/
|
|
244
277
|
fd(slot: i32): i32 {
|
|
245
|
-
|
|
278
|
+
const s: H2cSlot | null = this.open(slot)
|
|
279
|
+
return s !== null ? s.fd : H2C_NO_FD
|
|
246
280
|
}
|
|
247
281
|
|
|
248
282
|
/**
|
|
@@ -265,8 +299,14 @@ export class Http2CleartextServer {
|
|
|
265
299
|
*/
|
|
266
300
|
connection(slot: i32): Http2Connection {
|
|
267
301
|
this.date.current()
|
|
268
|
-
|
|
269
|
-
|
|
302
|
+
if (slot >= 0 && slot < toI32(this.connections.length)) {
|
|
303
|
+
return this.connections[slot]
|
|
304
|
+
}
|
|
305
|
+
// Slot 0's connection, made by the constructor, answers for any other slot, so this builds none.
|
|
306
|
+
if (toI32(this.connections.length) > 0) {
|
|
307
|
+
return this.connections[0]
|
|
308
|
+
}
|
|
309
|
+
return this.build()
|
|
270
310
|
}
|
|
271
311
|
|
|
272
312
|
/**
|
|
@@ -284,33 +324,44 @@ export class Http2CleartextServer {
|
|
|
284
324
|
if (fd < 0) {
|
|
285
325
|
return fd
|
|
286
326
|
}
|
|
287
|
-
|
|
288
|
-
if (
|
|
289
|
-
k = this.free[this.free.length - 1]
|
|
290
|
-
this.free.pop()
|
|
291
|
-
} else if (toI32(this.fds.length) < this.slots) {
|
|
292
|
-
k = toI32(this.fds.length)
|
|
293
|
-
this.fds.push(H2C_NO_FD)
|
|
294
|
-
this.got.push(H2C_ZERO)
|
|
295
|
-
this.since.push(toI64(H2C_ZERO))
|
|
296
|
-
this.ended.push(false)
|
|
297
|
-
}
|
|
298
|
-
if (k < 0) {
|
|
327
|
+
const s: H2cSlot | null = this.take()
|
|
328
|
+
if (s === null) {
|
|
299
329
|
netClose(fd)
|
|
300
330
|
return H2C_POOL_FULL
|
|
301
331
|
}
|
|
302
|
-
//
|
|
303
|
-
|
|
332
|
+
// `restart` gives back every buffer; the preface is read before any is borrowed.
|
|
333
|
+
s.conn.restart()
|
|
334
|
+
s.fd = fd
|
|
335
|
+
s.got = H2C_ZERO
|
|
336
|
+
s.since = monotonicNanos()
|
|
337
|
+
s.ended = false
|
|
338
|
+
this.waiting += 1
|
|
339
|
+
return s.at
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
/** A free slot for `accept`: a closed one first, then the next never used; null when every slot is busy. */
|
|
343
|
+
private take(): H2cSlot | null {
|
|
344
|
+
const free: H2cSlot[] = this.free
|
|
345
|
+
const f: i32 = toI32(free.length)
|
|
346
|
+
// `f > 0` proves the index and `free.length > 0` the `pop`, which the prover reads only off the array.
|
|
347
|
+
if (f > 0 && free.length > 0) {
|
|
348
|
+
const s: H2cSlot = free[f - 1]
|
|
349
|
+
free.pop()
|
|
350
|
+
return s
|
|
351
|
+
}
|
|
352
|
+
const k: i32 = toI32(this.held.length)
|
|
353
|
+
if (k >= this.slots) {
|
|
354
|
+
return null
|
|
355
|
+
}
|
|
356
|
+
// Slots are made in order and slot 0's connection by the constructor, so this makes one connection at
|
|
357
|
+
// most.
|
|
358
|
+
while (toI32(this.connections.length) < k) {
|
|
304
359
|
this.build()
|
|
305
360
|
}
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
this.
|
|
309
|
-
|
|
310
|
-
this.since[k] = monotonicNanos()
|
|
311
|
-
this.ended[k] = false
|
|
312
|
-
this.waiting = this.waiting + 1
|
|
313
|
-
return k
|
|
361
|
+
const conn: Http2Connection = k < toI32(this.connections.length) ? this.connections[k] : this.build()
|
|
362
|
+
const s: H2cSlot = new H2cSlot(k, conn)
|
|
363
|
+
this.held.push(s)
|
|
364
|
+
return s
|
|
314
365
|
}
|
|
315
366
|
|
|
316
367
|
/**
|
|
@@ -322,16 +373,18 @@ export class Http2CleartextServer {
|
|
|
322
373
|
* @returns True once the preface is whole; false while it is not, or once the slot is closed.
|
|
323
374
|
*/
|
|
324
375
|
private admit(slot: i32): boolean {
|
|
325
|
-
|
|
376
|
+
const s: H2cSlot | null = this.open(slot)
|
|
377
|
+
if (s === null) {
|
|
326
378
|
return false
|
|
327
379
|
}
|
|
328
|
-
if (
|
|
380
|
+
if (s.got === H2C_PREFACE_SIZE) {
|
|
329
381
|
return true
|
|
330
382
|
}
|
|
331
|
-
const
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
383
|
+
const preface: u8[] = s.preface
|
|
384
|
+
const want: string = H2C_PREFACE
|
|
385
|
+
let have: i32 = s.got
|
|
386
|
+
while (have >= 0 && have < H2C_PREFACE_SIZE) {
|
|
387
|
+
const n: i32 = netRead(s.fd, preface, have, H2C_PREFACE_SIZE - have)
|
|
335
388
|
if (n === H2C_AGAIN) {
|
|
336
389
|
return false
|
|
337
390
|
}
|
|
@@ -339,16 +392,22 @@ export class Http2CleartextServer {
|
|
|
339
392
|
this.close(slot)
|
|
340
393
|
return false
|
|
341
394
|
}
|
|
342
|
-
|
|
343
|
-
|
|
395
|
+
// `netRead` answers at most the 24 - `have` bytes it was asked for, so the unsigned sum is at most 24.
|
|
396
|
+
const end: i32 = toI32(toU32(have) + toU32(n))
|
|
397
|
+
for (let k: i32 = have; k < end; k++) {
|
|
398
|
+
if (k < 0 || k >= toI32(preface.length) || k >= toI32(want.length)) {
|
|
399
|
+
break
|
|
400
|
+
}
|
|
401
|
+
if (toI32(preface[k]) !== toI32(want.charCodeAt(k))) {
|
|
344
402
|
this.close(slot)
|
|
345
403
|
return false
|
|
346
404
|
}
|
|
347
405
|
}
|
|
348
|
-
|
|
406
|
+
s.got = end
|
|
407
|
+
have = end
|
|
349
408
|
}
|
|
350
|
-
this.waiting
|
|
351
|
-
|
|
409
|
+
this.waiting -= 1
|
|
410
|
+
s.conn.feed(preface, H2C_ZERO, H2C_PREFACE_SIZE)
|
|
352
411
|
return true
|
|
353
412
|
}
|
|
354
413
|
|
|
@@ -391,28 +450,29 @@ export class Http2CleartextServer {
|
|
|
391
450
|
* that failed, a free slot, or one closed for a bad preface.
|
|
392
451
|
*/
|
|
393
452
|
next(slot: i32): i32 {
|
|
394
|
-
|
|
453
|
+
const s: H2cSlot | null = this.open(slot)
|
|
454
|
+
if (s === null) {
|
|
395
455
|
return H2_ERROR
|
|
396
456
|
}
|
|
397
457
|
if (!this.admit(slot)) {
|
|
398
|
-
return
|
|
458
|
+
return s.fd >= 0 ? H2_NEED_MORE : H2_ERROR
|
|
399
459
|
}
|
|
400
460
|
this.date.current()
|
|
401
|
-
const conn: Http2Connection =
|
|
461
|
+
const conn: Http2Connection = s.conn
|
|
402
462
|
// The socket is read straight into the connection's input, so a byte is
|
|
403
463
|
// copied once on its way in.
|
|
404
|
-
while (!
|
|
464
|
+
while (!s.ended) {
|
|
405
465
|
const room: i32 = conn.inputTail()
|
|
406
466
|
if (room <= 0) {
|
|
407
467
|
break
|
|
408
468
|
}
|
|
409
|
-
const n: i32 = netRead(
|
|
469
|
+
const n: i32 = netRead(s.fd, conn.input, conn.inputEnd, room)
|
|
410
470
|
if (n === H2C_AGAIN) {
|
|
411
471
|
break
|
|
412
472
|
}
|
|
413
473
|
if (n <= 0) {
|
|
414
474
|
// The peer's end, or a socket that failed: either way nothing more comes.
|
|
415
|
-
|
|
475
|
+
s.ended = true
|
|
416
476
|
conn.endInput()
|
|
417
477
|
break
|
|
418
478
|
}
|
|
@@ -439,20 +499,22 @@ export class Http2CleartextServer {
|
|
|
439
499
|
* preface.
|
|
440
500
|
*/
|
|
441
501
|
flush(slot: i32): i32 {
|
|
442
|
-
|
|
502
|
+
const s: H2cSlot | null = this.open(slot)
|
|
503
|
+
if (s === null) {
|
|
443
504
|
return H2C_DONE
|
|
444
505
|
}
|
|
445
|
-
if (
|
|
506
|
+
if (s.got !== H2C_PREFACE_SIZE) {
|
|
446
507
|
return H2C_WANT_READ
|
|
447
508
|
}
|
|
448
|
-
const conn: Http2Connection =
|
|
509
|
+
const conn: Http2Connection = s.conn
|
|
449
510
|
while (conn.wantsWrite()) {
|
|
450
|
-
const
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
511
|
+
const start: i32 = conn.outputStart
|
|
512
|
+
const end: i32 = conn.outputEnd
|
|
513
|
+
if (start < 0 || end < start) {
|
|
514
|
+
break
|
|
515
|
+
}
|
|
516
|
+
// Both ends checked just above, so the unsigned difference is the span's length and does not wrap.
|
|
517
|
+
const n: i32 = netWrite(s.fd, conn.output, start, toI32(toU32(end) - toU32(start)))
|
|
456
518
|
if (n === H2C_AGAIN) {
|
|
457
519
|
break
|
|
458
520
|
}
|
|
@@ -466,7 +528,7 @@ export class Http2CleartextServer {
|
|
|
466
528
|
if (conn.isDone()) {
|
|
467
529
|
return H2C_DONE
|
|
468
530
|
}
|
|
469
|
-
const read: i32 =
|
|
531
|
+
const read: i32 = s.ended ? H2C_ZERO : H2C_WANT_READ
|
|
470
532
|
return conn.wantsWrite() ? read | H2C_WANT_WRITE : read
|
|
471
533
|
}
|
|
472
534
|
|
|
@@ -482,14 +544,21 @@ export class Http2CleartextServer {
|
|
|
482
544
|
if (this.waiting === 0) {
|
|
483
545
|
return 0
|
|
484
546
|
}
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
547
|
+
// At most one per slot, so the unsigned count cannot wrap.
|
|
548
|
+
let n: u32 = 0
|
|
549
|
+
for (const s of this.held) {
|
|
550
|
+
// `now` at or past `since`, so the unsigned difference is the wait, which does not wrap.
|
|
551
|
+
if (
|
|
552
|
+
s.fd >= 0 &&
|
|
553
|
+
s.got < H2C_PREFACE_SIZE &&
|
|
554
|
+
now >= s.since &&
|
|
555
|
+
toU64(now) - toU64(s.since) >= toU64(this.prefaceNanos)
|
|
556
|
+
) {
|
|
557
|
+
this.close(s.at)
|
|
558
|
+
n += 1
|
|
490
559
|
}
|
|
491
560
|
}
|
|
492
|
-
return n
|
|
561
|
+
return toI32(n)
|
|
493
562
|
}
|
|
494
563
|
|
|
495
564
|
/**
|
|
@@ -500,17 +569,18 @@ export class Http2CleartextServer {
|
|
|
500
569
|
* @param slot The slot to free; for a free or unknown slot nothing is closed.
|
|
501
570
|
*/
|
|
502
571
|
close(slot: i32): void {
|
|
503
|
-
|
|
572
|
+
const s: H2cSlot | null = this.open(slot)
|
|
573
|
+
if (s === null) {
|
|
504
574
|
return
|
|
505
575
|
}
|
|
506
|
-
netClose(
|
|
507
|
-
|
|
508
|
-
if (
|
|
509
|
-
this.waiting
|
|
576
|
+
netClose(s.fd)
|
|
577
|
+
s.fd = H2C_NO_FD
|
|
578
|
+
if (s.got < H2C_PREFACE_SIZE) {
|
|
579
|
+
this.waiting -= 1
|
|
510
580
|
}
|
|
511
|
-
|
|
512
|
-
this.free.push(
|
|
513
|
-
|
|
581
|
+
s.got = H2C_ZERO
|
|
582
|
+
this.free.push(s)
|
|
583
|
+
s.conn.drop()
|
|
514
584
|
}
|
|
515
585
|
|
|
516
586
|
/**
|