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