@dolthub/doltlite-wasm 0.50.2 → 0.50.3

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/sqlite3.mjs CHANGED
@@ -433,7 +433,6 @@ if (!Module['noFSInit'] && !FS.initialized)
433
433
  FS.ignorePermissions = false;
434
434
 
435
435
  TTY.init();
436
- SOCKFS.root = FS.mount(SOCKFS, {}, null);
437
436
  callRuntimeCallbacks(__ATINIT__);
438
437
  }
439
438
 
@@ -709,6 +708,11 @@ async function createWasm() {
709
708
  // include: runtime_debug.js
710
709
  // end include: runtime_debug.js
711
710
  // === Body ===
711
+
712
+ function doltliteWasmHttpSend(zUrl,zMethod,zAuth,pBody,nBody,timeoutMs) { var st = Module.__doltliteHttp || (Module.__doltliteHttp = {}); st.resp = null; var url = UTF8ToString(zUrl); var method = UTF8ToString(zMethod); var auth = zAuth ? UTF8ToString(zAuth) : ""; var body = null; if (nBody > 0) { body = new Uint8Array(nBody); body.set(HEAPU8.subarray(pBody, pBody + nBody)); } try { if (typeof XMLHttpRequest !== "undefined") { var xhr = new XMLHttpRequest(); xhr.open(method, url, false); var binaryString = false; try { xhr.responseType = "arraybuffer"; } catch (e) { binaryString = true; } if (xhr.responseType !== "arraybuffer") binaryString = true; if (binaryString && xhr.overrideMimeType) { xhr.overrideMimeType("text/plain; charset=x-user-defined"); } if (auth) xhr.setRequestHeader("Authorization", auth); if (body) xhr.setRequestHeader("Content-Type", "application/octet-stream"); xhr.send(body); if (binaryString) { var text = xhr.responseText || ""; var out = new Uint8Array(text.length); for (var i = 0; i < text.length; i++) out[i] = text.charCodeAt(i) & 0xff; st.resp = out; } else { st.resp = xhr.response ? new Uint8Array(xhr.response) : new Uint8Array(0); } return xhr.status; } if (typeof require === "function" && typeof SharedArrayBuffer !== "undefined") { if (!st.node) { var wt = require("node:worker_threads"); var src = [ "const { workerData } = require('node:worker_threads');", "const ctl = new Int32Array(workerData.ctl);", "const req = workerData.req;", "const data = workerData.data;", "const dec = new TextDecoder();", "(async function(){ for(;;){", " Atomics.wait(ctl, 0, 0);", " if(Atomics.load(ctl,0) !== 1) continue;", " let status = 0, len = 0, over = 0, bad = 0;", " try {", " const nj = Atomics.load(ctl,4), nb = Atomics.load(ctl,5);", " const spec = JSON.parse(dec.decode(new Uint8Array(req, 0, nj)));", " const opt = { method: spec.method };", " if(spec.timeoutMs > 0 && typeof AbortSignal !== 'undefined'", " && AbortSignal.timeout) opt.signal = AbortSignal.timeout(spec.timeoutMs);", " if(spec.auth) opt.headers = { Authorization: spec.auth };", " if(nb > 0){", " opt.body = Buffer.from(new Uint8Array(req, nj, nb));", " opt.headers = Object.assign({}, opt.headers, {'Content-Type':'application/octet-stream'});", " }", " const r = await fetch(spec.url, opt);", " status = r.status;", " const b = new Uint8Array(await r.arrayBuffer());", " len = b.length;", " if(len > data.byteLength){ over = 1; }", " else { new Uint8Array(data).set(b); }", " } catch(e){ bad = 1; }", " Atomics.store(ctl,1,status); Atomics.store(ctl,2,len);", " Atomics.store(ctl,3,bad); Atomics.store(ctl,6,over);", " Atomics.store(ctl,0,2); Atomics.notify(ctl,0);", "} })();" ].join("\n"); var ctlSab = new SharedArrayBuffer(32); st.node = { ctl: new Int32Array(ctlSab), ctlSab: ctlSab, req: new SharedArrayBuffer(8 * 1024 * 1024), data: new SharedArrayBuffer(8 * 1024 * 1024), src: src, wt: wt }; st.node.worker = new wt.Worker(src, { eval: true, workerData: { ctl: ctlSab, req: st.node.req, data: st.node.data } }); st.node.worker.unref(); } var n = st.node; for (;;) { var spec = JSON.stringify({ url: url, method: method, auth: auth, timeoutMs: timeoutMs }); var enc = new TextEncoder().encode(spec); if (enc.length + (body ? body.length : 0) > n.req.byteLength) return 0; new Uint8Array(n.req).set(enc, 0); if (body) new Uint8Array(n.req).set(body, enc.length); Atomics.store(n.ctl, 4, enc.length); Atomics.store(n.ctl, 5, body ? body.length : 0); Atomics.store(n.ctl, 6, 0); Atomics.store(n.ctl, 0, 1); Atomics.notify(n.ctl, 0); Atomics.wait(n.ctl, 0, 1); var over = Atomics.load(n.ctl, 6); var need = Atomics.load(n.ctl, 2); var bad = Atomics.load(n.ctl, 3); var status = Atomics.load(n.ctl, 1); Atomics.store(n.ctl, 0, 0); if (over) { var grow = n.data.byteLength; while (grow < need) grow *= 2; n.data = new SharedArrayBuffer(grow); n.worker.terminate(); n.worker = new n.wt.Worker(n.src, { eval: true, workerData: { ctl: n.ctlSab, req: n.req, data: n.data } }); n.worker.unref(); continue; } if (bad) return 0; st.resp = new Uint8Array(need); st.resp.set(new Uint8Array(n.data, 0, need)); return status; } } } catch (e) { st.resp = null; return 0; } return 0; }
713
+ function doltliteWasmHttpRespLen() { var st = Module.__doltliteHttp; return (st && st.resp) ? st.resp.length : 0; }
714
+ function doltliteWasmHttpRespTake(pDest) { var st = Module.__doltliteHttp; if (st && st.resp) HEAPU8.set(st.resp, pDest); if (st) st.resp = null; }
715
+
712
716
  // end include: preamble.js
713
717
 
714
718
 
@@ -3303,865 +3307,6 @@ async function createWasm() {
3303
3307
  }
3304
3308
  }
3305
3309
 
3306
- var SOCKFS = {
3307
- websocketArgs:{
3308
- },
3309
- callbacks:{
3310
- },
3311
- on(event, callback) {
3312
- SOCKFS.callbacks[event] = callback;
3313
- },
3314
- emit(event, param) {
3315
- SOCKFS.callbacks[event]?.(param);
3316
- },
3317
- mount(mount) {
3318
- // The incomming Module['websocket'] can be used for configuring
3319
- // configuring subprotocol/url, etc
3320
- SOCKFS.websocketArgs = Module['websocket'] || {};
3321
- // Add the Event registration mechanism to the exported websocket configuration
3322
- // object so we can register network callbacks from native JavaScript too.
3323
- // For more documentation see system/include/emscripten/emscripten.h
3324
- (Module['websocket'] ??= {})['on'] = SOCKFS.on;
3325
-
3326
- return FS.createNode(null, '/', 16895, 0);
3327
- },
3328
- createSocket(family, type, protocol) {
3329
- type &= ~526336; // Some applications may pass it; it makes no sense for a single process.
3330
- var streaming = type == 1;
3331
- if (streaming && protocol && protocol != 6) {
3332
- throw new FS.ErrnoError(66); // if SOCK_STREAM, must be tcp or 0.
3333
- }
3334
-
3335
- // create our internal socket structure
3336
- var sock = {
3337
- family,
3338
- type,
3339
- protocol,
3340
- server: null,
3341
- error: null, // Used in getsockopt for SOL_SOCKET/SO_ERROR test
3342
- peers: {},
3343
- pending: [],
3344
- recv_queue: [],
3345
- sock_ops: SOCKFS.websocket_sock_ops
3346
- };
3347
-
3348
- // create the filesystem node to store the socket structure
3349
- var name = SOCKFS.nextname();
3350
- var node = FS.createNode(SOCKFS.root, name, 49152, 0);
3351
- node.sock = sock;
3352
-
3353
- // and the wrapping stream that enables library functions such
3354
- // as read and write to indirectly interact with the socket
3355
- var stream = FS.createStream({
3356
- path: name,
3357
- node,
3358
- flags: 2,
3359
- seekable: false,
3360
- stream_ops: SOCKFS.stream_ops
3361
- });
3362
-
3363
- // map the new stream to the socket structure (sockets have a 1:1
3364
- // relationship with a stream)
3365
- sock.stream = stream;
3366
-
3367
- return sock;
3368
- },
3369
- getSocket(fd) {
3370
- var stream = FS.getStream(fd);
3371
- if (!stream || !FS.isSocket(stream.node.mode)) {
3372
- return null;
3373
- }
3374
- return stream.node.sock;
3375
- },
3376
- stream_ops:{
3377
- poll(stream) {
3378
- var sock = stream.node.sock;
3379
- return sock.sock_ops.poll(sock);
3380
- },
3381
- ioctl(stream, request, varargs) {
3382
- var sock = stream.node.sock;
3383
- return sock.sock_ops.ioctl(sock, request, varargs);
3384
- },
3385
- read(stream, buffer, offset, length, position /* ignored */) {
3386
- var sock = stream.node.sock;
3387
- var msg = sock.sock_ops.recvmsg(sock, length);
3388
- if (!msg) {
3389
- // socket is closed
3390
- return 0;
3391
- }
3392
- buffer.set(msg.buffer, offset);
3393
- return msg.buffer.length;
3394
- },
3395
- write(stream, buffer, offset, length, position /* ignored */) {
3396
- var sock = stream.node.sock;
3397
- return sock.sock_ops.sendmsg(sock, buffer, offset, length);
3398
- },
3399
- close(stream) {
3400
- var sock = stream.node.sock;
3401
- sock.sock_ops.close(sock);
3402
- },
3403
- },
3404
- nextname() {
3405
- if (!SOCKFS.nextname.current) {
3406
- SOCKFS.nextname.current = 0;
3407
- }
3408
- return `socket[${SOCKFS.nextname.current++}]`;
3409
- },
3410
- websocket_sock_ops:{
3411
- createPeer(sock, addr, port) {
3412
- var ws;
3413
-
3414
- if (typeof addr == 'object') {
3415
- ws = addr;
3416
- addr = null;
3417
- port = null;
3418
- }
3419
-
3420
- if (ws) {
3421
- // for sockets that've already connected (e.g. we're the server)
3422
- // we can inspect the _socket property for the address
3423
- if (ws._socket) {
3424
- addr = ws._socket.remoteAddress;
3425
- port = ws._socket.remotePort;
3426
- }
3427
- // if we're just now initializing a connection to the remote,
3428
- // inspect the url property
3429
- else {
3430
- var result = /ws[s]?:\/\/([^:]+):(\d+)/.exec(ws.url);
3431
- if (!result) {
3432
- throw new Error('WebSocket URL must be in the format ws(s)://address:port');
3433
- }
3434
- addr = result[1];
3435
- port = parseInt(result[2], 10);
3436
- }
3437
- } else {
3438
- // create the actual websocket object and connect
3439
- try {
3440
- // The default value is 'ws://' the replace is needed because the compiler replaces '//' comments with '#'
3441
- // comments without checking context, so we'd end up with ws:#, the replace swaps the '#' for '//' again.
3442
- var url = 'ws:#'.replace('#', '//');
3443
- // Make the WebSocket subprotocol (Sec-WebSocket-Protocol) default to binary if no configuration is set.
3444
- var subProtocols = 'binary'; // The default value is 'binary'
3445
- // The default WebSocket options
3446
- var opts = undefined;
3447
-
3448
- // Fetch runtime WebSocket URL config.
3449
- if (SOCKFS.websocketArgs['url']) {
3450
- url = SOCKFS.websocketArgs['url'];
3451
- }
3452
- // Fetch runtime WebSocket subprotocol config.
3453
- if (SOCKFS.websocketArgs['subprotocol']) {
3454
- subProtocols = SOCKFS.websocketArgs['subprotocol'];
3455
- } else if (SOCKFS.websocketArgs['subprotocol'] === null) {
3456
- subProtocols = 'null'
3457
- }
3458
-
3459
- if (url === 'ws://' || url === 'wss://') { // Is the supplied URL config just a prefix, if so complete it.
3460
- var parts = addr.split('/');
3461
- url = url + parts[0] + ":" + port + "/" + parts.slice(1).join('/');
3462
- }
3463
-
3464
- if (subProtocols !== 'null') {
3465
- // The regex trims the string (removes spaces at the beginning and end, then splits the string by
3466
- // <any space>,<any space> into an Array. Whitespace removal is important for Websockify and ws.
3467
- subProtocols = subProtocols.replace(/^ +| +$/g,"").split(/ *, */);
3468
-
3469
- opts = subProtocols;
3470
- }
3471
-
3472
- // If node we use the ws library.
3473
- var WebSocketConstructor;
3474
- {
3475
- WebSocketConstructor = WebSocket;
3476
- }
3477
- ws = new WebSocketConstructor(url, opts);
3478
- ws.binaryType = 'arraybuffer';
3479
- } catch (e) {
3480
- throw new FS.ErrnoError(23);
3481
- }
3482
- }
3483
-
3484
- var peer = {
3485
- addr,
3486
- port,
3487
- socket: ws,
3488
- msg_send_queue: []
3489
- };
3490
-
3491
- SOCKFS.websocket_sock_ops.addPeer(sock, peer);
3492
- SOCKFS.websocket_sock_ops.handlePeerEvents(sock, peer);
3493
-
3494
- // if this is a bound dgram socket, send the port number first to allow
3495
- // us to override the ephemeral port reported to us by remotePort on the
3496
- // remote end.
3497
- if (sock.type === 2 && typeof sock.sport != 'undefined') {
3498
- peer.msg_send_queue.push(new Uint8Array([
3499
- 255, 255, 255, 255,
3500
- 'p'.charCodeAt(0), 'o'.charCodeAt(0), 'r'.charCodeAt(0), 't'.charCodeAt(0),
3501
- ((sock.sport & 0xff00) >> 8) , (sock.sport & 0xff)
3502
- ]));
3503
- }
3504
-
3505
- return peer;
3506
- },
3507
- getPeer(sock, addr, port) {
3508
- return sock.peers[addr + ':' + port];
3509
- },
3510
- addPeer(sock, peer) {
3511
- sock.peers[peer.addr + ':' + peer.port] = peer;
3512
- },
3513
- removePeer(sock, peer) {
3514
- delete sock.peers[peer.addr + ':' + peer.port];
3515
- },
3516
- handlePeerEvents(sock, peer) {
3517
- var first = true;
3518
-
3519
- var handleOpen = function () {
3520
-
3521
- sock.connecting = false;
3522
- SOCKFS.emit('open', sock.stream.fd);
3523
-
3524
- try {
3525
- var queued = peer.msg_send_queue.shift();
3526
- while (queued) {
3527
- peer.socket.send(queued);
3528
- queued = peer.msg_send_queue.shift();
3529
- }
3530
- } catch (e) {
3531
- // not much we can do here in the way of proper error handling as we've already
3532
- // lied and said this data was sent. shut it down.
3533
- peer.socket.close();
3534
- }
3535
- };
3536
-
3537
- function handleMessage(data) {
3538
- if (typeof data == 'string') {
3539
- var encoder = new TextEncoder(); // should be utf-8
3540
- data = encoder.encode(data); // make a typed array from the string
3541
- } else {
3542
- assert(data.byteLength !== undefined); // must receive an ArrayBuffer
3543
- if (data.byteLength == 0) {
3544
- // An empty ArrayBuffer will emit a pseudo disconnect event
3545
- // as recv/recvmsg will return zero which indicates that a socket
3546
- // has performed a shutdown although the connection has not been disconnected yet.
3547
- return;
3548
- }
3549
- data = new Uint8Array(data); // make a typed array view on the array buffer
3550
- }
3551
-
3552
- // if this is the port message, override the peer's port with it
3553
- var wasfirst = first;
3554
- first = false;
3555
- if (wasfirst &&
3556
- data.length === 10 &&
3557
- data[0] === 255 && data[1] === 255 && data[2] === 255 && data[3] === 255 &&
3558
- data[4] === 'p'.charCodeAt(0) && data[5] === 'o'.charCodeAt(0) && data[6] === 'r'.charCodeAt(0) && data[7] === 't'.charCodeAt(0)) {
3559
- // update the peer's port and it's key in the peer map
3560
- var newport = ((data[8] << 8) | data[9]);
3561
- SOCKFS.websocket_sock_ops.removePeer(sock, peer);
3562
- peer.port = newport;
3563
- SOCKFS.websocket_sock_ops.addPeer(sock, peer);
3564
- return;
3565
- }
3566
-
3567
- sock.recv_queue.push({ addr: peer.addr, port: peer.port, data: data });
3568
- SOCKFS.emit('message', sock.stream.fd);
3569
- };
3570
-
3571
- if (ENVIRONMENT_IS_NODE) {
3572
- peer.socket.on('open', handleOpen);
3573
- peer.socket.on('message', function(data, isBinary) {
3574
- if (!isBinary) {
3575
- return;
3576
- }
3577
- handleMessage((new Uint8Array(data)).buffer); // copy from node Buffer -> ArrayBuffer
3578
- });
3579
- peer.socket.on('close', function() {
3580
- SOCKFS.emit('close', sock.stream.fd);
3581
- });
3582
- peer.socket.on('error', function(error) {
3583
- // Although the ws library may pass errors that may be more descriptive than
3584
- // ECONNREFUSED they are not necessarily the expected error code e.g.
3585
- // ENOTFOUND on getaddrinfo seems to be node.js specific, so using ECONNREFUSED
3586
- // is still probably the most useful thing to do.
3587
- sock.error = 14; // Used in getsockopt for SOL_SOCKET/SO_ERROR test.
3588
- SOCKFS.emit('error', [sock.stream.fd, sock.error, 'ECONNREFUSED: Connection refused']);
3589
- // don't throw
3590
- });
3591
- } else {
3592
- peer.socket.onopen = handleOpen;
3593
- peer.socket.onclose = function() {
3594
- SOCKFS.emit('close', sock.stream.fd);
3595
- };
3596
- peer.socket.onmessage = function peer_socket_onmessage(event) {
3597
- handleMessage(event.data);
3598
- };
3599
- peer.socket.onerror = function(error) {
3600
- // The WebSocket spec only allows a 'simple event' to be thrown on error,
3601
- // so we only really know as much as ECONNREFUSED.
3602
- sock.error = 14; // Used in getsockopt for SOL_SOCKET/SO_ERROR test.
3603
- SOCKFS.emit('error', [sock.stream.fd, sock.error, 'ECONNREFUSED: Connection refused']);
3604
- };
3605
- }
3606
- },
3607
- poll(sock) {
3608
- if (sock.type === 1 && sock.server) {
3609
- // listen sockets should only say they're available for reading
3610
- // if there are pending clients.
3611
- return sock.pending.length ? (64 | 1) : 0;
3612
- }
3613
-
3614
- var mask = 0;
3615
- var dest = sock.type === 1 ? // we only care about the socket state for connection-based sockets
3616
- SOCKFS.websocket_sock_ops.getPeer(sock, sock.daddr, sock.dport) :
3617
- null;
3618
-
3619
- if (sock.recv_queue.length ||
3620
- !dest || // connection-less sockets are always ready to read
3621
- (dest && dest.socket.readyState === dest.socket.CLOSING) ||
3622
- (dest && dest.socket.readyState === dest.socket.CLOSED)) { // let recv return 0 once closed
3623
- mask |= (64 | 1);
3624
- }
3625
-
3626
- if (!dest || // connection-less sockets are always ready to write
3627
- (dest && dest.socket.readyState === dest.socket.OPEN)) {
3628
- mask |= 4;
3629
- }
3630
-
3631
- if ((dest && dest.socket.readyState === dest.socket.CLOSING) ||
3632
- (dest && dest.socket.readyState === dest.socket.CLOSED)) {
3633
- // When an non-blocking connect fails mark the socket as writable.
3634
- // Its up to the calling code to then use getsockopt with SO_ERROR to
3635
- // retrieve the error.
3636
- // See https://man7.org/linux/man-pages/man2/connect.2.html
3637
- if (sock.connecting) {
3638
- mask |= 4;
3639
- } else {
3640
- mask |= 16;
3641
- }
3642
- }
3643
-
3644
- return mask;
3645
- },
3646
- ioctl(sock, request, arg) {
3647
- switch (request) {
3648
- case 21531:
3649
- var bytes = 0;
3650
- if (sock.recv_queue.length) {
3651
- bytes = sock.recv_queue[0].data.length;
3652
- }
3653
- HEAP32[((arg)>>2)] = bytes;
3654
- return 0;
3655
- default:
3656
- return 28;
3657
- }
3658
- },
3659
- close(sock) {
3660
- // if we've spawned a listen server, close it
3661
- if (sock.server) {
3662
- try {
3663
- sock.server.close();
3664
- } catch (e) {
3665
- }
3666
- sock.server = null;
3667
- }
3668
- // close any peer connections
3669
- var peers = Object.keys(sock.peers);
3670
- for (var i = 0; i < peers.length; i++) {
3671
- var peer = sock.peers[peers[i]];
3672
- try {
3673
- peer.socket.close();
3674
- } catch (e) {
3675
- }
3676
- SOCKFS.websocket_sock_ops.removePeer(sock, peer);
3677
- }
3678
- return 0;
3679
- },
3680
- bind(sock, addr, port) {
3681
- if (typeof sock.saddr != 'undefined' || typeof sock.sport != 'undefined') {
3682
- throw new FS.ErrnoError(28); // already bound
3683
- }
3684
- sock.saddr = addr;
3685
- sock.sport = port;
3686
- // in order to emulate dgram sockets, we need to launch a listen server when
3687
- // binding on a connection-less socket
3688
- // note: this is only required on the server side
3689
- if (sock.type === 2) {
3690
- // close the existing server if it exists
3691
- if (sock.server) {
3692
- sock.server.close();
3693
- sock.server = null;
3694
- }
3695
- // swallow error operation not supported error that occurs when binding in the
3696
- // browser where this isn't supported
3697
- try {
3698
- sock.sock_ops.listen(sock, 0);
3699
- } catch (e) {
3700
- if (!(e.name === 'ErrnoError')) throw e;
3701
- if (e.errno !== 138) throw e;
3702
- }
3703
- }
3704
- },
3705
- connect(sock, addr, port) {
3706
- if (sock.server) {
3707
- throw new FS.ErrnoError(138);
3708
- }
3709
-
3710
- // TODO autobind
3711
- // if (!sock.addr && sock.type == 2) {
3712
- // }
3713
-
3714
- // early out if we're already connected / in the middle of connecting
3715
- if (typeof sock.daddr != 'undefined' && typeof sock.dport != 'undefined') {
3716
- var dest = SOCKFS.websocket_sock_ops.getPeer(sock, sock.daddr, sock.dport);
3717
- if (dest) {
3718
- if (dest.socket.readyState === dest.socket.CONNECTING) {
3719
- throw new FS.ErrnoError(7);
3720
- } else {
3721
- throw new FS.ErrnoError(30);
3722
- }
3723
- }
3724
- }
3725
-
3726
- // add the socket to our peer list and set our
3727
- // destination address / port to match
3728
- var peer = SOCKFS.websocket_sock_ops.createPeer(sock, addr, port);
3729
- sock.daddr = peer.addr;
3730
- sock.dport = peer.port;
3731
-
3732
- // because we cannot synchronously block to wait for the WebSocket
3733
- // connection to complete, we return here pretending that the connection
3734
- // was a success.
3735
- sock.connecting = true;
3736
- },
3737
- listen(sock, backlog) {
3738
- if (!ENVIRONMENT_IS_NODE) {
3739
- throw new FS.ErrnoError(138);
3740
- }
3741
- },
3742
- accept(listensock) {
3743
- if (!listensock.server || !listensock.pending.length) {
3744
- throw new FS.ErrnoError(28);
3745
- }
3746
- var newsock = listensock.pending.shift();
3747
- newsock.stream.flags = listensock.stream.flags;
3748
- return newsock;
3749
- },
3750
- getname(sock, peer) {
3751
- var addr, port;
3752
- if (peer) {
3753
- if (sock.daddr === undefined || sock.dport === undefined) {
3754
- throw new FS.ErrnoError(53);
3755
- }
3756
- addr = sock.daddr;
3757
- port = sock.dport;
3758
- } else {
3759
- // TODO saddr and sport will be set for bind()'d UDP sockets, but what
3760
- // should we be returning for TCP sockets that've been connect()'d?
3761
- addr = sock.saddr || 0;
3762
- port = sock.sport || 0;
3763
- }
3764
- return { addr, port };
3765
- },
3766
- sendmsg(sock, buffer, offset, length, addr, port) {
3767
- if (sock.type === 2) {
3768
- // connection-less sockets will honor the message address,
3769
- // and otherwise fall back to the bound destination address
3770
- if (addr === undefined || port === undefined) {
3771
- addr = sock.daddr;
3772
- port = sock.dport;
3773
- }
3774
- // if there was no address to fall back to, error out
3775
- if (addr === undefined || port === undefined) {
3776
- throw new FS.ErrnoError(17);
3777
- }
3778
- } else {
3779
- // connection-based sockets will only use the bound
3780
- addr = sock.daddr;
3781
- port = sock.dport;
3782
- }
3783
-
3784
- // find the peer for the destination address
3785
- var dest = SOCKFS.websocket_sock_ops.getPeer(sock, addr, port);
3786
-
3787
- // early out if not connected with a connection-based socket
3788
- if (sock.type === 1) {
3789
- if (!dest || dest.socket.readyState === dest.socket.CLOSING || dest.socket.readyState === dest.socket.CLOSED) {
3790
- throw new FS.ErrnoError(53);
3791
- }
3792
- }
3793
-
3794
- // create a copy of the incoming data to send, as the WebSocket API
3795
- // doesn't work entirely with an ArrayBufferView, it'll just send
3796
- // the entire underlying buffer
3797
- if (ArrayBuffer.isView(buffer)) {
3798
- offset += buffer.byteOffset;
3799
- buffer = buffer.buffer;
3800
- }
3801
-
3802
- var data = buffer.slice(offset, offset + length);
3803
-
3804
- // if we don't have a cached connectionless UDP datagram connection, or
3805
- // the TCP socket is still connecting, queue the message to be sent upon
3806
- // connect, and lie, saying the data was sent now.
3807
- if (!dest || dest.socket.readyState !== dest.socket.OPEN) {
3808
- // if we're not connected, open a new connection
3809
- if (sock.type === 2) {
3810
- if (!dest || dest.socket.readyState === dest.socket.CLOSING || dest.socket.readyState === dest.socket.CLOSED) {
3811
- dest = SOCKFS.websocket_sock_ops.createPeer(sock, addr, port);
3812
- }
3813
- }
3814
- dest.msg_send_queue.push(data);
3815
- return length;
3816
- }
3817
-
3818
- try {
3819
- // send the actual data
3820
- dest.socket.send(data);
3821
- return length;
3822
- } catch (e) {
3823
- throw new FS.ErrnoError(28);
3824
- }
3825
- },
3826
- recvmsg(sock, length) {
3827
- // http://pubs.opengroup.org/onlinepubs/7908799/xns/recvmsg.html
3828
- if (sock.type === 1 && sock.server) {
3829
- // tcp servers should not be recv()'ing on the listen socket
3830
- throw new FS.ErrnoError(53);
3831
- }
3832
-
3833
- var queued = sock.recv_queue.shift();
3834
- if (!queued) {
3835
- if (sock.type === 1) {
3836
- var dest = SOCKFS.websocket_sock_ops.getPeer(sock, sock.daddr, sock.dport);
3837
-
3838
- if (!dest) {
3839
- // if we have a destination address but are not connected, error out
3840
- throw new FS.ErrnoError(53);
3841
- }
3842
- if (dest.socket.readyState === dest.socket.CLOSING || dest.socket.readyState === dest.socket.CLOSED) {
3843
- // return null if the socket has closed
3844
- return null;
3845
- }
3846
- // else, our socket is in a valid state but truly has nothing available
3847
- throw new FS.ErrnoError(6);
3848
- }
3849
- throw new FS.ErrnoError(6);
3850
- }
3851
-
3852
- // queued.data will be an ArrayBuffer if it's unadulterated, but if it's
3853
- // requeued TCP data it'll be an ArrayBufferView
3854
- var queuedLength = queued.data.byteLength || queued.data.length;
3855
- var queuedOffset = queued.data.byteOffset || 0;
3856
- var queuedBuffer = queued.data.buffer || queued.data;
3857
- var bytesRead = Math.min(length, queuedLength);
3858
- var res = {
3859
- buffer: new Uint8Array(queuedBuffer, queuedOffset, bytesRead),
3860
- addr: queued.addr,
3861
- port: queued.port
3862
- };
3863
-
3864
- // push back any unread data for TCP connections
3865
- if (sock.type === 1 && bytesRead < queuedLength) {
3866
- var bytesRemaining = queuedLength - bytesRead;
3867
- queued.data = new Uint8Array(queuedBuffer, queuedOffset + bytesRead, bytesRemaining);
3868
- sock.recv_queue.unshift(queued);
3869
- }
3870
-
3871
- return res;
3872
- },
3873
- },
3874
- };
3875
-
3876
- var getSocketFromFD = (fd) => {
3877
- var socket = SOCKFS.getSocket(fd);
3878
- if (!socket) throw new FS.ErrnoError(8);
3879
- return socket;
3880
- };
3881
-
3882
- var Sockets = {
3883
- BUFFER_SIZE:10240,
3884
- MAX_BUFFER_SIZE:10485760,
3885
- nextFd:1,
3886
- fds:{
3887
- },
3888
- nextport:1,
3889
- maxport:65535,
3890
- peer:null,
3891
- connections:{
3892
- },
3893
- portmap:{
3894
- },
3895
- localAddr:4261412874,
3896
- addrPool:[33554442,50331658,67108874,83886090,100663306,117440522,134217738,150994954,167772170,184549386,201326602,218103818,234881034],
3897
- };
3898
-
3899
- var inetNtop4 = (addr) =>
3900
- (addr & 0xff) + '.' + ((addr >> 8) & 0xff) + '.' + ((addr >> 16) & 0xff) + '.' + ((addr >> 24) & 0xff);
3901
-
3902
-
3903
- var inetNtop6 = (ints) => {
3904
- // ref: http://www.ietf.org/rfc/rfc2373.txt - section 2.5.4
3905
- // Format for IPv4 compatible and mapped 128-bit IPv6 Addresses
3906
- // 128-bits are split into eight 16-bit words
3907
- // stored in network byte order (big-endian)
3908
- // | 80 bits | 16 | 32 bits |
3909
- // +-----------------------------------------------------------------+
3910
- // | 10 bytes | 2 | 4 bytes |
3911
- // +--------------------------------------+--------------------------+
3912
- // + 5 words | 1 | 2 words |
3913
- // +--------------------------------------+--------------------------+
3914
- // |0000..............................0000|0000| IPv4 ADDRESS | (compatible)
3915
- // +--------------------------------------+----+---------------------+
3916
- // |0000..............................0000|FFFF| IPv4 ADDRESS | (mapped)
3917
- // +--------------------------------------+----+---------------------+
3918
- var str = "";
3919
- var word = 0;
3920
- var longest = 0;
3921
- var lastzero = 0;
3922
- var zstart = 0;
3923
- var len = 0;
3924
- var i = 0;
3925
- var parts = [
3926
- ints[0] & 0xffff,
3927
- (ints[0] >> 16),
3928
- ints[1] & 0xffff,
3929
- (ints[1] >> 16),
3930
- ints[2] & 0xffff,
3931
- (ints[2] >> 16),
3932
- ints[3] & 0xffff,
3933
- (ints[3] >> 16)
3934
- ];
3935
-
3936
- // Handle IPv4-compatible, IPv4-mapped, loopback and any/unspecified addresses
3937
-
3938
- var hasipv4 = true;
3939
- var v4part = "";
3940
- // check if the 10 high-order bytes are all zeros (first 5 words)
3941
- for (i = 0; i < 5; i++) {
3942
- if (parts[i] !== 0) { hasipv4 = false; break; }
3943
- }
3944
-
3945
- if (hasipv4) {
3946
- // low-order 32-bits store an IPv4 address (bytes 13 to 16) (last 2 words)
3947
- v4part = inetNtop4(parts[6] | (parts[7] << 16));
3948
- // IPv4-mapped IPv6 address if 16-bit value (bytes 11 and 12) == 0xFFFF (6th word)
3949
- if (parts[5] === -1) {
3950
- str = "::ffff:";
3951
- str += v4part;
3952
- return str;
3953
- }
3954
- // IPv4-compatible IPv6 address if 16-bit value (bytes 11 and 12) == 0x0000 (6th word)
3955
- if (parts[5] === 0) {
3956
- str = "::";
3957
- //special case IPv6 addresses
3958
- if (v4part === "0.0.0.0") v4part = ""; // any/unspecified address
3959
- if (v4part === "0.0.0.1") v4part = "1";// loopback address
3960
- str += v4part;
3961
- return str;
3962
- }
3963
- }
3964
-
3965
- // Handle all other IPv6 addresses
3966
-
3967
- // first run to find the longest contiguous zero words
3968
- for (word = 0; word < 8; word++) {
3969
- if (parts[word] === 0) {
3970
- if (word - lastzero > 1) {
3971
- len = 0;
3972
- }
3973
- lastzero = word;
3974
- len++;
3975
- }
3976
- if (len > longest) {
3977
- longest = len;
3978
- zstart = word - longest + 1;
3979
- }
3980
- }
3981
-
3982
- for (word = 0; word < 8; word++) {
3983
- if (longest > 1) {
3984
- // compress contiguous zeros - to produce "::"
3985
- if (parts[word] === 0 && word >= zstart && word < (zstart + longest) ) {
3986
- if (word === zstart) {
3987
- str += ":";
3988
- if (zstart === 0) str += ":"; //leading zeros case
3989
- }
3990
- continue;
3991
- }
3992
- }
3993
- // converts 16-bit words from big-endian to little-endian before converting to hex string
3994
- str += Number(_ntohs(parts[word] & 0xffff)).toString(16);
3995
- str += word < 7 ? ":" : "";
3996
- }
3997
- return str;
3998
- };
3999
-
4000
- var readSockaddr = (sa, salen) => {
4001
- // family / port offsets are common to both sockaddr_in and sockaddr_in6
4002
- var family = HEAP16[((sa)>>1)];
4003
- var port = _ntohs(HEAPU16[(((sa)+(2))>>1)]);
4004
- var addr;
4005
-
4006
- switch (family) {
4007
- case 2:
4008
- if (salen !== 16) {
4009
- return { errno: 28 };
4010
- }
4011
- addr = HEAP32[(((sa)+(4))>>2)];
4012
- addr = inetNtop4(addr);
4013
- break;
4014
- case 10:
4015
- if (salen !== 28) {
4016
- return { errno: 28 };
4017
- }
4018
- addr = [
4019
- HEAP32[(((sa)+(8))>>2)],
4020
- HEAP32[(((sa)+(12))>>2)],
4021
- HEAP32[(((sa)+(16))>>2)],
4022
- HEAP32[(((sa)+(20))>>2)]
4023
- ];
4024
- addr = inetNtop6(addr);
4025
- break;
4026
- default:
4027
- return { errno: 5 };
4028
- }
4029
-
4030
- return { family: family, addr: addr, port: port };
4031
- };
4032
-
4033
-
4034
- var inetPton4 = (str) => {
4035
- var b = str.split('.');
4036
- for (var i = 0; i < 4; i++) {
4037
- var tmp = Number(b[i]);
4038
- if (isNaN(tmp)) return null;
4039
- b[i] = tmp;
4040
- }
4041
- return (b[0] | (b[1] << 8) | (b[2] << 16) | (b[3] << 24)) >>> 0;
4042
- };
4043
-
4044
-
4045
- /** @suppress {checkTypes} */
4046
- var jstoi_q = (str) => parseInt(str);
4047
- var inetPton6 = (str) => {
4048
- var words;
4049
- var w, offset, z, i;
4050
- /* http://home.deds.nl/~aeron/regex/ */
4051
- var valid6regx = /^((?=.*::)(?!.*::.+::)(::)?([\dA-F]{1,4}:(:|\b)|){5}|([\dA-F]{1,4}:){6})((([\dA-F]{1,4}((?!\3)::|:\b|$))|(?!\2\3)){2}|(((2[0-4]|1\d|[1-9])?\d|25[0-5])\.?\b){4})$/i
4052
- var parts = [];
4053
- if (!valid6regx.test(str)) {
4054
- return null;
4055
- }
4056
- if (str === "::") {
4057
- return [0, 0, 0, 0, 0, 0, 0, 0];
4058
- }
4059
- // Z placeholder to keep track of zeros when splitting the string on ":"
4060
- if (str.startsWith("::")) {
4061
- str = str.replace("::", "Z:"); // leading zeros case
4062
- } else {
4063
- str = str.replace("::", ":Z:");
4064
- }
4065
-
4066
- if (str.indexOf(".") > 0) {
4067
- // parse IPv4 embedded stress
4068
- str = str.replace(new RegExp('[.]', 'g'), ":");
4069
- words = str.split(":");
4070
- words[words.length-4] = jstoi_q(words[words.length-4]) + jstoi_q(words[words.length-3])*256;
4071
- words[words.length-3] = jstoi_q(words[words.length-2]) + jstoi_q(words[words.length-1])*256;
4072
- words = words.slice(0, words.length-2);
4073
- } else {
4074
- words = str.split(":");
4075
- }
4076
-
4077
- offset = 0; z = 0;
4078
- for (w=0; w < words.length; w++) {
4079
- if (typeof words[w] == 'string') {
4080
- if (words[w] === 'Z') {
4081
- // compressed zeros - write appropriate number of zero words
4082
- for (z = 0; z < (8 - words.length+1); z++) {
4083
- parts[w+z] = 0;
4084
- }
4085
- offset = z-1;
4086
- } else {
4087
- // parse hex to field to 16-bit value and write it in network byte-order
4088
- parts[w+offset] = _htons(parseInt(words[w],16));
4089
- }
4090
- } else {
4091
- // parsed IPv4 words
4092
- parts[w+offset] = words[w];
4093
- }
4094
- }
4095
- return [
4096
- (parts[1] << 16) | parts[0],
4097
- (parts[3] << 16) | parts[2],
4098
- (parts[5] << 16) | parts[4],
4099
- (parts[7] << 16) | parts[6]
4100
- ];
4101
- };
4102
- var DNS = {
4103
- address_map:{
4104
- id:1,
4105
- addrs:{
4106
- },
4107
- names:{
4108
- },
4109
- },
4110
- lookup_name(name) {
4111
- // If the name is already a valid ipv4 / ipv6 address, don't generate a fake one.
4112
- var res = inetPton4(name);
4113
- if (res !== null) {
4114
- return name;
4115
- }
4116
- res = inetPton6(name);
4117
- if (res !== null) {
4118
- return name;
4119
- }
4120
-
4121
- // See if this name is already mapped.
4122
- var addr;
4123
-
4124
- if (DNS.address_map.addrs[name]) {
4125
- addr = DNS.address_map.addrs[name];
4126
- } else {
4127
- var id = DNS.address_map.id++;
4128
- assert(id < 65535, 'exceeded max address mappings of 65535');
4129
-
4130
- addr = '172.29.' + (id & 0xff) + '.' + (id & 0xff00);
4131
-
4132
- DNS.address_map.names[addr] = name;
4133
- DNS.address_map.addrs[name] = addr;
4134
- }
4135
-
4136
- return addr;
4137
- },
4138
- lookup_addr(addr) {
4139
- if (DNS.address_map.names[addr]) {
4140
- return DNS.address_map.names[addr];
4141
- }
4142
-
4143
- return null;
4144
- },
4145
- };
4146
- var getSocketAddress = (addrp, addrlen) => {
4147
- var info = readSockaddr(addrp, addrlen);
4148
- if (info.errno) throw new FS.ErrnoError(info.errno);
4149
- info.addr = DNS.lookup_addr(info.addr) || info.addr;
4150
- return info;
4151
- };
4152
- function ___syscall_connect(fd, addr, addrlen, d1, d2, d3) {
4153
- try {
4154
-
4155
- var sock = getSocketFromFD(fd);
4156
- var info = getSocketAddress(addr, addrlen);
4157
- sock.sock_ops.connect(sock, info.addr, info.port);
4158
- return 0;
4159
- } catch (e) {
4160
- if (typeof FS == 'undefined' || !(e.name === 'ErrnoError')) throw e;
4161
- return -e.errno;
4162
- }
4163
- }
4164
-
4165
3310
  function ___syscall_faccessat(dirfd, path, amode, flags) {
4166
3311
  try {
4167
3312
 
@@ -4388,27 +3533,6 @@ async function createWasm() {
4388
3533
  }
4389
3534
  }
4390
3535
 
4391
- function ___syscall_getsockopt(fd, level, optname, optval, optlen, d1) {
4392
- try {
4393
-
4394
- var sock = getSocketFromFD(fd);
4395
- // Minimal getsockopt aimed at resolving https://github.com/emscripten-core/emscripten/issues/2211
4396
- // so only supports SOL_SOCKET with SO_ERROR.
4397
- if (level === 1) {
4398
- if (optname === 4) {
4399
- HEAP32[((optval)>>2)] = sock.error;
4400
- HEAP32[((optlen)>>2)] = 4;
4401
- sock.error = null; // Clear the error (The SO_ERROR option obtains and then clears this field).
4402
- return 0;
4403
- }
4404
- }
4405
- return -50; // The option is unknown at the level indicated.
4406
- } catch (e) {
4407
- if (typeof FS == 'undefined' || !(e.name === 'ErrnoError')) throw e;
4408
- return -e.errno;
4409
- }
4410
- }
4411
-
4412
3536
 
4413
3537
  function ___syscall_ioctl(fd, op, varargs) {
4414
3538
  SYSCALLS.varargs = varargs;
@@ -4559,33 +3683,6 @@ async function createWasm() {
4559
3683
  }
4560
3684
  }
4561
3685
 
4562
- function ___syscall_poll(fds, nfds, timeout) {
4563
- try {
4564
-
4565
- var nonzero = 0;
4566
- for (var i = 0; i < nfds; i++) {
4567
- var pollfd = fds + 8 * i;
4568
- var fd = HEAP32[((pollfd)>>2)];
4569
- var events = HEAP16[(((pollfd)+(4))>>1)];
4570
- var mask = 32;
4571
- var stream = FS.getStream(fd);
4572
- if (stream) {
4573
- mask = SYSCALLS.DEFAULT_POLLMASK;
4574
- if (stream.stream_ops.poll) {
4575
- mask = stream.stream_ops.poll(stream, -1);
4576
- }
4577
- }
4578
- mask &= events | 8 | 16;
4579
- if (mask) nonzero++;
4580
- HEAP16[(((pollfd)+(6))>>1)] = mask;
4581
- }
4582
- return nonzero;
4583
- } catch (e) {
4584
- if (typeof FS == 'undefined' || !(e.name === 'ErrnoError')) throw e;
4585
- return -e.errno;
4586
- }
4587
- }
4588
-
4589
3686
 
4590
3687
 
4591
3688
  function ___syscall_readlinkat(dirfd, path, buf, bufsize) {
@@ -4609,21 +3706,6 @@ async function createWasm() {
4609
3706
  }
4610
3707
  }
4611
3708
 
4612
- function ___syscall_renameat(olddirfd, oldpath, newdirfd, newpath) {
4613
- try {
4614
-
4615
- oldpath = SYSCALLS.getStr(oldpath);
4616
- newpath = SYSCALLS.getStr(newpath);
4617
- oldpath = SYSCALLS.calculateAt(olddirfd, oldpath);
4618
- newpath = SYSCALLS.calculateAt(newdirfd, newpath);
4619
- FS.rename(oldpath, newpath);
4620
- return 0;
4621
- } catch (e) {
4622
- if (typeof FS == 'undefined' || !(e.name === 'ErrnoError')) throw e;
4623
- return -e.errno;
4624
- }
4625
- }
4626
-
4627
3709
  function ___syscall_rmdir(path) {
4628
3710
  try {
4629
3711
 
@@ -4636,35 +3718,6 @@ async function createWasm() {
4636
3718
  }
4637
3719
  }
4638
3720
 
4639
-
4640
- function ___syscall_sendto(fd, message, length, flags, addr, addr_len) {
4641
- try {
4642
-
4643
- var sock = getSocketFromFD(fd);
4644
- if (!addr) {
4645
- // send, no address provided
4646
- return FS.write(sock.stream, HEAP8, message, length);
4647
- }
4648
- var dest = getSocketAddress(addr, addr_len);
4649
- // sendto an address
4650
- return sock.sock_ops.sendmsg(sock, HEAP8, message, length, dest.addr, dest.port);
4651
- } catch (e) {
4652
- if (typeof FS == 'undefined' || !(e.name === 'ErrnoError')) throw e;
4653
- return -e.errno;
4654
- }
4655
- }
4656
-
4657
- function ___syscall_socket(domain, type, protocol) {
4658
- try {
4659
-
4660
- var sock = SOCKFS.createSocket(domain, type, protocol);
4661
- return sock.stream.fd;
4662
- } catch (e) {
4663
- if (typeof FS == 'undefined' || !(e.name === 'ErrnoError')) throw e;
4664
- return -e.errno;
4665
- }
4666
- }
4667
-
4668
3721
  function ___syscall_stat64(path, buf) {
4669
3722
  try {
4670
3723
 
@@ -5243,219 +4296,6 @@ async function createWasm() {
5243
4296
  }
5244
4297
  }
5245
4298
 
5246
-
5247
-
5248
-
5249
-
5250
-
5251
-
5252
-
5253
-
5254
-
5255
-
5256
- /** @param {number=} addrlen */
5257
- var writeSockaddr = (sa, family, addr, port, addrlen) => {
5258
- switch (family) {
5259
- case 2:
5260
- addr = inetPton4(addr);
5261
- zeroMemory(sa, 16);
5262
- if (addrlen) {
5263
- HEAP32[((addrlen)>>2)] = 16;
5264
- }
5265
- HEAP16[((sa)>>1)] = family;
5266
- HEAP32[(((sa)+(4))>>2)] = addr;
5267
- HEAP16[(((sa)+(2))>>1)] = _htons(port);
5268
- break;
5269
- case 10:
5270
- addr = inetPton6(addr);
5271
- zeroMemory(sa, 28);
5272
- if (addrlen) {
5273
- HEAP32[((addrlen)>>2)] = 28;
5274
- }
5275
- HEAP32[((sa)>>2)] = family;
5276
- HEAP32[(((sa)+(8))>>2)] = addr[0];
5277
- HEAP32[(((sa)+(12))>>2)] = addr[1];
5278
- HEAP32[(((sa)+(16))>>2)] = addr[2];
5279
- HEAP32[(((sa)+(20))>>2)] = addr[3];
5280
- HEAP16[(((sa)+(2))>>1)] = _htons(port);
5281
- break;
5282
- default:
5283
- return 5;
5284
- }
5285
- return 0;
5286
- };
5287
-
5288
-
5289
-
5290
- var _getaddrinfo = (node, service, hint, out) => {
5291
- // Note getaddrinfo currently only returns a single addrinfo with ai_next defaulting to NULL. When NULL
5292
- // hints are specified or ai_family set to AF_UNSPEC or ai_socktype or ai_protocol set to 0 then we
5293
- // really should provide a linked list of suitable addrinfo values.
5294
- var addrs = [];
5295
- var canon = null;
5296
- var addr = 0;
5297
- var port = 0;
5298
- var flags = 0;
5299
- var family = 0;
5300
- var type = 0;
5301
- var proto = 0;
5302
- var ai, last;
5303
-
5304
- function allocaddrinfo(family, type, proto, canon, addr, port) {
5305
- var sa, salen, ai;
5306
- var errno;
5307
-
5308
- salen = family === 10 ?
5309
- 28 :
5310
- 16;
5311
- addr = family === 10 ?
5312
- inetNtop6(addr) :
5313
- inetNtop4(addr);
5314
- sa = _malloc(salen);
5315
- errno = writeSockaddr(sa, family, addr, port);
5316
- assert(!errno);
5317
-
5318
- ai = _malloc(32);
5319
- HEAP32[(((ai)+(4))>>2)] = family;
5320
- HEAP32[(((ai)+(8))>>2)] = type;
5321
- HEAP32[(((ai)+(12))>>2)] = proto;
5322
- HEAPU32[(((ai)+(24))>>2)] = canon;
5323
- HEAPU32[(((ai)+(20))>>2)] = sa;
5324
- if (family === 10) {
5325
- HEAP32[(((ai)+(16))>>2)] = 28;
5326
- } else {
5327
- HEAP32[(((ai)+(16))>>2)] = 16;
5328
- }
5329
- HEAP32[(((ai)+(28))>>2)] = 0;
5330
-
5331
- return ai;
5332
- }
5333
-
5334
- if (hint) {
5335
- flags = HEAP32[((hint)>>2)];
5336
- family = HEAP32[(((hint)+(4))>>2)];
5337
- type = HEAP32[(((hint)+(8))>>2)];
5338
- proto = HEAP32[(((hint)+(12))>>2)];
5339
- }
5340
- if (type && !proto) {
5341
- proto = type === 2 ? 17 : 6;
5342
- }
5343
- if (!type && proto) {
5344
- type = proto === 17 ? 2 : 1;
5345
- }
5346
-
5347
- // If type or proto are set to zero in hints we should really be returning multiple addrinfo values, but for
5348
- // now default to a TCP STREAM socket so we can at least return a sensible addrinfo given NULL hints.
5349
- if (proto === 0) {
5350
- proto = 6;
5351
- }
5352
- if (type === 0) {
5353
- type = 1;
5354
- }
5355
-
5356
- if (!node && !service) {
5357
- return -2;
5358
- }
5359
- if (flags & ~(1|2|4|
5360
- 1024|8|16|32)) {
5361
- return -1;
5362
- }
5363
- if (hint !== 0 && (HEAP32[((hint)>>2)] & 2) && !node) {
5364
- return -1;
5365
- }
5366
- if (flags & 32) {
5367
- // TODO
5368
- return -2;
5369
- }
5370
- if (type !== 0 && type !== 1 && type !== 2) {
5371
- return -7;
5372
- }
5373
- if (family !== 0 && family !== 2 && family !== 10) {
5374
- return -6;
5375
- }
5376
-
5377
- if (service) {
5378
- service = UTF8ToString(service);
5379
- port = parseInt(service, 10);
5380
-
5381
- if (isNaN(port)) {
5382
- if (flags & 1024) {
5383
- return -2;
5384
- }
5385
- // TODO support resolving well-known service names from:
5386
- // http://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.txt
5387
- return -8;
5388
- }
5389
- }
5390
-
5391
- if (!node) {
5392
- if (family === 0) {
5393
- family = 2;
5394
- }
5395
- if ((flags & 1) === 0) {
5396
- if (family === 2) {
5397
- addr = _htonl(2130706433);
5398
- } else {
5399
- addr = [0, 0, 0, _htonl(1)];
5400
- }
5401
- }
5402
- ai = allocaddrinfo(family, type, proto, null, addr, port);
5403
- HEAPU32[((out)>>2)] = ai;
5404
- return 0;
5405
- }
5406
-
5407
- //
5408
- // try as a numeric address
5409
- //
5410
- node = UTF8ToString(node);
5411
- addr = inetPton4(node);
5412
- if (addr !== null) {
5413
- // incoming node is a valid ipv4 address
5414
- if (family === 0 || family === 2) {
5415
- family = 2;
5416
- }
5417
- else if (family === 10 && (flags & 8)) {
5418
- addr = [0, 0, _htonl(0xffff), addr];
5419
- family = 10;
5420
- } else {
5421
- return -2;
5422
- }
5423
- } else {
5424
- addr = inetPton6(node);
5425
- if (addr !== null) {
5426
- // incoming node is a valid ipv6 address
5427
- if (family === 0 || family === 10) {
5428
- family = 10;
5429
- } else {
5430
- return -2;
5431
- }
5432
- }
5433
- }
5434
- if (addr != null) {
5435
- ai = allocaddrinfo(family, type, proto, node, addr, port);
5436
- HEAPU32[((out)>>2)] = ai;
5437
- return 0;
5438
- }
5439
- if (flags & 4) {
5440
- return -2;
5441
- }
5442
-
5443
- //
5444
- // try as a hostname
5445
- //
5446
- // resolve the hostname to a temporary fake address
5447
- node = DNS.lookup_name(node);
5448
- addr = inetPton4(node);
5449
- if (family === 0) {
5450
- family = 2;
5451
- } else if (family === 10) {
5452
- addr = [0, 0, _htonl(0xffff), addr];
5453
- }
5454
- ai = allocaddrinfo(family, type, proto, null, addr, port);
5455
- HEAPU32[((out)>>2)] = ai;
5456
- return 0;
5457
- };
5458
-
5459
4299
  FS.createPreloadedFile = FS_createPreloadedFile;
5460
4300
  FS.staticInit();
5461
4301
  // Set module methods based on EXPORTED_RUNTIME_METHODS
@@ -5471,8 +4311,6 @@ var wasmImports = {
5471
4311
  /** @export */
5472
4312
  __syscall_chmod: ___syscall_chmod,
5473
4313
  /** @export */
5474
- __syscall_connect: ___syscall_connect,
5475
- /** @export */
5476
4314
  __syscall_faccessat: ___syscall_faccessat,
5477
4315
  /** @export */
5478
4316
  __syscall_fchmod: ___syscall_fchmod,
@@ -5491,8 +4329,6 @@ var wasmImports = {
5491
4329
  /** @export */
5492
4330
  __syscall_getdents64: ___syscall_getdents64,
5493
4331
  /** @export */
5494
- __syscall_getsockopt: ___syscall_getsockopt,
5495
- /** @export */
5496
4332
  __syscall_ioctl: ___syscall_ioctl,
5497
4333
  /** @export */
5498
4334
  __syscall_lstat64: ___syscall_lstat64,
@@ -5503,18 +4339,10 @@ var wasmImports = {
5503
4339
  /** @export */
5504
4340
  __syscall_openat: ___syscall_openat,
5505
4341
  /** @export */
5506
- __syscall_poll: ___syscall_poll,
5507
- /** @export */
5508
4342
  __syscall_readlinkat: ___syscall_readlinkat,
5509
4343
  /** @export */
5510
- __syscall_renameat: ___syscall_renameat,
5511
- /** @export */
5512
4344
  __syscall_rmdir: ___syscall_rmdir,
5513
4345
  /** @export */
5514
- __syscall_sendto: ___syscall_sendto,
5515
- /** @export */
5516
- __syscall_socket: ___syscall_socket,
5517
- /** @export */
5518
4346
  __syscall_stat64: ___syscall_stat64,
5519
4347
  /** @export */
5520
4348
  __syscall_unlinkat: ___syscall_unlinkat,
@@ -5535,6 +4363,12 @@ var wasmImports = {
5535
4363
  /** @export */
5536
4364
  clock_time_get: _clock_time_get,
5537
4365
  /** @export */
4366
+ doltliteWasmHttpRespLen,
4367
+ /** @export */
4368
+ doltliteWasmHttpRespTake,
4369
+ /** @export */
4370
+ doltliteWasmHttpSend,
4371
+ /** @export */
5538
4372
  emscripten_date_now: _emscripten_date_now,
5539
4373
  /** @export */
5540
4374
  emscripten_get_heap_max: _emscripten_get_heap_max,
@@ -5561,8 +4395,6 @@ var wasmImports = {
5561
4395
  /** @export */
5562
4396
  fd_write: _fd_write,
5563
4397
  /** @export */
5564
- getaddrinfo: _getaddrinfo,
5565
- /** @export */
5566
4398
  memory: wasmMemory
5567
4399
  };
5568
4400
  var wasmExports;
@@ -5825,10 +4657,7 @@ var _sqlite3_preupdate_count = Module['_sqlite3_preupdate_count'] = (a0) => (_sq
5825
4657
  var _sqlite3_preupdate_depth = Module['_sqlite3_preupdate_depth'] = (a0) => (_sqlite3_preupdate_depth = Module['_sqlite3_preupdate_depth'] = wasmExports['sqlite3_preupdate_depth'])(a0);
5826
4658
  var _sqlite3_preupdate_blobwrite = Module['_sqlite3_preupdate_blobwrite'] = (a0) => (_sqlite3_preupdate_blobwrite = Module['_sqlite3_preupdate_blobwrite'] = wasmExports['sqlite3_preupdate_blobwrite'])(a0);
5827
4659
  var _sqlite3_preupdate_new = Module['_sqlite3_preupdate_new'] = (a0, a1, a2) => (_sqlite3_preupdate_new = Module['_sqlite3_preupdate_new'] = wasmExports['sqlite3_preupdate_new'])(a0, a1, a2);
5828
- var _htonl = (a0) => (_htonl = wasmExports['htonl'])(a0);
5829
- var _htons = (a0) => (_htons = wasmExports['htons'])(a0);
5830
4660
  var _emscripten_builtin_memalign = (a0, a1) => (_emscripten_builtin_memalign = wasmExports['emscripten_builtin_memalign'])(a0, a1);
5831
- var _ntohs = (a0) => (_ntohs = wasmExports['ntohs'])(a0);
5832
4661
  var __emscripten_stack_restore = (a0) => (__emscripten_stack_restore = wasmExports['_emscripten_stack_restore'])(a0);
5833
4662
  var __emscripten_stack_alloc = (a0) => (__emscripten_stack_alloc = wasmExports['_emscripten_stack_alloc'])(a0);
5834
4663
  var _emscripten_stack_get_current = () => (_emscripten_stack_get_current = wasmExports['emscripten_stack_get_current'])();