@amritk/nish-x86_64-linux 0.49.1 → 0.50.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/INSTALL.md +1 -1
- package/bin/nish +0 -0
- package/docs/AI.md +233 -159
- package/package.json +1 -1
- package/runtime/gfx/nish-gfx.h +373 -61
- package/runtime/nish.d.ts +12 -9
- package/std/README.md +8 -5
- package/std/base64.ts +74 -1
- package/std/bytes.ts +201 -93
- package/std/compress/deflate.ts +20 -15
- package/std/crypto/base64url.ts +93 -66
- package/std/crypto/bcrypt.ts +25 -21
- package/std/crypto/hmac.ts +1 -1
- package/std/crypto/jwt.ts +32 -19
- package/std/crypto/p256.ts +9 -12
- package/std/crypto/pki-roots.ts +7 -4
- package/std/crypto/pki.ts +43 -55
- package/std/crypto/rsa-sign.ts +1632 -0
- package/std/crypto/rsa.ts +26 -4
- package/std/crypto/sha256.ts +135 -68
- package/std/crypto/x25519.ts +12 -11
- package/std/crypto/x509.ts +164 -40
- package/std/gpu/sys.ts +490 -0
- package/std/json-equal.ts +33 -18
- package/std/json-format.ts +39 -8
- package/std/json-number.ts +15 -3
- package/std/json-tokenizer.ts +4 -3
- package/std/json-typed.ts +12 -6
- package/std/json-value.ts +222 -104
- package/std/json.ts +81 -46
- package/std/net/dns-config.ts +18 -5
- package/std/net/dns-message.ts +60 -27
- package/std/net/dns-resolver.ts +35 -16
- package/std/net/dns.ts +3 -2
- package/std/net/fetch.ts +120 -38
- package/std/net/handler.ts +178 -66
- package/std/net/hpack.ts +192 -98
- package/std/net/http-compress.ts +83 -30
- package/std/net/http-fields.ts +327 -31
- package/std/net/http-server.ts +317 -20
- package/std/net/http1-client-codec.ts +137 -40
- package/std/net/http1-codec.ts +391 -202
- package/std/net/http1-server.ts +220 -38
- package/std/net/http2-cleartext.ts +10 -4
- package/std/net/http2-frame.ts +2 -2
- package/std/net/http2-tls.ts +3 -3
- package/std/net/http2.ts +69 -15
- package/std/net/http3-frame.ts +11 -14
- package/std/net/http3-server.ts +12 -15
- package/std/net/http3.ts +41 -29
- package/std/net/multipart.ts +592 -0
- package/std/net/outbound.ts +24 -8
- package/std/net/postgres-async.ts +92 -54
- package/std/net/postgres-carrier.ts +28 -4
- package/std/net/postgres.ts +166 -65
- package/std/net/prefork.ts +86 -5
- package/std/net/protobuf.ts +6 -2
- package/std/net/qpack.ts +66 -25
- package/std/net/quic-conn-ack.ts +27 -7
- package/std/net/quic-conn-cid.ts +13 -7
- package/std/net/quic-datagram.ts +6 -5
- package/std/net/quic-frame.ts +67 -23
- package/std/net/quic-listener.ts +19 -12
- package/std/net/quic-recovery.ts +11 -9
- package/std/net/quic-stream.ts +7 -5
- package/std/net/quic.ts +36 -31
- package/std/net/router.ts +136 -24
- package/std/net/serve.ts +59 -5
- package/std/net/static.ts +81 -33
- package/std/net/tls/record.ts +26 -13
- package/std/net/tls/ticket.ts +6 -5
- package/std/net/tls-tcp.ts +69 -30
- package/std/net/tls.ts +152 -38
- package/std/net/upstream.ts +65 -19
- package/std/net/url.ts +97 -78
- package/std/net/websocket.ts +16 -9
- package/std/net/webtransport.ts +28 -12
- package/std/regex.ts +600 -388
- package/std/sqlite.ts +37 -19
- package/std/sync/ring.ts +232 -115
- package/std/sync/shm.ts +11 -4
- package/std/temporal.ts +232 -133
- package/std/term-io.ts +12 -6
- package/std/term-pixels.ts +158 -22
- package/std/term-rate.ts +8 -3
- package/std/term.ts +4 -4
- package/std/text.ts +33 -11
- package/std/yaml-json.ts +238 -106
- package/std/yaml-lines.ts +47 -27
- package/std/yaml-write.ts +58 -24
- package/std/yaml.ts +808 -395
|
@@ -172,7 +172,7 @@ import {
|
|
|
172
172
|
} from "nish:net"
|
|
173
173
|
import { monotonicNanos } from "nish:process"
|
|
174
174
|
import { Secret } from "nish:secret"
|
|
175
|
-
import {
|
|
175
|
+
import { tryCopyBytes } from "nish/bytes"
|
|
176
176
|
import {
|
|
177
177
|
PG_ERR_CLOSED,
|
|
178
178
|
PG_ERR_ENCODING,
|
|
@@ -263,25 +263,31 @@ const PG_ASYNC_SEQ_MASK: i32 = PG_ASYNC_SEQ_WRAP - 1
|
|
|
263
263
|
const PG_ASYNC_QUEUE_MASK: i32 = PG_ASYNC_QUEUE_WRAP - 1
|
|
264
264
|
|
|
265
265
|
/**
|
|
266
|
-
* `n` plus one, wrapped below `mask` plus one, a power of two:
|
|
267
|
-
*
|
|
268
|
-
*
|
|
266
|
+
* `n` plus one, wrapped below `mask` plus one, a power of two: `(n + 1) %
|
|
267
|
+
* wrap` for `n` below that wrap. A count at or past the mask, or below 0,
|
|
268
|
+
* which no step makes, starts again at 0.
|
|
269
269
|
*/
|
|
270
|
-
const pgAsyncStep = (n: i32, mask: i32): i32 =>
|
|
270
|
+
const pgAsyncStep = (n: i32, mask: i32): i32 => (n >= 0 && n < mask ? n + 1 : 0)
|
|
271
271
|
|
|
272
272
|
/**
|
|
273
273
|
* How far `from` is behind `to`, two counts that wrap below `mask` plus one,
|
|
274
|
-
* a power of two: `(to - from + wrap) % wrap` for counts below the wrap
|
|
275
|
-
*
|
|
274
|
+
* a power of two: `(to - from + wrap) % wrap` for counts below the wrap. Both
|
|
275
|
+
* are at least 0, so their difference is exact before the mask takes it; a
|
|
276
|
+
* negative count, which no step makes, is no distance.
|
|
276
277
|
*/
|
|
277
|
-
const pgAsyncGap = (to: i32, from: i32, mask: i32): i32 =>
|
|
278
|
+
const pgAsyncGap = (to: i32, from: i32, mask: i32): i32 => {
|
|
279
|
+
if (to < 0 || from < 0) {
|
|
280
|
+
return 0
|
|
281
|
+
}
|
|
282
|
+
return (to - from) & mask
|
|
283
|
+
}
|
|
278
284
|
|
|
279
285
|
/**
|
|
280
|
-
* Where wake `w`'s socket pair starts in `wakes`, `2w`:
|
|
281
|
-
*
|
|
282
|
-
*
|
|
286
|
+
* Where wake `w`'s socket pair starts in `wakes`, `2w`: -1 for a wake below 0
|
|
287
|
+
* or at 2^30 or past it, which every caller checks against `wakes` before it
|
|
288
|
+
* reads.
|
|
283
289
|
*/
|
|
284
|
-
const pgAsyncPair = (w: i32): i32 =>
|
|
290
|
+
const pgAsyncPair = (w: i32): i32 => (w >= 0 && w < 1073741824 ? w * 2 : -1)
|
|
285
291
|
|
|
286
292
|
/** `n` plus one, held at the `i32` ceiling: a statistic that counts on, never back. */
|
|
287
293
|
const pgAsyncCount = (n: i32): i32 => (n < 2147483647 ? n + 1 : n)
|
|
@@ -888,8 +894,8 @@ const pgAsyncStartup = async (conn: PgConnection, fd: i32, began: i64, waitMs: i
|
|
|
888
894
|
if (start < 0 || end <= start) {
|
|
889
895
|
break
|
|
890
896
|
}
|
|
891
|
-
// Both are at least 0 and `end` is past `start`, so the
|
|
892
|
-
const n: i32 = netWrite(fd, conn.outputBuffer(), start,
|
|
897
|
+
// Both are at least 0 and `end` is past `start`, so the difference is exact.
|
|
898
|
+
const n: i32 = netWrite(fd, conn.outputBuffer(), start, end - start)
|
|
893
899
|
if (n === PG_ASYNC_AGAIN) {
|
|
894
900
|
const waited: boolean = await pgAsyncWaitUntil(fd, true, began, waitMs)
|
|
895
901
|
if (!waited) {
|
|
@@ -957,9 +963,10 @@ const pgAsyncWaitUntil = async (fd: i32, write: boolean, began: i64, waitMs: i32
|
|
|
957
963
|
|
|
958
964
|
/** Milliseconds since `began`, a `monotonicNanos` reading. */
|
|
959
965
|
const pgAsyncSince = (began: i64): i32 => {
|
|
960
|
-
// `
|
|
961
|
-
//
|
|
962
|
-
const
|
|
966
|
+
// A clock read after `began` is never behind it; a reading that is, or a
|
|
967
|
+
// negative one, counts as no time.
|
|
968
|
+
const now: i64 = monotonicNanos()
|
|
969
|
+
const ms: i64 = began >= 0 && now >= 0 && now >= began ? (now - began) / toI64(1000000) : toI64(0)
|
|
963
970
|
return ms > toI64(1073741823) ? 1073741823 : toI32(ms)
|
|
964
971
|
}
|
|
965
972
|
|
|
@@ -1060,8 +1067,9 @@ const pgAsyncWakePool = (pool: PgAsyncPool): void => {
|
|
|
1060
1067
|
wake = wake > PG_ASYNC_LANES ? PG_ASYNC_LANES : wake
|
|
1061
1068
|
for (let k: i32 = 0; k < wake; k++) {
|
|
1062
1069
|
// The queue lane of the `k`th task waiting, after the pool's own wake.
|
|
1063
|
-
const lane:
|
|
1064
|
-
|
|
1070
|
+
const lane: i32 =
|
|
1071
|
+
((pool.seatHead & (PG_ASYNC_LANES - 1)) + (k & (PG_ASYNC_LANES - 1))) & (PG_ASYNC_LANES - 1)
|
|
1072
|
+
pgAsyncSignal(pool, PG_ASYNC_POOL_WAKE + 1 + lane)
|
|
1065
1073
|
}
|
|
1066
1074
|
}
|
|
1067
1075
|
|
|
@@ -1181,16 +1189,16 @@ export const pgAsyncClaim = async (pool: PgAsyncPool): Promise<i32> => {
|
|
|
1181
1189
|
}
|
|
1182
1190
|
live = true
|
|
1183
1191
|
if (toI32(pool.claimed[s]) === 0 && pool.seated[s] === 0 && pool.doomAt[s] < 0) {
|
|
1184
|
-
// The claim count wraps below 2^24, so
|
|
1185
|
-
//
|
|
1186
|
-
const claim:
|
|
1192
|
+
// The claim count wraps below 2^24, so the ticket, the count times 64
|
|
1193
|
+
// slots plus the slot, is below 2^30.
|
|
1194
|
+
const claim: i32 = pgAsyncStep(pool.claims[s], PG_ASYNC_CLAIM_MASK) & PG_ASYNC_CLAIM_MASK
|
|
1187
1195
|
pool.claimed[s] = 1
|
|
1188
|
-
pool.claims[s] =
|
|
1196
|
+
pool.claims[s] = claim
|
|
1189
1197
|
if (waited) {
|
|
1190
1198
|
// Another waiter may find room this one did not take.
|
|
1191
1199
|
pgAsyncWakePool(pool)
|
|
1192
1200
|
}
|
|
1193
|
-
return
|
|
1201
|
+
return claim * PG_ASYNC_MAX_SIZE + (s & (PG_ASYNC_MAX_SIZE - 1))
|
|
1194
1202
|
}
|
|
1195
1203
|
}
|
|
1196
1204
|
if (!live) {
|
|
@@ -1374,9 +1382,11 @@ export const pgAsyncSeat = async (pool: PgAsyncPool, statement: i32): Promise<i3
|
|
|
1374
1382
|
? pgAsyncGap(queued, pool.seatHead, PG_ASYNC_QUEUE_MASK) < free
|
|
1375
1383
|
: pool.seatHead === pool.seatTail
|
|
1376
1384
|
if (best >= 0 && turn) {
|
|
1377
|
-
// `best` is below 64 and `statement` below 64, so
|
|
1378
|
-
//
|
|
1379
|
-
const known: i32 =
|
|
1385
|
+
// `best` is below 64 and `statement` below 64, so the offset is exact;
|
|
1386
|
+
// it is then checked against its array.
|
|
1387
|
+
const known: i32 =
|
|
1388
|
+
(best & (PG_ASYNC_MAX_SIZE - 1)) * PG_ASYNC_MAX_STATEMENTS +
|
|
1389
|
+
(statement & (PG_ASYNC_MAX_STATEMENTS - 1))
|
|
1380
1390
|
for (let k: i32 = 0; k < PG_ASYNC_MAX_DEPTH; k++) {
|
|
1381
1391
|
const seat: i32 = pgAsyncSeatAt(best, k)
|
|
1382
1392
|
if (
|
|
@@ -1400,8 +1410,8 @@ export const pgAsyncSeat = async (pool: PgAsyncPool, statement: i32): Promise<i3
|
|
|
1400
1410
|
continue
|
|
1401
1411
|
}
|
|
1402
1412
|
// The seat claim count wraps below 2^20, so the ticket, the count
|
|
1403
|
-
// times 1024 seats plus the seat, is
|
|
1404
|
-
const claim:
|
|
1413
|
+
// times 1024 seats plus the seat, is below 2^30.
|
|
1414
|
+
const claim: i32 = pgAsyncStep(pool.seatClaims[seat], PG_ASYNC_SEAT_MASK) & PG_ASYNC_SEAT_MASK
|
|
1405
1415
|
pool.seatUsed[seat] = 1
|
|
1406
1416
|
pool.seatWaiting[seat] = 0
|
|
1407
1417
|
pool.seatSeq[seat] = pool.nextSeq[best]
|
|
@@ -1411,10 +1421,10 @@ export const pgAsyncSeat = async (pool: PgAsyncPool, statement: i32): Promise<i3
|
|
|
1411
1421
|
pool.nextSeq[best] = pgAsyncStep(pool.nextSeq[best], PG_ASYNC_SEQ_MASK)
|
|
1412
1422
|
pool.seated[best] = pgAsyncCount(pool.seated[best])
|
|
1413
1423
|
pool.writing[best] = 1
|
|
1414
|
-
pool.seatClaims[seat] =
|
|
1424
|
+
pool.seatClaims[seat] = claim
|
|
1415
1425
|
// The next in the queue may find a seat this one did not take.
|
|
1416
1426
|
pgAsyncUnqueue(pool, queued)
|
|
1417
|
-
return
|
|
1427
|
+
return claim * PG_ASYNC_SEATS + (seat & (PG_ASYNC_SEATS - 1))
|
|
1418
1428
|
}
|
|
1419
1429
|
}
|
|
1420
1430
|
if (!live) {
|
|
@@ -1437,10 +1447,7 @@ export const pgAsyncSeat = async (pool: PgAsyncPool, statement: i32): Promise<i3
|
|
|
1437
1447
|
continue
|
|
1438
1448
|
}
|
|
1439
1449
|
// A queued task waits on its queue lane, after the pool's own wake.
|
|
1440
|
-
const w: i32 =
|
|
1441
|
-
queued >= 0
|
|
1442
|
-
? toI32(toU32(PG_ASYNC_POOL_WAKE + 1) + (toU32(queued) & toU32(PG_ASYNC_LANES - 1)))
|
|
1443
|
-
: PG_ASYNC_POOL_WAKE
|
|
1450
|
+
const w: i32 = queued >= 0 ? PG_ASYNC_POOL_WAKE + 1 + (queued & (PG_ASYNC_LANES - 1)) : PG_ASYNC_POOL_WAKE
|
|
1444
1451
|
pool.waits = pgAsyncCount(pool.waits)
|
|
1445
1452
|
await pgAsyncPark(pool, w, left)
|
|
1446
1453
|
pgAsyncDrain(pool, w)
|
|
@@ -1509,8 +1516,13 @@ export const pgAsyncSend = async (pool: PgAsyncPool, ticket: i32, params: PgAsyn
|
|
|
1509
1516
|
}
|
|
1510
1517
|
let sent: i32 = 0
|
|
1511
1518
|
while (sent >= 0 && sent < toI32(out.length)) {
|
|
1512
|
-
// Both are at least 0 and `sent` is short of the end, so the
|
|
1513
|
-
const
|
|
1519
|
+
// Both are at least 0 and `sent` is short of the end, so the difference is exact.
|
|
1520
|
+
const total: i32 = toI32(out.length)
|
|
1521
|
+
let rest: i32 = 0
|
|
1522
|
+
if (sent >= 0 && total >= 0) {
|
|
1523
|
+
rest = total - sent
|
|
1524
|
+
}
|
|
1525
|
+
const n: i32 = netWrite(fd, out, sent, rest)
|
|
1514
1526
|
if (n === PG_ASYNC_AGAIN) {
|
|
1515
1527
|
const waited: boolean = await writable(fd)
|
|
1516
1528
|
const failed: i32 = pgAsyncWaitFailure(waited)
|
|
@@ -1549,10 +1561,15 @@ const pgAsyncAhead = (served: i32, seq: i32): i32 => pgAsyncGap(seq, served, PG_
|
|
|
1549
1561
|
|
|
1550
1562
|
/**
|
|
1551
1563
|
* Where slot `s`'s `k`th seat is in the seat arrays, `s * PG_ASYNC_MAX_DEPTH
|
|
1552
|
-
* + k`:
|
|
1553
|
-
*
|
|
1564
|
+
* + k`: -1 for a slot or depth out of range, and every caller checks the
|
|
1565
|
+
* seat against the arrays it reads.
|
|
1554
1566
|
*/
|
|
1555
|
-
const pgAsyncSeatAt = (s: i32, k: i32): i32 =>
|
|
1567
|
+
const pgAsyncSeatAt = (s: i32, k: i32): i32 => {
|
|
1568
|
+
if (s < 0 || s >= PG_ASYNC_MAX_SIZE || k < 0 || k >= PG_ASYNC_MAX_DEPTH) {
|
|
1569
|
+
return -1
|
|
1570
|
+
}
|
|
1571
|
+
return (s & (PG_ASYNC_MAX_SIZE - 1)) * PG_ASYNC_MAX_DEPTH + (k & (PG_ASYNC_MAX_DEPTH - 1))
|
|
1572
|
+
}
|
|
1556
1573
|
|
|
1557
1574
|
/**
|
|
1558
1575
|
* Whether seat `seat`'s answer is lost: its connection failed at or before
|
|
@@ -1801,8 +1818,8 @@ const pgAsyncRoom = (pool: PgAsyncPool, s: i32, input: u8[]): i32 => {
|
|
|
1801
1818
|
}
|
|
1802
1819
|
let room: i32 = end
|
|
1803
1820
|
if (start > 0) {
|
|
1804
|
-
//
|
|
1805
|
-
room =
|
|
1821
|
+
// `end` is at or past `start`, so the difference is the bytes kept.
|
|
1822
|
+
room = end - start
|
|
1806
1823
|
if (!tryCopyBytes(input, 0, input, start, room)) {
|
|
1807
1824
|
return -1
|
|
1808
1825
|
}
|
|
@@ -1995,8 +2012,8 @@ const pgAsyncPlain = (pool: PgAsyncPool, s: i32): boolean => {
|
|
|
1995
2012
|
if (size < 4 || size >= left) {
|
|
1996
2013
|
return false
|
|
1997
2014
|
}
|
|
1998
|
-
// In
|
|
1999
|
-
const next: i32 = toI32(
|
|
2015
|
+
// In i64: the frame ends before `stop`, so the sum fits an i32.
|
|
2016
|
+
const next: i32 = toI32(toI64(at) + toI64(1) + toI64(size))
|
|
2000
2017
|
if (type === 90) {
|
|
2001
2018
|
return next === stop && size === 5 && toI32(input[at + 5]) === PG_ASYNC_IDLE
|
|
2002
2019
|
}
|
|
@@ -2119,8 +2136,8 @@ const pgAsyncScan = (pool: PgAsyncPool, s: i32): boolean => {
|
|
|
2119
2136
|
return false
|
|
2120
2137
|
}
|
|
2121
2138
|
const type: i32 = toI32(input[at])
|
|
2122
|
-
// In
|
|
2123
|
-
at = toI32(
|
|
2139
|
+
// In i64: the frame ends at or before `end`, so the sum fits an i32.
|
|
2140
|
+
at = toI32(toI64(at) + toI64(1) + toI64(size))
|
|
2124
2141
|
if (type === 49) {
|
|
2125
2142
|
pool.inParsed[s] = 1
|
|
2126
2143
|
}
|
|
@@ -2308,8 +2325,11 @@ export const pgAsyncAnswer = async (pool: PgAsyncPool, ticket: i32, turn: i32):
|
|
|
2308
2325
|
const fd: i32 = pool.fds[s]
|
|
2309
2326
|
const from: i32 = pool.inStart[s]
|
|
2310
2327
|
const to: i32 = pool.inAnswer[s] >= 0 ? pool.inAnswer[s] : pool.inEnd[s]
|
|
2311
|
-
//
|
|
2312
|
-
|
|
2328
|
+
// `to` is at or past `from` here, so the difference is the bytes.
|
|
2329
|
+
let count: i32 = 0
|
|
2330
|
+
if (from >= 0 && from <= to && to <= toI32(input.length)) {
|
|
2331
|
+
count = to - from
|
|
2332
|
+
}
|
|
2313
2333
|
if (count < 0 || count > 65535) {
|
|
2314
2334
|
// Not reached: an input is `PG_ASYNC_INPUT_SIZE` bytes. `pgAsyncZeroed`
|
|
2315
2335
|
// would build a longer one by `push`, which the spawn rules read as
|
|
@@ -2451,8 +2471,13 @@ export const pgAsyncQuery = async (
|
|
|
2451
2471
|
}
|
|
2452
2472
|
let sent: i32 = 0
|
|
2453
2473
|
while (sent >= 0 && sent < toI32(out.length)) {
|
|
2454
|
-
//
|
|
2455
|
-
const
|
|
2474
|
+
// `sent` is at least 0 and below the `length` here, so the difference is the rest.
|
|
2475
|
+
const total: i32 = toI32(out.length)
|
|
2476
|
+
let rest: i32 = 0
|
|
2477
|
+
if (sent >= 0 && total >= 0) {
|
|
2478
|
+
rest = total - sent
|
|
2479
|
+
}
|
|
2480
|
+
const n: i32 = netWrite(fd, out, sent, rest)
|
|
2456
2481
|
if (n === PG_ASYNC_AGAIN) {
|
|
2457
2482
|
const waited: boolean = await writable(fd)
|
|
2458
2483
|
const failed: i32 = pgAsyncWaitFailure(waited)
|
|
@@ -2740,7 +2765,13 @@ const pgAsyncRead = async (
|
|
|
2740
2765
|
return pgAsyncLost(result, PG_ERR_FRAME, 0)
|
|
2741
2766
|
}
|
|
2742
2767
|
const type: i32 = toI32(buf[start])
|
|
2743
|
-
|
|
2768
|
+
// Read here rather than with `getI32BE`, whose window the prover would
|
|
2769
|
+
// need tested again after the calls before it.
|
|
2770
|
+
const length: i32 =
|
|
2771
|
+
(toI32(buf[start + 1]) << 24) |
|
|
2772
|
+
(toI32(buf[start + 2]) << 16) |
|
|
2773
|
+
(toI32(buf[start + 3]) << 8) |
|
|
2774
|
+
toI32(buf[start + 4])
|
|
2744
2775
|
if (length < 4) {
|
|
2745
2776
|
return pgAsyncLost(result, PG_ERR_FRAME, 0)
|
|
2746
2777
|
}
|
|
@@ -2772,10 +2803,12 @@ const pgAsyncRead = async (
|
|
|
2772
2803
|
}
|
|
2773
2804
|
if (type === 68) {
|
|
2774
2805
|
// 'D': DataRow, a count then each column's length (-1 for NULL) and bytes.
|
|
2775
|
-
|
|
2806
|
+
// The body lies in `buf`, so the second test is never taken: it is
|
|
2807
|
+
// the one the count's two bytes are read under.
|
|
2808
|
+
if (size < 2 || body < 0 || body > toI32(buf.length) - 2) {
|
|
2776
2809
|
return pgAsyncLost(result, PG_ERR_FRAME, 0)
|
|
2777
2810
|
}
|
|
2778
|
-
const columns: i32 = toI32(
|
|
2811
|
+
const columns: i32 = toI32((toU16(buf[body]) << 8) | toU16(buf[body + 1]))
|
|
2779
2812
|
if (columns > maxColumns) {
|
|
2780
2813
|
return pgAsyncLost(result, PG_ERR_TOO_BIG, 0)
|
|
2781
2814
|
}
|
|
@@ -2870,7 +2903,12 @@ const pgAsyncRead = async (
|
|
|
2870
2903
|
const held: i32 = end - start
|
|
2871
2904
|
want = toI32(5) - held
|
|
2872
2905
|
if (held >= 5 && start < toI32(buf.length) - 5) {
|
|
2873
|
-
|
|
2906
|
+
// Read here rather than with `getI32BE`, as above.
|
|
2907
|
+
const length: i32 =
|
|
2908
|
+
(toI32(buf[start + 1]) << 24) |
|
|
2909
|
+
(toI32(buf[start + 2]) << 16) |
|
|
2910
|
+
(toI32(buf[start + 3]) << 8) |
|
|
2911
|
+
toI32(buf[start + 4])
|
|
2874
2912
|
// A length past `maxMessage` was failed before this read.
|
|
2875
2913
|
if (length < 4) {
|
|
2876
2914
|
return pgAsyncLost(result, PG_ERR_FRAME, 0)
|
|
@@ -182,6 +182,29 @@ const PG_CARRIER_TIMED_OUT: i32 = -110
|
|
|
182
182
|
const PG_CARRIER_MAX_BATCHERS: i32 = 8
|
|
183
183
|
/** The most queries or executions one carrier holds. */
|
|
184
184
|
const PG_CARRIER_MAX_QUERIES: i32 = 65536
|
|
185
|
+
/** 2^62 - 1 nanoseconds, past any monotonic clock reading; a connect deadline stops there. */
|
|
186
|
+
const PG_CARRIER_CLOCK_MOST: i64 = 1073741824 * 4294967296 - 1
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* The monotonic clock plus `span` nanoseconds, held at `PG_CARRIER_CLOCK_MOST`
|
|
190
|
+
* instead of passing it.
|
|
191
|
+
*
|
|
192
|
+
* @param span - The nanoseconds to add, at least 0.
|
|
193
|
+
* @returns The deadline, or the clock itself when either reading is negative.
|
|
194
|
+
*/
|
|
195
|
+
const pgCarrierDeadline = (span: i64): i64 => {
|
|
196
|
+
const now: i64 = monotonicNanos()
|
|
197
|
+
if (now < 0 || span < 0) {
|
|
198
|
+
return now
|
|
199
|
+
}
|
|
200
|
+
const room: i64 = PG_CARRIER_CLOCK_MOST - now
|
|
201
|
+
if (room < 0) {
|
|
202
|
+
return PG_CARRIER_CLOCK_MOST
|
|
203
|
+
}
|
|
204
|
+
const left: i64 = room - span
|
|
205
|
+
return left > 0 ? PG_CARRIER_CLOCK_MOST - left : PG_CARRIER_CLOCK_MOST
|
|
206
|
+
}
|
|
207
|
+
|
|
185
208
|
/** Where `next()` is in its pass, so that a call resumes where the last stopped. */
|
|
186
209
|
const PG_CARRIER_POLL: i32 = 0
|
|
187
210
|
const PG_CARRIER_SLOTS: i32 = 1
|
|
@@ -466,7 +489,10 @@ export class PgCarrier {
|
|
|
466
489
|
const runs: PgCarrierExecution[] = []
|
|
467
490
|
const eFree: PgCarrierExecution[] = []
|
|
468
491
|
for (let e: i32 = 0; e < executions; e++) {
|
|
469
|
-
|
|
492
|
+
// Summed in i64; both counts are at most PG_CARRIER_MAX_QUERIES, checked
|
|
493
|
+
// above, so the id fits an i32.
|
|
494
|
+
const id: i64 = toI64(queries) + toI64(e)
|
|
495
|
+
runs.push(new PgCarrierExecution(toI32(id)))
|
|
470
496
|
}
|
|
471
497
|
k = toI32(runs.length)
|
|
472
498
|
while (k > 0) {
|
|
@@ -1272,9 +1298,7 @@ export class PgCarrier {
|
|
|
1272
1298
|
const sockets: PgCarrierSlot[] = this.sockets
|
|
1273
1299
|
if (connect) {
|
|
1274
1300
|
let want: i32 = this.pool.wanted()
|
|
1275
|
-
|
|
1276
|
-
// short of the top.
|
|
1277
|
-
const deadline: i64 = want >= 0 ? toI64(toU64(monotonicNanos()) + toU64(this.timeoutNs)) : toI64(0)
|
|
1301
|
+
const deadline: i64 = want >= 0 ? pgCarrierDeadline(this.timeoutNs) : toI64(0)
|
|
1278
1302
|
while (want >= 0 && want < toI32(sockets.length)) {
|
|
1279
1303
|
const slot: PgCarrierSlot = sockets[want]
|
|
1280
1304
|
crypto.getRandomValues(this.nonce)
|