nish 0.35.0 → 0.36.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/docs/AI.md +9 -2
- package/docs/INSTALL.md +6 -1
- package/package.json +15 -5
- package/runtime/nish.d.ts +4612 -430
- package/runtime/vite.d.ts +30 -0
- package/runtime/vite.mjs +150 -0
- package/scripts/build.sh +108 -13
- package/std/base64.ts +34 -5
- package/std/bytes.ts +256 -40
- package/std/cli-args.ts +296 -70
- package/std/cli-flags.ts +184 -19
- package/std/cli.ts +475 -54
- package/std/collections.ts +121 -23
- package/std/compress/checksum.ts +44 -14
- package/std/compress/deflate.ts +224 -111
- package/std/compress/gzip.ts +217 -53
- package/std/compress/zlib.ts +63 -7
- package/std/crypto/aes.ts +80 -9
- package/std/crypto/base64url.ts +22 -0
- package/std/crypto/bcrypt-batch.ts +88 -21
- package/std/crypto/bcrypt.ts +60 -0
- package/std/crypto/chacha20poly1305.ts +53 -0
- package/std/crypto/ct.ts +32 -13
- package/std/crypto/ed25519.ts +47 -0
- package/std/crypto/hkdf.ts +198 -13
- package/std/crypto/hmac.ts +235 -31
- package/std/crypto/jwt.ts +192 -63
- package/std/crypto/p256.ts +159 -16
- package/std/crypto/p384.ts +28 -3
- package/std/crypto/pki-roots.ts +32 -2
- package/std/crypto/pki.ts +81 -15
- package/std/crypto/rsa.ts +33 -3
- package/std/crypto/sha1.ts +3 -0
- package/std/crypto/sha256.ts +24 -1
- package/std/crypto/sha512.ts +99 -14
- package/std/crypto/x25519.ts +152 -14
- package/std/crypto/x509-random.ts +10 -0
- package/std/crypto/x509.ts +67 -7
- package/std/json-equal.ts +19 -0
- package/std/json-format.ts +112 -13
- package/std/json-number.ts +64 -14
- package/std/json-pointer.ts +23 -1
- package/std/json-tokenizer.ts +100 -29
- package/std/json-typed.ts +713 -66
- package/std/json-value.ts +400 -124
- package/std/json.ts +138 -10
- package/std/map.ts +25 -7
- package/std/math.ts +36 -4
- package/std/net/buffer-pool.ts +42 -11
- package/std/net/dns-config.ts +109 -23
- package/std/net/dns-message.ts +62 -7
- package/std/net/dns-resolver.ts +247 -53
- package/std/net/dns.ts +203 -35
- package/std/net/fetch.ts +151 -61
- package/std/net/handler.ts +278 -80
- package/std/net/hpack.ts +262 -52
- package/std/net/http-compress.ts +125 -15
- package/std/net/http-fields.ts +85 -9
- package/std/net/http1-client-codec.ts +100 -19
- package/std/net/http1-codec.ts +235 -27
- package/std/net/http1-server.ts +343 -85
- package/std/net/http2-frame.ts +272 -35
- package/std/net/http2-tls.ts +135 -34
- package/std/net/http2.ts +247 -106
- package/std/net/http3-frame.ts +154 -17
- package/std/net/http3-server.ts +246 -96
- package/std/net/http3.ts +307 -115
- package/std/net/outbound.ts +37 -3
- package/std/net/postgres-carrier.ts +144 -8
- package/std/net/postgres.ts +723 -103
- package/std/net/prefork.ts +164 -31
- package/std/net/qpack.ts +105 -18
- package/std/net/quic-conn-ack.ts +59 -12
- package/std/net/quic-conn-cid.ts +124 -27
- package/std/net/quic-conn-params.ts +70 -10
- package/std/net/quic-datagram.ts +43 -3
- package/std/net/quic-frame.ts +286 -12
- package/std/net/quic-listener.ts +101 -32
- package/std/net/quic-packet.ts +302 -21
- package/std/net/quic-recovery.ts +228 -44
- package/std/net/quic-stream.ts +353 -91
- package/std/net/quic.ts +489 -171
- package/std/net/router.ts +87 -40
- package/std/net/tls/client.ts +166 -51
- package/std/net/tls/codec.ts +413 -56
- package/std/net/tls/record-client.ts +110 -55
- package/std/net/tls/record-server.ts +159 -59
- package/std/net/tls/record.ts +109 -12
- package/std/net/tls/schedule.ts +235 -26
- package/std/net/tls/ticket.ts +159 -40
- package/std/net/tls/verify.ts +49 -3
- package/std/net/tls-tcp.ts +250 -45
- package/std/net/tls.ts +221 -59
- package/std/net/upstream.ts +81 -45
- package/std/net/url.ts +97 -13
- package/std/net/websocket.ts +122 -12
- package/std/net/webtransport.ts +220 -89
- package/std/pair.ts +10 -2
- package/std/random.ts +34 -9
- package/std/regex.ts +352 -198
- package/std/region.ts +70 -15
- package/std/secret.ts +52 -11
- package/std/sort.ts +17 -2
- package/std/sqlite.ts +256 -35
- package/std/sync/ring.ts +205 -35
- package/std/sync/shm.ts +194 -16
- package/std/term-io.ts +137 -64
- package/std/term-pixels.ts +144 -19
- package/std/term-probe.ts +66 -25
- package/std/term-rate.ts +128 -57
- package/std/term.ts +332 -121
- package/std/testing.ts +130 -32
- package/std/text.ts +73 -7
- package/std/threads.ts +229 -41
- package/std/yaml-json.ts +94 -82
- package/std/yaml-lines.ts +47 -15
- package/std/yaml-write.ts +24 -16
- package/std/yaml.ts +764 -384
package/std/net/http1-server.ts
CHANGED
|
@@ -197,6 +197,7 @@ export const H1_POOL_FULL: i32 = -105
|
|
|
197
197
|
|
|
198
198
|
/** Interest bits, the same as `nish/net/tls/record-server`'s: the low two are `pollModify`'s events. */
|
|
199
199
|
export const H1_WANT_READ: i32 = 1
|
|
200
|
+
/** The slot has output waiting for the socket: ask the readiness loop for writable. */
|
|
200
201
|
export const H1_WANT_WRITE: i32 = 2
|
|
201
202
|
/** The slot's connection is over and every byte is sent: `close` it. */
|
|
202
203
|
export const H1_DONE: i32 = 16
|
|
@@ -286,19 +287,19 @@ const http1ServerCopy = (out: u8[], at: i32, src: readonly u8[], off: i32, n: i3
|
|
|
286
287
|
*/
|
|
287
288
|
export class HttpDate {
|
|
288
289
|
/** The IMF-fixdate of `second`: what `current` answers, made once. */
|
|
289
|
-
bytes: u8[]
|
|
290
|
+
private bytes: u8[]
|
|
290
291
|
/** The second `bytes` holds, since 1970; -1 before the first `current`. */
|
|
291
|
-
second: i64 = -1
|
|
292
|
+
private second: i64 = -1
|
|
292
293
|
/** The instant `pin` fixed, in milliseconds since 1970, while `pinned`. */
|
|
293
|
-
pinnedMs: i64 = 0
|
|
294
|
+
private pinnedMs: i64 = 0
|
|
294
295
|
/** The clock reading `hold` took, in milliseconds since 1970, while `held`. */
|
|
295
|
-
heldMs: i64 = 0
|
|
296
|
+
private heldMs: i64 = 0
|
|
296
297
|
/** How many times `bytes` has been rewritten. */
|
|
297
|
-
rewrites: i64 = 0
|
|
298
|
+
private rewrites: i64 = 0
|
|
298
299
|
/** How many times the wall clock has been read. */
|
|
299
|
-
reads: i64 = 0
|
|
300
|
-
pinned: boolean = false
|
|
301
|
-
held: boolean = false
|
|
300
|
+
private reads: i64 = 0
|
|
301
|
+
private pinned: boolean = false
|
|
302
|
+
private held: boolean = false
|
|
302
303
|
|
|
303
304
|
/** A date on the wall clock, with nothing formatted yet. */
|
|
304
305
|
constructor() {
|
|
@@ -311,6 +312,8 @@ export class HttpDate {
|
|
|
311
312
|
* steps back. It allocates nothing, and the array is the same one each time,
|
|
312
313
|
* so a caller copies it out rather than keeping it. A wall clock before 1970
|
|
313
314
|
* or past 9999 answers the nearer of the two ends.
|
|
315
|
+
*
|
|
316
|
+
* @returns the object's own 29-byte IMF-fixdate of the current second, to copy before the next call rewrites it
|
|
314
317
|
*/
|
|
315
318
|
current(): u8[] {
|
|
316
319
|
let ms: i64 = this.pinnedMs
|
|
@@ -335,6 +338,9 @@ export class HttpDate {
|
|
|
335
338
|
* Makes `current` answer `unixMs`, milliseconds since 1970, until `unpin`.
|
|
336
339
|
* False, and nothing changed, for an instant before 1970-01-01T00:00:00Z or
|
|
337
340
|
* after 9999-12-31T23:59:59.999Z, which an IMF-fixdate cannot name.
|
|
341
|
+
*
|
|
342
|
+
* @param unixMs the instant every later `current` names, in milliseconds since 1970
|
|
343
|
+
* @returns true once the date is pinned; false when the instant is out of the IMF-fixdate's range
|
|
338
344
|
*/
|
|
339
345
|
pin(unixMs: i64): boolean {
|
|
340
346
|
if (unixMs < 0 || unixMs / 1000 > HTTP_DATE_LAST_SECOND) {
|
|
@@ -368,17 +374,25 @@ export class HttpDate {
|
|
|
368
374
|
}
|
|
369
375
|
|
|
370
376
|
/** The wall clock, in milliseconds since 1970. */
|
|
371
|
-
now(): i64 {
|
|
377
|
+
private now(): i64 {
|
|
372
378
|
this.reads += 1
|
|
373
379
|
return toI64(Date.now())
|
|
374
380
|
}
|
|
375
381
|
|
|
376
|
-
/**
|
|
382
|
+
/**
|
|
383
|
+
* How many times the wall clock has been read: once per `hold`, and once per `current` outside one.
|
|
384
|
+
*
|
|
385
|
+
* @returns the count of `Date.now()` reads since the date was made, for a test that checks a serve call reads once
|
|
386
|
+
*/
|
|
377
387
|
clockReads(): i64 {
|
|
378
388
|
return this.reads
|
|
379
389
|
}
|
|
380
390
|
|
|
381
|
-
/**
|
|
391
|
+
/**
|
|
392
|
+
* How many times the bytes have been rewritten: one per second that `current` was asked for, at most.
|
|
393
|
+
*
|
|
394
|
+
* @returns the count of IMF-fixdate formats since the date was made, for a test that checks the once-a-second promise
|
|
395
|
+
*/
|
|
382
396
|
formats(): i64 {
|
|
383
397
|
return this.rewrites
|
|
384
398
|
}
|
|
@@ -495,16 +509,25 @@ const http1ServerReserved = (name: u8[]): boolean =>
|
|
|
495
509
|
export class Http1OutputPool {
|
|
496
510
|
// Widest first, so the layout packs without padding.
|
|
497
511
|
free: u8[][]
|
|
498
|
-
size: i32 = 0
|
|
512
|
+
private size: i32 = 0
|
|
499
513
|
/** How many buffers the pool has made. */
|
|
500
514
|
made: i32 = 0
|
|
501
515
|
|
|
516
|
+
/**
|
|
517
|
+
* An empty pool: no buffer is made until the first `take`.
|
|
518
|
+
*
|
|
519
|
+
* @param size the length in bytes of every buffer the pool makes
|
|
520
|
+
*/
|
|
502
521
|
constructor(size: i32) {
|
|
503
522
|
this.size = size
|
|
504
523
|
this.free = []
|
|
505
524
|
}
|
|
506
525
|
|
|
507
|
-
/**
|
|
526
|
+
/**
|
|
527
|
+
* A buffer of `size` bytes: the one given back last, or a new one.
|
|
528
|
+
*
|
|
529
|
+
* @internal Called by `Http1Connection` in this module, when it first needs room to write and when it unparks its input and head buffers.
|
|
530
|
+
*/
|
|
508
531
|
take(): u8[] {
|
|
509
532
|
if (this.free.length > 0) {
|
|
510
533
|
const buf: u8[] = this.free[this.free.length - 1]
|
|
@@ -515,7 +538,11 @@ export class Http1OutputPool {
|
|
|
515
538
|
return new Array<u8>(this.size)
|
|
516
539
|
}
|
|
517
540
|
|
|
518
|
-
/**
|
|
541
|
+
/**
|
|
542
|
+
* Takes back a buffer `take` gave.
|
|
543
|
+
*
|
|
544
|
+
* @internal Called by `Http1Connection` in this module, from `release` and `park`, once a borrowed buffer holds nothing it still needs.
|
|
545
|
+
*/
|
|
519
546
|
give(buf: u8[]): void {
|
|
520
547
|
this.free.push(buf)
|
|
521
548
|
}
|
|
@@ -564,14 +591,20 @@ export class Http1Connection {
|
|
|
564
591
|
lastActive: i64 = 0
|
|
565
592
|
/** When the head being read began to arrive, in `monotonicNanos`; meaningful while `headTimed`. */
|
|
566
593
|
headSince: i64 = 0
|
|
567
|
-
state: i32 = 0
|
|
568
|
-
response: i32 = 0
|
|
594
|
+
private state: i32 = 0
|
|
595
|
+
private response: i32 = 0
|
|
569
596
|
/**
|
|
570
597
|
* How the response's body is framed: a length (0 or more), `HTTP1_CHUNKED`,
|
|
571
598
|
* or `HTTP1_NO_BODY` for one that ends with the connection.
|
|
599
|
+
*
|
|
600
|
+
* @internal Read by `std/net/handler.ts` to tell a sized response from a chunked one when it checks a write against what is owed.
|
|
572
601
|
*/
|
|
573
602
|
responseFraming: i32 = 0
|
|
574
|
-
/**
|
|
603
|
+
/**
|
|
604
|
+
* A response with a length: the bytes it still owes.
|
|
605
|
+
*
|
|
606
|
+
* @internal Read by `std/net/handler.ts` to know how much of a sized body is still to write.
|
|
607
|
+
*/
|
|
575
608
|
responseLeft: i32 = 0
|
|
576
609
|
outputStart: i32 = 0
|
|
577
610
|
outputEnd: i32 = 0
|
|
@@ -581,24 +614,24 @@ export class Http1Connection {
|
|
|
581
614
|
* the empty one is out of cache by the time a resting connection's next
|
|
582
615
|
* request comes. Only the connection assigns `output`, and with it this.
|
|
583
616
|
*/
|
|
584
|
-
outputCap: i32 = 0
|
|
617
|
+
private outputCap: i32 = 0
|
|
585
618
|
/** The most input the connection buffers, unread: the cap `inputRoom` holds it to. */
|
|
586
619
|
bufferLimit: i32 = 0
|
|
587
620
|
/** A request's head has been read and its exchange is not over. */
|
|
588
|
-
requestOpen: boolean = false
|
|
621
|
+
private requestOpen: boolean = false
|
|
589
622
|
/** The request's body has been read to its end. */
|
|
590
|
-
requestEnded: boolean = false
|
|
623
|
+
private requestEnded: boolean = false
|
|
591
624
|
/** The response carries no body (HEAD, 204, 304): what is written is dropped. */
|
|
592
625
|
responseEmpty: boolean = false
|
|
593
626
|
/** The connection closes once this exchange is over. */
|
|
594
627
|
closeAfter: boolean = false
|
|
595
628
|
/** The program accepted the request's WebSocket handshake. */
|
|
596
|
-
upgraded: boolean = false
|
|
629
|
+
private upgraded: boolean = false
|
|
597
630
|
/** A write was held back; `next` answers nothing but `H1_WRITE` until there is room. */
|
|
598
631
|
writeHeld: boolean = false
|
|
599
|
-
pongPending: boolean = false
|
|
632
|
+
private pongPending: boolean = false
|
|
600
633
|
/** The peer's byte stream has ended. */
|
|
601
|
-
inputEnded: boolean = false
|
|
634
|
+
private inputEnded: boolean = false
|
|
602
635
|
/** A head has begun to arrive and is not read whole yet: `headSince` is its deadline's start. */
|
|
603
636
|
headTimed: boolean = false
|
|
604
637
|
dataStart: i32 = 0
|
|
@@ -607,7 +640,7 @@ export class Http1Connection {
|
|
|
607
640
|
opcode: i32 = 0
|
|
608
641
|
/** `H1_ERROR`'s HTTP status or WebSocket close code, or `H1_WS_CLOSE`'s close code. */
|
|
609
642
|
status: i32 = 0
|
|
610
|
-
pongLength: i32 = 0
|
|
643
|
+
private pongLength: i32 = 0
|
|
611
644
|
/**
|
|
612
645
|
* The TCP maximum segment size the program sets for this connection, for
|
|
613
646
|
* `respondEncoded` under `HttpCompressor.segmentMode`; 0, the default,
|
|
@@ -625,7 +658,7 @@ export class Http1Connection {
|
|
|
625
658
|
* as `write` does.
|
|
626
659
|
*/
|
|
627
660
|
fd: i32 = -1
|
|
628
|
-
config: Http1Config
|
|
661
|
+
private config: Http1Config
|
|
629
662
|
/**
|
|
630
663
|
* The frame decoder: made when the slot first switches to WebSocket, so a
|
|
631
664
|
* slot that only ever speaks HTTP never holds its buffers, then kept for
|
|
@@ -637,9 +670,13 @@ export class Http1Connection {
|
|
|
637
670
|
/** A ping's payload, kept until its pong fits: empty until the first ping. */
|
|
638
671
|
pong: u8[]
|
|
639
672
|
/** No fields, for the responses the connection writes itself: made once. */
|
|
640
|
-
noFields: u8[][]
|
|
673
|
+
private noFields: u8[][]
|
|
641
674
|
|
|
642
|
-
/**
|
|
675
|
+
/**
|
|
676
|
+
* A connection under `config`. A cap outside what the connection can work with panics.
|
|
677
|
+
*
|
|
678
|
+
* @param config the caps the connection is held to, read now and kept
|
|
679
|
+
*/
|
|
643
680
|
constructor(config: Http1Config) {
|
|
644
681
|
const big: i32 = 1073741824
|
|
645
682
|
const one: i32 = 1
|
|
@@ -780,12 +817,20 @@ export class Http1Connection {
|
|
|
780
817
|
|
|
781
818
|
// ---- Bytes in and out ---------------------------------------------------------
|
|
782
819
|
|
|
783
|
-
/**
|
|
820
|
+
/**
|
|
821
|
+
* The most input the connection holds unread: what `inputRoom` counts against.
|
|
822
|
+
*
|
|
823
|
+
* @returns the cap in bytes on unread input: the buffer limit for HTTP, the message cap plus a frame header for WebSocket
|
|
824
|
+
*/
|
|
784
825
|
inputLimit(): i32 {
|
|
785
826
|
return this.state === H1_S_WEBSOCKET ? this.config.maxMessage + 14 : this.bufferLimit
|
|
786
827
|
}
|
|
787
828
|
|
|
788
|
-
/**
|
|
829
|
+
/**
|
|
830
|
+
* How many bytes `feed` would take now: none while a write is held back or once the connection is closing.
|
|
831
|
+
*
|
|
832
|
+
* @returns how many more input bytes the connection takes now; 0 asks the carrier to stop reading
|
|
833
|
+
*/
|
|
789
834
|
inputRoom(): i32 {
|
|
790
835
|
if (this.writeHeld || this.inputEnded || this.state === H1_S_CLOSING || this.state === H1_S_FAILED) {
|
|
791
836
|
return 0
|
|
@@ -806,6 +851,11 @@ export class Http1Connection {
|
|
|
806
851
|
* Takes as much of `buf[off .. off + len)` as `inputRoom` allows and
|
|
807
852
|
* answers how much; the rest is the caller's to feed again later. A window
|
|
808
853
|
* outside `buf` panics.
|
|
854
|
+
*
|
|
855
|
+
* @param buf the bytes the carrier read from the peer
|
|
856
|
+
* @param off where in `buf` the new bytes start
|
|
857
|
+
* @param len how many new bytes there are
|
|
858
|
+
* @returns how many of them the connection took, from `off`; the rest is the caller's to feed again
|
|
809
859
|
*/
|
|
810
860
|
feed(buf: u8[], off: i32, len: i32): i32 {
|
|
811
861
|
http1ServerCheckWindow("Http1Connection.feed", buf, off, len)
|
|
@@ -845,7 +895,7 @@ export class Http1Connection {
|
|
|
845
895
|
* is written into it, which is why `room` calls it. It allocates only when
|
|
846
896
|
* the pool has no free buffer, or for a connection's own, once.
|
|
847
897
|
*/
|
|
848
|
-
acquire(): void {
|
|
898
|
+
private acquire(): void {
|
|
849
899
|
if (this.outputCap > 0) {
|
|
850
900
|
return
|
|
851
901
|
}
|
|
@@ -874,7 +924,11 @@ export class Http1Connection {
|
|
|
874
924
|
this.outputEnd = 0
|
|
875
925
|
}
|
|
876
926
|
|
|
877
|
-
/**
|
|
927
|
+
/**
|
|
928
|
+
* Marks the first `n` bytes of the output sent.
|
|
929
|
+
*
|
|
930
|
+
* @param n how many bytes from `outputStart` the carrier sent; more than are waiting counts as all of them
|
|
931
|
+
*/
|
|
878
932
|
consume(n: i32): void {
|
|
879
933
|
const pending: i32 = this.outputEnd - this.outputStart
|
|
880
934
|
this.outputStart = this.outputStart + (n < pending ? n : pending)
|
|
@@ -884,12 +938,20 @@ export class Http1Connection {
|
|
|
884
938
|
}
|
|
885
939
|
}
|
|
886
940
|
|
|
887
|
-
/**
|
|
941
|
+
/**
|
|
942
|
+
* Whether the output holds bytes to send.
|
|
943
|
+
*
|
|
944
|
+
* @returns true while `output[outputStart .. outputEnd)` is not empty, so the carrier should wait for writable
|
|
945
|
+
*/
|
|
888
946
|
wantsWrite(): boolean {
|
|
889
947
|
return this.outputEnd > this.outputStart
|
|
890
948
|
}
|
|
891
949
|
|
|
892
|
-
/**
|
|
950
|
+
/**
|
|
951
|
+
* Whether the connection is over and everything is sent: the carrier closes it.
|
|
952
|
+
*
|
|
953
|
+
* @returns true once the connection is closing or failed and no byte or pong is left to send
|
|
954
|
+
*/
|
|
893
955
|
isDone(): boolean {
|
|
894
956
|
return (
|
|
895
957
|
(this.state === H1_S_CLOSING || this.state === H1_S_FAILED) && !this.wantsWrite() && !this.pongPending
|
|
@@ -897,7 +959,7 @@ export class Http1Connection {
|
|
|
897
959
|
}
|
|
898
960
|
|
|
899
961
|
/** The room at the end of the output, once what was sent is moved out of the way. */
|
|
900
|
-
room(): i32 {
|
|
962
|
+
private room(): i32 {
|
|
901
963
|
this.acquire()
|
|
902
964
|
const output: u8[] = this.output
|
|
903
965
|
const live: i32 = this.outputEnd - this.outputStart
|
|
@@ -912,14 +974,18 @@ export class Http1Connection {
|
|
|
912
974
|
}
|
|
913
975
|
|
|
914
976
|
/** The room a response or a frame may use: all but the control reserve. */
|
|
915
|
-
bodyRoom(): i32 {
|
|
977
|
+
private bodyRoom(): i32 {
|
|
916
978
|
const r: i32 = this.room() - H1_CONTROL_RESERVE
|
|
917
979
|
return r > 0 ? r : 0
|
|
918
980
|
}
|
|
919
981
|
|
|
920
982
|
// ---- Events -------------------------------------------------------------------
|
|
921
983
|
|
|
922
|
-
/**
|
|
984
|
+
/**
|
|
985
|
+
* The next event; see the module comment.
|
|
986
|
+
*
|
|
987
|
+
* @returns one of the `H1_` events: `H1_NEED_MORE` when there is nothing to hand over yet, `H1_ERROR` once the connection has failed
|
|
988
|
+
*/
|
|
923
989
|
next(): i32 {
|
|
924
990
|
if (this.state === H1_S_FAILED) {
|
|
925
991
|
return H1_ERROR
|
|
@@ -943,7 +1009,7 @@ export class Http1Connection {
|
|
|
943
1009
|
}
|
|
944
1010
|
|
|
945
1011
|
/** `next` while the connection speaks HTTP. */
|
|
946
|
-
nextRequest(): i32 {
|
|
1012
|
+
private nextRequest(): i32 {
|
|
947
1013
|
while (true) {
|
|
948
1014
|
if (this.requestEnded) {
|
|
949
1015
|
if (this.response !== H1_R_DONE) {
|
|
@@ -1014,7 +1080,7 @@ export class Http1Connection {
|
|
|
1014
1080
|
* Refuses the request with `status`: the response that says so, when none
|
|
1015
1081
|
* has started, and the close after it. Answers `H1_ERROR`.
|
|
1016
1082
|
*/
|
|
1017
|
-
fail(status: i32): i32 {
|
|
1083
|
+
private fail(status: i32): i32 {
|
|
1018
1084
|
this.status = status
|
|
1019
1085
|
if (this.response === H1_R_NONE) {
|
|
1020
1086
|
// The control reserve keeps room for this whatever the output holds.
|
|
@@ -1040,7 +1106,7 @@ export class Http1Connection {
|
|
|
1040
1106
|
}
|
|
1041
1107
|
|
|
1042
1108
|
/** The frame decoder, made on the slot's first switch to WebSocket. */
|
|
1043
|
-
decoder(): WsDecoder {
|
|
1109
|
+
private decoder(): WsDecoder {
|
|
1044
1110
|
const ws: WsDecoder | null = this.ws
|
|
1045
1111
|
if (ws !== null) {
|
|
1046
1112
|
return ws
|
|
@@ -1051,7 +1117,7 @@ export class Http1Connection {
|
|
|
1051
1117
|
}
|
|
1052
1118
|
|
|
1053
1119
|
/** `next` once the slot has switched to WebSocket. */
|
|
1054
|
-
nextFrame(): i32 {
|
|
1120
|
+
private nextFrame(): i32 {
|
|
1055
1121
|
while (true) {
|
|
1056
1122
|
if (this.pongPending && !this.sendPong()) {
|
|
1057
1123
|
return H1_NEED_MORE
|
|
@@ -1096,7 +1162,7 @@ export class Http1Connection {
|
|
|
1096
1162
|
}
|
|
1097
1163
|
|
|
1098
1164
|
/** Writes the pending pong if it fits, from the control reserve; answers whether it went. */
|
|
1099
|
-
sendPong(): boolean {
|
|
1165
|
+
private sendPong(): boolean {
|
|
1100
1166
|
this.room()
|
|
1101
1167
|
const end: i32 = websocketWriteFrame(
|
|
1102
1168
|
this.output,
|
|
@@ -1117,7 +1183,7 @@ export class Http1Connection {
|
|
|
1117
1183
|
}
|
|
1118
1184
|
|
|
1119
1185
|
/** Writes a close frame with `code` (none for 1005), from the control reserve. */
|
|
1120
|
-
sendClose(code: i32): void {
|
|
1186
|
+
private sendClose(code: i32): void {
|
|
1121
1187
|
this.room()
|
|
1122
1188
|
const payload: u8[] | null = websocketClosePayload(code, "")
|
|
1123
1189
|
// A code that may not be sent (1005, for a close that had none) is
|
|
@@ -1141,7 +1207,11 @@ export class Http1Connection {
|
|
|
1141
1207
|
|
|
1142
1208
|
// ---- The response -------------------------------------------------------------
|
|
1143
1209
|
|
|
1144
|
-
/**
|
|
1210
|
+
/**
|
|
1211
|
+
* Whether the program may answer the current request now.
|
|
1212
|
+
*
|
|
1213
|
+
* @returns true while a request's head has been read and no response to it has been started
|
|
1214
|
+
*/
|
|
1145
1215
|
answerable(): boolean {
|
|
1146
1216
|
return this.state === H1_S_HTTP && this.requestOpen && this.response === H1_R_NONE
|
|
1147
1217
|
}
|
|
@@ -1155,6 +1225,13 @@ export class Http1Connection {
|
|
|
1155
1225
|
* name or value `http1WriteResponseHead` refuses, or a head larger than the
|
|
1156
1226
|
* output; `H1_AGAIN` when the output has no room for it yet (`H1_WRITE`
|
|
1157
1227
|
* says when to try again); `H1_CLOSED` with no request to answer.
|
|
1228
|
+
*
|
|
1229
|
+
* @param status the HTTP status code to send, 100 to 599 but not 101
|
|
1230
|
+
* @param names the program's field names, one per field; nothing checks their
|
|
1231
|
+
* case, and the reserved names are refused in any ASCII case
|
|
1232
|
+
* @param values each field's value, at the same index as its name
|
|
1233
|
+
* @param bodyLength the body's length in bytes, `HTTP1_CHUNKED`, or `HTTP1_NO_BODY`
|
|
1234
|
+
* @returns 0 once the head is queued, else `H1_INVALID`, `H1_AGAIN` or `H1_CLOSED` as above
|
|
1158
1235
|
*/
|
|
1159
1236
|
respond(status: i32, names: u8[][], values: u8[][], bodyLength: i32): i32 {
|
|
1160
1237
|
if (!this.answerable()) {
|
|
@@ -1232,6 +1309,11 @@ export class Http1Connection {
|
|
|
1232
1309
|
* when nothing was. A response with no body takes everything and sends
|
|
1233
1310
|
* nothing. `H1_CLOSED` with no response under way. A window outside `buf`
|
|
1234
1311
|
* panics.
|
|
1312
|
+
*
|
|
1313
|
+
* @param buf the body bytes to send, which stay the caller's
|
|
1314
|
+
* @param off where in `buf` the window starts
|
|
1315
|
+
* @param len how many bytes the window holds
|
|
1316
|
+
* @returns how many bytes from `off` were taken, or `H1_AGAIN`, `H1_INVALID` or `H1_CLOSED` as above
|
|
1235
1317
|
*/
|
|
1236
1318
|
write(buf: readonly u8[], off: i32, len: i32): i32 {
|
|
1237
1319
|
http1ServerCheckWindow("Http1Connection.write", buf, off, len)
|
|
@@ -1288,6 +1370,11 @@ export class Http1Connection {
|
|
|
1288
1370
|
* `H1_INVALID` for more than the response still owes; `H1_CLOSED` also
|
|
1289
1371
|
* when the socket failed during the send, which aborts the connection. A
|
|
1290
1372
|
* window outside `buf` panics.
|
|
1373
|
+
*
|
|
1374
|
+
* @param buf the body bytes to send, free for the caller to reuse once this returns
|
|
1375
|
+
* @param off where in `buf` the window starts
|
|
1376
|
+
* @param len how many bytes the window holds
|
|
1377
|
+
* @returns how many bytes from `off` were sent or queued, or the error `write` would answer
|
|
1291
1378
|
*/
|
|
1292
1379
|
sendBody(buf: readonly u8[], off: i32, len: i32): i32 {
|
|
1293
1380
|
http1ServerCheckWindow("Http1Connection.sendBody", buf, off, len)
|
|
@@ -1334,6 +1421,8 @@ export class Http1Connection {
|
|
|
1334
1421
|
* `H1_INVALID` for a response with a length that still owes bytes;
|
|
1335
1422
|
* `H1_AGAIN` when the last chunk does not fit yet; `H1_CLOSED` with no
|
|
1336
1423
|
* response under way.
|
|
1424
|
+
*
|
|
1425
|
+
* @returns 0 once the response is complete, else `H1_INVALID`, `H1_AGAIN` or `H1_CLOSED` as above
|
|
1337
1426
|
*/
|
|
1338
1427
|
end(): i32 {
|
|
1339
1428
|
if (this.response !== H1_R_BODY || this.state !== H1_S_HTTP) {
|
|
@@ -1371,6 +1460,8 @@ export class Http1Connection {
|
|
|
1371
1460
|
* `HTTP_CODING_NONE` when the client refuses identity and does not take
|
|
1372
1461
|
* gzip. Allocates nothing. Read at `H1_REQUEST`, `H1_BODY` or `H1_END`
|
|
1373
1462
|
* alike: the head stays the request's until its response is done.
|
|
1463
|
+
*
|
|
1464
|
+
* @returns the `HTTP_CODING_` value the response should use, ready to pass to `respondEncoded`
|
|
1374
1465
|
*/
|
|
1375
1466
|
acceptEncoding(): i32 {
|
|
1376
1467
|
return this.acceptEncodingOf(HTTP_OFFER_GZIP)
|
|
@@ -1379,13 +1470,15 @@ export class Http1Connection {
|
|
|
1379
1470
|
/**
|
|
1380
1471
|
* Whether the current request's `Accept-Encoding` refuses the body as it
|
|
1381
1472
|
* is (`httpIdentityRefused`); `respondEncoded` then gzips any body it can.
|
|
1473
|
+
*
|
|
1474
|
+
* @returns true when the client's `Accept-Encoding` rules out the body as it is, so only a compressed one is acceptable
|
|
1382
1475
|
*/
|
|
1383
1476
|
identityRefused(): boolean {
|
|
1384
1477
|
return this.acceptEncodingOf(toI32(0)) === HTTP_CODING_NONE
|
|
1385
1478
|
}
|
|
1386
1479
|
|
|
1387
1480
|
/** `httpAcceptEncoding` of the current request's `Accept-Encoding`, with `offered`. */
|
|
1388
|
-
acceptEncodingOf(offered: i32): i32 {
|
|
1481
|
+
private acceptEncodingOf(offered: i32): i32 {
|
|
1389
1482
|
const parser: Http1Parser = this.parser
|
|
1390
1483
|
const i: i32 = parser.headerIndex("accept-encoding")
|
|
1391
1484
|
const spans: i32[] = parser.spans
|
|
@@ -1405,6 +1498,9 @@ export class Http1Connection {
|
|
|
1405
1498
|
* connection's `mss` when the program set it, else `enc.mss` when the
|
|
1406
1499
|
* program set it to other than `HTTP_DEFAULT_MSS`, else the socket's
|
|
1407
1500
|
* (`socketMss`), else `HTTP_DEFAULT_MSS`.
|
|
1501
|
+
*
|
|
1502
|
+
* @param enc the compressor whose own `mss` is the fallback after this connection's
|
|
1503
|
+
* @returns the segment size in bytes that segment counting uses for this connection
|
|
1408
1504
|
*/
|
|
1409
1505
|
segmentMss(enc: HttpCompressor): i32 {
|
|
1410
1506
|
if (this.mss > 0) {
|
|
@@ -1437,6 +1533,16 @@ export class Http1Connection {
|
|
|
1437
1533
|
* larger than the output could ever hold or one `respond` refuses,
|
|
1438
1534
|
* `H1_CLOSED` with no request to answer; 0 once it is queued. A window
|
|
1439
1535
|
* outside `body` panics.
|
|
1536
|
+
*
|
|
1537
|
+
* @param status the HTTP status code to send, as `respond` takes it
|
|
1538
|
+
* @param names the program's field names, without `Content-Encoding` (or `Vary` under `enc.vary`)
|
|
1539
|
+
* @param values each field's value, at the same index as its name
|
|
1540
|
+
* @param body the program's bytes the body is in, read but not kept
|
|
1541
|
+
* @param off where in `body` the response body starts
|
|
1542
|
+
* @param len how many bytes the response body holds as it is
|
|
1543
|
+
* @param enc the compressor that gzips the body and adds the coding fields; its scratch output is reused per call
|
|
1544
|
+
* @param coding the coding chosen for this request, normally what `acceptEncoding` answered
|
|
1545
|
+
* @returns 0 once the whole response is queued, else `H1_AGAIN`, `H1_INVALID` or `H1_CLOSED` as above
|
|
1440
1546
|
*/
|
|
1441
1547
|
respondEncoded(
|
|
1442
1548
|
status: i32,
|
|
@@ -1524,7 +1630,7 @@ export class Http1Connection {
|
|
|
1524
1630
|
}
|
|
1525
1631
|
|
|
1526
1632
|
/** Takes back a head `respond` just queued: `outputEnd` and `closeAfter` as they were before it. */
|
|
1527
|
-
unrespond(outputEnd: i32, closeAfter: boolean): void {
|
|
1633
|
+
private unrespond(outputEnd: i32, closeAfter: boolean): void {
|
|
1528
1634
|
this.outputEnd = outputEnd
|
|
1529
1635
|
this.closeAfter = closeAfter
|
|
1530
1636
|
this.response = H1_R_NONE
|
|
@@ -1542,6 +1648,9 @@ export class Http1Connection {
|
|
|
1542
1648
|
* request is not a valid opening handshake (the program answers 400, or 426
|
|
1543
1649
|
* for the wrong version) or `protocol` is not a token; `H1_AGAIN` when the
|
|
1544
1650
|
* output has no room yet; `H1_CLOSED` with no request to answer.
|
|
1651
|
+
*
|
|
1652
|
+
* @param protocol the subprotocol to name in `Sec-WebSocket-Protocol`, one the client offered, or "" for none
|
|
1653
|
+
* @returns 0 once the 101 is queued, else `H1_INVALID`, `H1_AGAIN` or `H1_CLOSED` as above
|
|
1545
1654
|
*/
|
|
1546
1655
|
acceptWebSocket(protocol: string): i32 {
|
|
1547
1656
|
if (!this.answerable()) {
|
|
@@ -1574,6 +1683,13 @@ export class Http1Connection {
|
|
|
1574
1683
|
* `websocketWriteFrame` refuses, a close (that is `closeWebSocket`), or one
|
|
1575
1684
|
* larger than the output; `H1_AGAIN` when it does not fit yet; `H1_CLOSED`
|
|
1576
1685
|
* when the slot is not an open WebSocket. A window outside `buf` panics.
|
|
1686
|
+
*
|
|
1687
|
+
* @param fin true when this frame ends its message; false for a fragment that continuations follow
|
|
1688
|
+
* @param opcode the frame's `WS_OP_` opcode: text, binary, continuation, ping or pong, never close
|
|
1689
|
+
* @param buf the payload bytes, copied into the output
|
|
1690
|
+
* @param off where in `buf` the window starts
|
|
1691
|
+
* @param len how many bytes the window holds
|
|
1692
|
+
* @returns 0 once the frame is queued, else `H1_INVALID`, `H1_AGAIN` or `H1_CLOSED` as above
|
|
1577
1693
|
*/
|
|
1578
1694
|
sendFrame(fin: boolean, opcode: i32, buf: u8[], off: i32, len: i32): i32 {
|
|
1579
1695
|
http1ServerCheckWindow("Http1Connection.sendFrame", buf, off, len)
|
|
@@ -1600,6 +1716,9 @@ export class Http1Connection {
|
|
|
1600
1716
|
* then the connection is done once it is sent. Answers 0, `H1_INVALID` for a
|
|
1601
1717
|
* code that may not be sent, or `H1_CLOSED` when the slot is not an open
|
|
1602
1718
|
* WebSocket.
|
|
1719
|
+
*
|
|
1720
|
+
* @param code the close status code to send (RFC 6455 §7.4), such as 1000 for a normal close
|
|
1721
|
+
* @returns 0 once the close frame is queued, else `H1_INVALID` or `H1_CLOSED` as above
|
|
1603
1722
|
*/
|
|
1604
1723
|
closeWebSocket(code: i32): i32 {
|
|
1605
1724
|
if (this.state !== H1_S_WEBSOCKET) {
|
|
@@ -1613,13 +1732,17 @@ export class Http1Connection {
|
|
|
1613
1732
|
return 0
|
|
1614
1733
|
}
|
|
1615
1734
|
|
|
1616
|
-
/**
|
|
1735
|
+
/**
|
|
1736
|
+
* Whether the slot has switched to WebSocket and is open.
|
|
1737
|
+
*
|
|
1738
|
+
* @returns true while `next` reads frames rather than requests and `sendFrame` may be called
|
|
1739
|
+
*/
|
|
1617
1740
|
isWebSocket(): boolean {
|
|
1618
1741
|
return this.state === H1_S_WEBSOCKET
|
|
1619
1742
|
}
|
|
1620
1743
|
|
|
1621
1744
|
/** Whether nothing has moved for longer than the idle timeout, at `now` (`monotonicNanos`). */
|
|
1622
|
-
idle(now: i64): boolean {
|
|
1745
|
+
private idle(now: i64): boolean {
|
|
1623
1746
|
return now - this.lastActive > toI64(this.config.idleTimeout) * toI64(1000000)
|
|
1624
1747
|
}
|
|
1625
1748
|
|
|
@@ -1629,6 +1752,8 @@ export class Http1Connection {
|
|
|
1629
1752
|
* call it after each `feed`; a program that feeds a connection itself calls
|
|
1630
1753
|
* it the same way. Bytes that wait while the previous exchange is still
|
|
1631
1754
|
* open start no clock: they count from when it is over (`nextRequest`).
|
|
1755
|
+
*
|
|
1756
|
+
* @param now the current time in `monotonicNanos`, which the deadline counts from
|
|
1632
1757
|
*/
|
|
1633
1758
|
headArrived(now: i64): void {
|
|
1634
1759
|
if (this.parser.buffered() > 0) {
|
|
@@ -1643,6 +1768,8 @@ export class Http1Connection {
|
|
|
1643
1768
|
* the handshake: a record trickled a byte at a time hands no plaintext to
|
|
1644
1769
|
* `headArrived` until it is whole, so its bytes would otherwise only keep
|
|
1645
1770
|
* the slot from going idle.
|
|
1771
|
+
*
|
|
1772
|
+
* @internal Called by `headArrived` and by `Http1TlsServer` in this module to start the slowloris clock on ciphertext.
|
|
1646
1773
|
*/
|
|
1647
1774
|
headAwaited(now: i64): void {
|
|
1648
1775
|
if (!this.headTimed && this.state === H1_S_HTTP && !this.requestOpen) {
|
|
@@ -1652,11 +1779,15 @@ export class Http1Connection {
|
|
|
1652
1779
|
}
|
|
1653
1780
|
|
|
1654
1781
|
/** Whether a head has been arriving for longer than `headTimeout` at `now` (`monotonicNanos`). */
|
|
1655
|
-
headLate(now: i64): boolean {
|
|
1782
|
+
private headLate(now: i64): boolean {
|
|
1656
1783
|
return this.headTimed && now - this.headSince > toI64(this.config.headTimeout) * toI64(1000000)
|
|
1657
1784
|
}
|
|
1658
1785
|
|
|
1659
|
-
/**
|
|
1786
|
+
/**
|
|
1787
|
+
* Whether `expire` closes the slot at `now`: idle, or a head past its deadline.
|
|
1788
|
+
*
|
|
1789
|
+
* @internal Called by `Http1Server.expire` and `Http1TlsServer.expire` in this module to pick the slots to close.
|
|
1790
|
+
*/
|
|
1660
1791
|
expired(now: i64): boolean {
|
|
1661
1792
|
return this.idle(now) || this.headLate(now)
|
|
1662
1793
|
}
|
|
@@ -1669,6 +1800,10 @@ export class Http1Connection {
|
|
|
1669
1800
|
* `lastActive` when it ends. Counting a quiet keep-alive's clock from
|
|
1670
1801
|
* `lastActive` put it in the past once it was quiet for longer than
|
|
1671
1802
|
* `headTimeout`, so each `expire` walked every slot.
|
|
1803
|
+
*
|
|
1804
|
+
* @param now the current time in `monotonicNanos`
|
|
1805
|
+
* @returns the earliest `monotonicNanos` instant at which `expired` could answer true, so `expire` can skip the slot until then
|
|
1806
|
+
* @internal Called by `Http1Server.expire` and `Http1TlsServer.expire` in this module to skip the slots that cannot expire yet.
|
|
1672
1807
|
*/
|
|
1673
1808
|
expiresNoSooner(now: i64): i64 {
|
|
1674
1809
|
const idle: i64 = this.lastActive + toI64(this.config.idleTimeout) * toI64(1000000)
|
|
@@ -1700,7 +1835,7 @@ const http1ExpireFloor = (config: Http1Config): i64 => {
|
|
|
1700
1835
|
* `accept` until it calls `close`, and its descriptor is `fd(slot)`.
|
|
1701
1836
|
*/
|
|
1702
1837
|
export class Http1Server {
|
|
1703
|
-
config: Http1Config
|
|
1838
|
+
private config: Http1Config
|
|
1704
1839
|
/**
|
|
1705
1840
|
* The connections built so far, slot `k`'s at `k`: one per slot ever
|
|
1706
1841
|
* accepted into, and slot 0's once `connection` has asked for it.
|
|
@@ -1719,7 +1854,7 @@ export class Http1Server {
|
|
|
1719
1854
|
*/
|
|
1720
1855
|
fds: i32[]
|
|
1721
1856
|
/** Each used slot's interest as the loop last armed it, for `rearm`. */
|
|
1722
|
-
armed: i32[]
|
|
1857
|
+
private armed: i32[]
|
|
1723
1858
|
/** The output buffers the slots borrow while they write. */
|
|
1724
1859
|
outputs: Http1OutputPool
|
|
1725
1860
|
/** The input and head buffers resting slots lend, with `Http1Config.idleInput`. */
|
|
@@ -1733,19 +1868,19 @@ export class Http1Server {
|
|
|
1733
1868
|
*/
|
|
1734
1869
|
free: i32[]
|
|
1735
1870
|
/** Where the socket is read into before the connection takes the bytes. */
|
|
1736
|
-
scratch: u8[]
|
|
1871
|
+
private scratch: u8[]
|
|
1737
1872
|
/** The last accepted peer's address, in `nish:net`'s 18-byte form. */
|
|
1738
|
-
peer: u8[]
|
|
1873
|
+
private peer: u8[]
|
|
1739
1874
|
/** How many slots the pool may hold, which `size` answers. */
|
|
1740
|
-
slots: i32 = 1
|
|
1875
|
+
private slots: i32 = 1
|
|
1741
1876
|
/** The listening socket, which the program made with `tcpListen` and still owns. */
|
|
1742
|
-
listener: i32 = -1
|
|
1877
|
+
private listener: i32 = -1
|
|
1743
1878
|
/**
|
|
1744
1879
|
* No slot can expire before this (`monotonicNanos`), so `expire` called
|
|
1745
1880
|
* sooner walks none: it walks every slot only about once per the shorter
|
|
1746
1881
|
* timeout, however many there are.
|
|
1747
1882
|
*/
|
|
1748
|
-
expireAfter: i64 = 0
|
|
1883
|
+
private expireAfter: i64 = 0
|
|
1749
1884
|
/** How many calls of `expire` walked every slot, for a program measuring its cost. */
|
|
1750
1885
|
expireScans: i32 = 0
|
|
1751
1886
|
|
|
@@ -1755,6 +1890,10 @@ export class Http1Server {
|
|
|
1755
1890
|
* allocated by the first `accept` into it and kept, so a pool sized for a
|
|
1756
1891
|
* peak costs at start-up only the read scratch, the shared `Date` and the
|
|
1757
1892
|
* output pool, and at most `size` connections once the peak has come.
|
|
1893
|
+
*
|
|
1894
|
+
* @param config the caps every slot's connection is held to
|
|
1895
|
+
* @param listener the listening socket from `tcpListen`, which stays the program's to close
|
|
1896
|
+
* @param size how many connections the pool serves at once; less than 1 counts as 1
|
|
1758
1897
|
*/
|
|
1759
1898
|
constructor(config: Http1Config, listener: i32, size: i32) {
|
|
1760
1899
|
this.config = config
|
|
@@ -1773,7 +1912,7 @@ export class Http1Server {
|
|
|
1773
1912
|
}
|
|
1774
1913
|
|
|
1775
1914
|
/** A new connection on this pool's outputs and `Date`, for the next slot built. */
|
|
1776
|
-
build(): Http1Connection {
|
|
1915
|
+
private build(): Http1Connection {
|
|
1777
1916
|
const conn: Http1Connection = new Http1Connection(this.config)
|
|
1778
1917
|
conn.pool = this.outputs
|
|
1779
1918
|
conn.date = this.date
|
|
@@ -1785,12 +1924,20 @@ export class Http1Server {
|
|
|
1785
1924
|
return conn
|
|
1786
1925
|
}
|
|
1787
1926
|
|
|
1788
|
-
/**
|
|
1927
|
+
/**
|
|
1928
|
+
* How many slots the pool has, built or not.
|
|
1929
|
+
*
|
|
1930
|
+
* @returns the pool's capacity in connections, as the constructor fixed it
|
|
1931
|
+
*/
|
|
1789
1932
|
size(): i32 {
|
|
1790
1933
|
return this.slots
|
|
1791
1934
|
}
|
|
1792
1935
|
|
|
1793
|
-
/**
|
|
1936
|
+
/**
|
|
1937
|
+
* How many slots hold a connection.
|
|
1938
|
+
*
|
|
1939
|
+
* @returns the count of slots accepted into and not yet closed
|
|
1940
|
+
*/
|
|
1794
1941
|
busy(): i32 {
|
|
1795
1942
|
let n: i32 = 0
|
|
1796
1943
|
for (const fd of this.fds) {
|
|
@@ -1801,12 +1948,22 @@ export class Http1Server {
|
|
|
1801
1948
|
return n
|
|
1802
1949
|
}
|
|
1803
1950
|
|
|
1804
|
-
/**
|
|
1951
|
+
/**
|
|
1952
|
+
* Whether `slot` is a slot of this pool that holds a connection.
|
|
1953
|
+
*
|
|
1954
|
+
* @param slot the slot index to ask about, any value
|
|
1955
|
+
* @returns true when the slot is in range and accepted into, not closed
|
|
1956
|
+
*/
|
|
1805
1957
|
holds(slot: i32): boolean {
|
|
1806
1958
|
return slot >= 0 && slot < toI32(this.fds.length) && this.fds[slot] >= 0
|
|
1807
1959
|
}
|
|
1808
1960
|
|
|
1809
|
-
/**
|
|
1961
|
+
/**
|
|
1962
|
+
* The descriptor of `slot`, for `pollAdd`; -1 for a free or unknown one.
|
|
1963
|
+
*
|
|
1964
|
+
* @param slot the slot `accept` answered
|
|
1965
|
+
* @returns the slot's socket descriptor, which the pool owns and `close` closes; -1 when the slot holds none
|
|
1966
|
+
*/
|
|
1810
1967
|
fd(slot: i32): i32 {
|
|
1811
1968
|
return this.holds(slot) ? this.fds[slot] : -1
|
|
1812
1969
|
}
|
|
@@ -1815,6 +1972,9 @@ export class Http1Server {
|
|
|
1815
1972
|
* The connection of `slot`. A slot never accepted into, or out of range,
|
|
1816
1973
|
* names slot 0's connection, which this builds when no slot has been yet
|
|
1817
1974
|
* (the first `accept` then takes it, restarted).
|
|
1975
|
+
*
|
|
1976
|
+
* @param slot the slot `accept` answered
|
|
1977
|
+
* @returns the slot's connection, which the pool keeps; read its events and write its response through it
|
|
1818
1978
|
*/
|
|
1819
1979
|
connection(slot: i32): Http1Connection {
|
|
1820
1980
|
if (slot >= 0 && slot < toI32(this.connections.length)) {
|
|
@@ -1828,6 +1988,8 @@ export class Http1Server {
|
|
|
1828
1988
|
* slot, which the program adds to its loop with `H1_WANT_READ`; -11 when
|
|
1829
1989
|
* none is waiting, `H1_POOL_FULL` when every slot is busy (the connection
|
|
1830
1990
|
* is closed), or `tcpAccept`'s own failure.
|
|
1991
|
+
*
|
|
1992
|
+
* @returns the new connection's slot, or a negative code as above
|
|
1831
1993
|
*/
|
|
1832
1994
|
accept(): i32 {
|
|
1833
1995
|
const fd: i32 = tcpAccept(this.listener, this.peer)
|
|
@@ -1870,6 +2032,9 @@ export class Http1Server {
|
|
|
1870
2032
|
* and the socket has more, then sends. Answers the interest. It begins a
|
|
1871
2033
|
* serve call, which the program's `flush` of the slot ends: the responses
|
|
1872
2034
|
* written in between carry one clock reading as their `Date`.
|
|
2035
|
+
*
|
|
2036
|
+
* @param slot the slot `accept` answered
|
|
2037
|
+
* @returns the `H1_WANT_` bits the slot now waits for, with `H1_DONE` once it should be closed
|
|
1873
2038
|
*/
|
|
1874
2039
|
readable(slot: i32): i32 {
|
|
1875
2040
|
if (!this.holds(slot)) {
|
|
@@ -1912,7 +2077,12 @@ export class Http1Server {
|
|
|
1912
2077
|
return this.settle(slot)
|
|
1913
2078
|
}
|
|
1914
2079
|
|
|
1915
|
-
/**
|
|
2080
|
+
/**
|
|
2081
|
+
* The socket of `slot` is writable: sends, and begins a serve call as `readable` does. Answers the interest.
|
|
2082
|
+
*
|
|
2083
|
+
* @param slot the slot `accept` answered
|
|
2084
|
+
* @returns the `H1_WANT_` bits the slot now waits for, with `H1_DONE` once it should be closed
|
|
2085
|
+
*/
|
|
1916
2086
|
writable(slot: i32): i32 {
|
|
1917
2087
|
if (!this.holds(slot)) {
|
|
1918
2088
|
return H1_DONE
|
|
@@ -1927,6 +2097,9 @@ export class Http1Server {
|
|
|
1927
2097
|
* for is made here and `H1_WRITE` comes in the same pass; otherwise what
|
|
1928
2098
|
* the program writes in answer to one event and the next goes out together
|
|
1929
2099
|
* at `flush`, as one segment rather than several.
|
|
2100
|
+
*
|
|
2101
|
+
* @param slot the slot `accept` answered
|
|
2102
|
+
* @returns the connection's next `H1_` event, as `Http1Connection.next` answers it
|
|
1930
2103
|
*/
|
|
1931
2104
|
next(slot: i32): i32 {
|
|
1932
2105
|
if (!this.holds(slot)) {
|
|
@@ -1944,6 +2117,9 @@ export class Http1Server {
|
|
|
1944
2117
|
* answers the interest: `H1_DONE` once the connection is over and sent,
|
|
1945
2118
|
* otherwise read while it has room and write while it holds bytes. It ends
|
|
1946
2119
|
* the serve call, so a response written after it reads the clock anew.
|
|
2120
|
+
*
|
|
2121
|
+
* @param slot the slot `accept` answered
|
|
2122
|
+
* @returns the `H1_WANT_` bits to arm the slot with, or `H1_DONE` when the program should `close` it
|
|
1947
2123
|
*/
|
|
1948
2124
|
flush(slot: i32): i32 {
|
|
1949
2125
|
this.date.unhold()
|
|
@@ -1951,7 +2127,7 @@ export class Http1Server {
|
|
|
1951
2127
|
}
|
|
1952
2128
|
|
|
1953
2129
|
/** `flush` within a serve call: sends, answers the interest, and keeps the clock reading. */
|
|
1954
|
-
settle(slot: i32): i32 {
|
|
2130
|
+
private settle(slot: i32): i32 {
|
|
1955
2131
|
if (!this.holds(slot)) {
|
|
1956
2132
|
return H1_DONE
|
|
1957
2133
|
}
|
|
@@ -1972,7 +2148,7 @@ export class Http1Server {
|
|
|
1972
2148
|
}
|
|
1973
2149
|
|
|
1974
2150
|
/** Writes what `slot`'s connection holds, which it holds, until the socket would block. */
|
|
1975
|
-
send(slot: i32): void {
|
|
2151
|
+
private send(slot: i32): void {
|
|
1976
2152
|
const conn: Http1Connection = this.connections[slot]
|
|
1977
2153
|
const fd: i32 = this.fds[slot]
|
|
1978
2154
|
const pending: i32 = conn.outputEnd - conn.outputStart
|
|
@@ -1998,6 +2174,12 @@ export class Http1Server {
|
|
|
1998
2174
|
* armed when it must. A keep-alive connection answers the same interest
|
|
1999
2175
|
* request after request, and each `pollModify` is a system call
|
|
2000
2176
|
* (`epoll_ctl`) that changes nothing.
|
|
2177
|
+
*
|
|
2178
|
+
* @param slot the slot `accept` answered
|
|
2179
|
+
* @param wants the interest bits a serve call answered; only `H1_WANT_READ` and `H1_WANT_WRITE` count
|
|
2180
|
+
* @returns true when the interest changed and the program should call
|
|
2181
|
+
* `pollModify`; false when `slot` is already armed for it, or is free or
|
|
2182
|
+
* out of range
|
|
2001
2183
|
*/
|
|
2002
2184
|
rearm(slot: i32, wants: i32): boolean {
|
|
2003
2185
|
const interest: i32 = wants & (H1_WANT_READ | H1_WANT_WRITE)
|
|
@@ -2008,7 +2190,11 @@ export class Http1Server {
|
|
|
2008
2190
|
return true
|
|
2009
2191
|
}
|
|
2010
2192
|
|
|
2011
|
-
/**
|
|
2193
|
+
/**
|
|
2194
|
+
* Closes `slot`'s socket, whatever is left unsent, and frees the slot.
|
|
2195
|
+
*
|
|
2196
|
+
* @param slot the slot to close; a free or unknown one is ignored
|
|
2197
|
+
*/
|
|
2012
2198
|
close(slot: i32): void {
|
|
2013
2199
|
if (!this.holds(slot)) {
|
|
2014
2200
|
return
|
|
@@ -2024,6 +2210,9 @@ export class Http1Server {
|
|
|
2024
2210
|
/**
|
|
2025
2211
|
* Closes every slot that has been idle past `idleTimeout`, or reading one
|
|
2026
2212
|
* head for longer than `headTimeout`, at `now` (`monotonicNanos`); answers how many.
|
|
2213
|
+
*
|
|
2214
|
+
* @param now the current time in `monotonicNanos`, which every timeout is measured against
|
|
2215
|
+
* @returns how many slots this call closed
|
|
2027
2216
|
*/
|
|
2028
2217
|
expire(now: i64): i32 {
|
|
2029
2218
|
if (now < this.expireAfter) {
|
|
@@ -2058,7 +2247,7 @@ export class Http1Server {
|
|
|
2058
2247
|
* `Http1Server`'s is.
|
|
2059
2248
|
*/
|
|
2060
2249
|
export class Http1TlsServer {
|
|
2061
|
-
config: Http1Config
|
|
2250
|
+
private config: Http1Config
|
|
2062
2251
|
tls: TlsTcpServer
|
|
2063
2252
|
/**
|
|
2064
2253
|
* The connections built so far, slot `k`'s at `k`: one per slot ever
|
|
@@ -2072,18 +2261,18 @@ export class Http1TlsServer {
|
|
|
2072
2261
|
* another slot's live request. Its first read allocates it, once per
|
|
2073
2262
|
* server, and a caller must not change it.
|
|
2074
2263
|
*/
|
|
2075
|
-
vacant: Http1Connection | null = null
|
|
2264
|
+
private vacant: Http1Connection | null = null
|
|
2076
2265
|
/** The `Date` every slot's responses carry, as `Http1Server.date` is. */
|
|
2077
2266
|
date: HttpDate
|
|
2078
2267
|
/** Where TLS decrypts into before the connection takes the bytes. */
|
|
2079
|
-
scratch: u8[]
|
|
2268
|
+
private scratch: u8[]
|
|
2080
2269
|
/** The output buffers the slots borrow while they write. */
|
|
2081
2270
|
outputs: Http1OutputPool
|
|
2082
2271
|
/** The input and head buffers resting slots lend, with `Http1Config.idleInput`. */
|
|
2083
|
-
inputs: Http1OutputPool
|
|
2084
|
-
heads: Http1OutputPool
|
|
2272
|
+
private inputs: Http1OutputPool
|
|
2273
|
+
private heads: Http1OutputPool
|
|
2085
2274
|
/** No slot can expire before this (`monotonicNanos`): `Http1Server.expireAfter`. */
|
|
2086
|
-
expireAfter: i64 = 0
|
|
2275
|
+
private expireAfter: i64 = 0
|
|
2087
2276
|
/** How many calls of `expire` walked every slot. */
|
|
2088
2277
|
expireScans: i32 = 0
|
|
2089
2278
|
|
|
@@ -2093,6 +2282,11 @@ export class Http1TlsServer {
|
|
|
2093
2282
|
* a slot builds its connection and, in `tls`, its handshake state, and
|
|
2094
2283
|
* keeps them, so a pool sized for a peak costs at start-up only the read
|
|
2095
2284
|
* scratches, the shared `Date` and the empty pools.
|
|
2285
|
+
*
|
|
2286
|
+
* @param tlsConfig the certificate chain and TLS settings every handshake uses
|
|
2287
|
+
* @param config the caps every slot's connection is held to
|
|
2288
|
+
* @param listener the listening socket from `tcpListen`, which stays the program's to close
|
|
2289
|
+
* @param size how many connections the pool serves at once
|
|
2096
2290
|
*/
|
|
2097
2291
|
constructor(tlsConfig: TlsServerConfig, config: Http1Config, listener: i32, size: i32) {
|
|
2098
2292
|
this.config = config
|
|
@@ -2110,14 +2304,14 @@ export class Http1TlsServer {
|
|
|
2110
2304
|
* built. Called by `accept` alone, as `tls` builds slots: slot `k`'s
|
|
2111
2305
|
* connection must sit at index `k` of `connections`.
|
|
2112
2306
|
*/
|
|
2113
|
-
build(): Http1Connection {
|
|
2307
|
+
private build(): Http1Connection {
|
|
2114
2308
|
const conn: Http1Connection = this.make()
|
|
2115
2309
|
this.connections.push(conn)
|
|
2116
2310
|
return conn
|
|
2117
2311
|
}
|
|
2118
2312
|
|
|
2119
2313
|
/** A connection on this pool's outputs and `Date` that no slot holds yet. */
|
|
2120
|
-
make(): Http1Connection {
|
|
2314
|
+
private make(): Http1Connection {
|
|
2121
2315
|
const conn: Http1Connection = new Http1Connection(this.config)
|
|
2122
2316
|
conn.pool = this.outputs
|
|
2123
2317
|
conn.date = this.date
|
|
@@ -2128,22 +2322,40 @@ export class Http1TlsServer {
|
|
|
2128
2322
|
return conn
|
|
2129
2323
|
}
|
|
2130
2324
|
|
|
2131
|
-
/**
|
|
2325
|
+
/**
|
|
2326
|
+
* How many slots the pool has, built or not.
|
|
2327
|
+
*
|
|
2328
|
+
* @returns the pool's capacity in connections, as `tls` holds it
|
|
2329
|
+
*/
|
|
2132
2330
|
size(): i32 {
|
|
2133
2331
|
return this.tls.size()
|
|
2134
2332
|
}
|
|
2135
2333
|
|
|
2136
|
-
/**
|
|
2334
|
+
/**
|
|
2335
|
+
* How many slots hold a connection.
|
|
2336
|
+
*
|
|
2337
|
+
* @returns the count of slots accepted into and not yet closed, handshakes included
|
|
2338
|
+
*/
|
|
2137
2339
|
busy(): i32 {
|
|
2138
2340
|
return this.tls.busy()
|
|
2139
2341
|
}
|
|
2140
2342
|
|
|
2141
|
-
/**
|
|
2343
|
+
/**
|
|
2344
|
+
* Whether `slot` holds a connection.
|
|
2345
|
+
*
|
|
2346
|
+
* @param slot the slot index to ask about, any value
|
|
2347
|
+
* @returns true when the slot is in range and accepted into, not closed
|
|
2348
|
+
*/
|
|
2142
2349
|
holds(slot: i32): boolean {
|
|
2143
2350
|
return this.tls.holds(slot)
|
|
2144
2351
|
}
|
|
2145
2352
|
|
|
2146
|
-
/**
|
|
2353
|
+
/**
|
|
2354
|
+
* The descriptor of `slot`, for `pollAdd`; -1 for a free one.
|
|
2355
|
+
*
|
|
2356
|
+
* @param slot the slot `accept` answered
|
|
2357
|
+
* @returns the slot's socket descriptor, which the pool owns and `close` closes; -1 when the slot holds none
|
|
2358
|
+
*/
|
|
2147
2359
|
fd(slot: i32): i32 {
|
|
2148
2360
|
return this.tls.fd(slot)
|
|
2149
2361
|
}
|
|
@@ -2153,7 +2365,7 @@ export class Http1TlsServer {
|
|
|
2153
2365
|
* as `Http2TlsServer.live` asks: a slot accepted on `tls` directly holds a
|
|
2154
2366
|
* TLS session and no `Http1Connection`, and reads as free here.
|
|
2155
2367
|
*/
|
|
2156
|
-
live(slot: i32): boolean {
|
|
2368
|
+
private live(slot: i32): boolean {
|
|
2157
2369
|
return this.tls.holds(slot) && slot < toI32(this.connections.length)
|
|
2158
2370
|
}
|
|
2159
2371
|
|
|
@@ -2161,6 +2373,9 @@ export class Http1TlsServer {
|
|
|
2161
2373
|
* The HTTP/1.1 connection of `slot`. A slot never accepted into answers
|
|
2162
2374
|
* `vacant`, as a free slot answers a connection that holds nothing, and
|
|
2163
2375
|
* builds no slot; a slot out of range names slot 0's.
|
|
2376
|
+
*
|
|
2377
|
+
* @param slot the slot `accept` answered
|
|
2378
|
+
* @returns the slot's connection, which the pool keeps; the shared `vacant` one, not to be changed, for a slot never built
|
|
2164
2379
|
*/
|
|
2165
2380
|
connection(slot: i32): Http1Connection {
|
|
2166
2381
|
const index: i32 = slot >= 0 && slot < this.tls.size() ? slot : 0
|
|
@@ -2176,12 +2391,22 @@ export class Http1TlsServer {
|
|
|
2176
2391
|
return made
|
|
2177
2392
|
}
|
|
2178
2393
|
|
|
2179
|
-
/**
|
|
2394
|
+
/**
|
|
2395
|
+
* The ALPN protocol `slot`'s handshake chose, or empty.
|
|
2396
|
+
*
|
|
2397
|
+
* @param slot the slot `accept` answered
|
|
2398
|
+
* @returns the protocol identifier the handshake agreed on, such as "http/1.1", or "" when none was chosen yet or at all
|
|
2399
|
+
*/
|
|
2180
2400
|
alpn(slot: i32): string {
|
|
2181
2401
|
return this.tls.connection(slot).tls.alpn
|
|
2182
2402
|
}
|
|
2183
2403
|
|
|
2184
|
-
/**
|
|
2404
|
+
/**
|
|
2405
|
+
* Whether `slot`'s handshake is done and chose a protocol other than `http/1.1`.
|
|
2406
|
+
*
|
|
2407
|
+
* @param slot the slot `accept` answered
|
|
2408
|
+
* @returns true when the slot will be shut down rather than served, because its client wants another protocol
|
|
2409
|
+
*/
|
|
2185
2410
|
refused(slot: i32): boolean {
|
|
2186
2411
|
const chosen: string = this.alpn(slot)
|
|
2187
2412
|
return this.tls.connection(slot).state === TLS_RECORD_STATE_OPEN && chosen !== "" && chosen !== H1_ALPN
|
|
@@ -2192,6 +2417,10 @@ export class Http1TlsServer {
|
|
|
2192
2417
|
* the caller's 32-byte server random and x25519 key, and gives it a fresh
|
|
2193
2418
|
* connection, building the slot's on its first accept. Answers the slot, or
|
|
2194
2419
|
* what `TlsTcpServer.accept` answers.
|
|
2420
|
+
*
|
|
2421
|
+
* @param serverRandom 32 fresh random bytes for the ServerHello
|
|
2422
|
+
* @param ephemeralPrivate a fresh x25519 private key for this handshake alone
|
|
2423
|
+
* @returns the new connection's slot, or the negative code `TlsTcpServer.accept` answers
|
|
2195
2424
|
*/
|
|
2196
2425
|
accept(serverRandom: u8[], ephemeralPrivate: u8[]): i32 {
|
|
2197
2426
|
const slot: i32 = this.tls.accept(serverRandom, ephemeralPrivate)
|
|
@@ -2208,7 +2437,12 @@ export class Http1TlsServer {
|
|
|
2208
2437
|
return slot
|
|
2209
2438
|
}
|
|
2210
2439
|
|
|
2211
|
-
/**
|
|
2440
|
+
/**
|
|
2441
|
+
* The socket of `slot` is readable: TLS reads it, and what the connection has to send goes after. Answers the interest.
|
|
2442
|
+
*
|
|
2443
|
+
* @param slot the slot `accept` answered
|
|
2444
|
+
* @returns the TLS interest bits the slot now waits for (`H1_WANT_` values), with `TLS_RECORD_DONE` once it should be closed
|
|
2445
|
+
*/
|
|
2212
2446
|
readable(slot: i32): i32 {
|
|
2213
2447
|
const live: boolean = this.live(slot)
|
|
2214
2448
|
const now: i64 = monotonicNanos()
|
|
@@ -2228,13 +2462,24 @@ export class Http1TlsServer {
|
|
|
2228
2462
|
return this.flush(slot)
|
|
2229
2463
|
}
|
|
2230
2464
|
|
|
2231
|
-
/**
|
|
2465
|
+
/**
|
|
2466
|
+
* The socket of `slot` is writable. Answers the interest.
|
|
2467
|
+
*
|
|
2468
|
+
* @param slot the slot `accept` answered
|
|
2469
|
+
* @returns the TLS interest bits the slot now waits for (`H1_WANT_` values), with `TLS_RECORD_DONE` once it should be closed
|
|
2470
|
+
*/
|
|
2232
2471
|
writable(slot: i32): i32 {
|
|
2233
2472
|
this.tls.writable(slot)
|
|
2234
2473
|
return this.flush(slot)
|
|
2235
2474
|
}
|
|
2236
2475
|
|
|
2237
|
-
/**
|
|
2476
|
+
/**
|
|
2477
|
+
* Signs `slot`'s CertificateVerify with `key`, as `TlsTcpServer.signP256` does. Answers the interest.
|
|
2478
|
+
*
|
|
2479
|
+
* @param slot the slot whose handshake waits for its signature
|
|
2480
|
+
* @param key the certificate's P-256 private key, which stays the caller's to wipe
|
|
2481
|
+
* @returns the TLS interest bits the slot now waits for (`H1_WANT_` values), with `TLS_RECORD_DONE` once it should be closed
|
|
2482
|
+
*/
|
|
2238
2483
|
signP256(slot: i32, key: Secret<u8[]>): i32 {
|
|
2239
2484
|
this.tls.signP256(slot, key)
|
|
2240
2485
|
return this.flush(slot)
|
|
@@ -2244,6 +2489,9 @@ export class Http1TlsServer {
|
|
|
2244
2489
|
* Moves what TLS has decrypted for `slot` into its connection, as far as
|
|
2245
2490
|
* the connection has room, and answers the connection's next event. A free
|
|
2246
2491
|
* slot, or one whose ALPN was another protocol, answers `H1_ERROR`.
|
|
2492
|
+
*
|
|
2493
|
+
* @param slot the slot `accept` answered
|
|
2494
|
+
* @returns the connection's next `H1_` event, as `Http1Connection.next` answers it
|
|
2247
2495
|
*/
|
|
2248
2496
|
next(slot: i32): i32 {
|
|
2249
2497
|
if (!this.live(slot) || this.refused(slot)) {
|
|
@@ -2277,6 +2525,9 @@ export class Http1TlsServer {
|
|
|
2277
2525
|
* and sends it; shuts TLS down once the connection is over or ALPN chose
|
|
2278
2526
|
* another protocol. Answers TLS's interest, with the write bit while the
|
|
2279
2527
|
* connection still holds bytes.
|
|
2528
|
+
*
|
|
2529
|
+
* @param slot the slot `accept` answered
|
|
2530
|
+
* @returns the TLS interest bits the slot now waits for (`H1_WANT_` values), with `TLS_RECORD_DONE` once it should be closed
|
|
2280
2531
|
*/
|
|
2281
2532
|
flush(slot: i32): i32 {
|
|
2282
2533
|
if (!this.live(slot)) {
|
|
@@ -2299,7 +2550,7 @@ export class Http1TlsServer {
|
|
|
2299
2550
|
* Writes what `slot`'s connection holds into TLS, as far as TLS takes it;
|
|
2300
2551
|
* a slot never built has nothing to write.
|
|
2301
2552
|
*/
|
|
2302
|
-
send(slot: i32): void {
|
|
2553
|
+
private send(slot: i32): void {
|
|
2303
2554
|
if (slot < 0 || slot >= toI32(this.connections.length)) {
|
|
2304
2555
|
return
|
|
2305
2556
|
}
|
|
@@ -2318,7 +2569,11 @@ export class Http1TlsServer {
|
|
|
2318
2569
|
conn.release()
|
|
2319
2570
|
}
|
|
2320
2571
|
|
|
2321
|
-
/**
|
|
2572
|
+
/**
|
|
2573
|
+
* Ends `slot`'s connection and frees the slot at once, as `TlsTcpServer.close` does.
|
|
2574
|
+
*
|
|
2575
|
+
* @param slot the slot to close
|
|
2576
|
+
*/
|
|
2322
2577
|
close(slot: i32): void {
|
|
2323
2578
|
this.tls.close(slot)
|
|
2324
2579
|
if (slot >= 0 && slot < toI32(this.connections.length)) {
|
|
@@ -2329,6 +2584,9 @@ export class Http1TlsServer {
|
|
|
2329
2584
|
/**
|
|
2330
2585
|
* Closes every slot that has been idle past `idleTimeout`, or reading one
|
|
2331
2586
|
* head for longer than `headTimeout`, at `now` (`monotonicNanos`); answers how many.
|
|
2587
|
+
*
|
|
2588
|
+
* @param now the current time in `monotonicNanos`, which every timeout is measured against
|
|
2589
|
+
* @returns how many slots this call closed
|
|
2332
2590
|
*/
|
|
2333
2591
|
expire(now: i64): i32 {
|
|
2334
2592
|
if (now < this.expireAfter) {
|