@mimasu/tdt 3.0.0-beta.1 → 3.0.4
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 +58 -0
- package/README.md +11 -0
- package/dist/index.d.ts +10 -1
- package/dist/index.js +5 -0
- package/dist/wasm/Microsoft.CSharp.wasm +0 -0
- package/dist/wasm/Microsoft.VisualBasic.Core.wasm +0 -0
- package/dist/wasm/Microsoft.VisualBasic.wasm +0 -0
- package/dist/wasm/Microsoft.Win32.Primitives.wasm +0 -0
- package/dist/wasm/Microsoft.Win32.Registry.wasm +0 -0
- package/dist/wasm/System.AppContext.wasm +0 -0
- package/dist/wasm/System.Buffers.wasm +0 -0
- package/dist/wasm/System.Collections.Concurrent.wasm +0 -0
- package/dist/wasm/System.Collections.Immutable.wasm +0 -0
- package/dist/wasm/System.Collections.NonGeneric.wasm +0 -0
- package/dist/wasm/System.Collections.Specialized.wasm +0 -0
- package/dist/wasm/System.Collections.wasm +0 -0
- package/dist/wasm/System.ComponentModel.Annotations.wasm +0 -0
- package/dist/wasm/System.ComponentModel.DataAnnotations.wasm +0 -0
- package/dist/wasm/System.ComponentModel.EventBasedAsync.wasm +0 -0
- package/dist/wasm/System.ComponentModel.Primitives.wasm +0 -0
- package/dist/wasm/System.ComponentModel.TypeConverter.wasm +0 -0
- package/dist/wasm/System.ComponentModel.wasm +0 -0
- package/dist/wasm/System.Configuration.wasm +0 -0
- package/dist/wasm/System.Console.wasm +0 -0
- package/dist/wasm/System.Core.wasm +0 -0
- package/dist/wasm/System.Data.Common.wasm +0 -0
- package/dist/wasm/System.Data.DataSetExtensions.wasm +0 -0
- package/dist/wasm/System.Data.wasm +0 -0
- package/dist/wasm/System.Diagnostics.Contracts.wasm +0 -0
- package/dist/wasm/System.Diagnostics.Debug.wasm +0 -0
- package/dist/wasm/System.Diagnostics.DiagnosticSource.wasm +0 -0
- package/dist/wasm/System.Diagnostics.FileVersionInfo.wasm +0 -0
- package/dist/wasm/System.Diagnostics.Process.wasm +0 -0
- package/dist/wasm/System.Diagnostics.StackTrace.wasm +0 -0
- package/dist/wasm/System.Diagnostics.TextWriterTraceListener.wasm +0 -0
- package/dist/wasm/System.Diagnostics.Tools.wasm +0 -0
- package/dist/wasm/System.Diagnostics.TraceSource.wasm +0 -0
- package/dist/wasm/System.Diagnostics.Tracing.wasm +0 -0
- package/dist/wasm/System.Drawing.Primitives.wasm +0 -0
- package/dist/wasm/System.Drawing.wasm +0 -0
- package/dist/wasm/System.Dynamic.Runtime.wasm +0 -0
- package/dist/wasm/System.Formats.Asn1.wasm +0 -0
- package/dist/wasm/System.Formats.Tar.wasm +0 -0
- package/dist/wasm/System.Globalization.Calendars.wasm +0 -0
- package/dist/wasm/System.Globalization.Extensions.wasm +0 -0
- package/dist/wasm/System.Globalization.wasm +0 -0
- package/dist/wasm/System.IO.Compression.Brotli.wasm +0 -0
- package/dist/wasm/System.IO.Compression.FileSystem.wasm +0 -0
- package/dist/wasm/System.IO.Compression.ZipFile.wasm +0 -0
- package/dist/wasm/System.IO.Compression.wasm +0 -0
- package/dist/wasm/System.IO.FileSystem.AccessControl.wasm +0 -0
- package/dist/wasm/System.IO.FileSystem.DriveInfo.wasm +0 -0
- package/dist/wasm/System.IO.FileSystem.Primitives.wasm +0 -0
- package/dist/wasm/System.IO.FileSystem.Watcher.wasm +0 -0
- package/dist/wasm/System.IO.FileSystem.wasm +0 -0
- package/dist/wasm/System.IO.IsolatedStorage.wasm +0 -0
- package/dist/wasm/System.IO.MemoryMappedFiles.wasm +0 -0
- package/dist/wasm/System.IO.Pipelines.wasm +0 -0
- package/dist/wasm/System.IO.Pipes.AccessControl.wasm +0 -0
- package/dist/wasm/System.IO.Pipes.wasm +0 -0
- package/dist/wasm/System.IO.UnmanagedMemoryStream.wasm +0 -0
- package/dist/wasm/System.IO.wasm +0 -0
- package/dist/wasm/System.Linq.AsyncEnumerable.wasm +0 -0
- package/dist/wasm/System.Linq.Expressions.wasm +0 -0
- package/dist/wasm/System.Linq.Parallel.wasm +0 -0
- package/dist/wasm/System.Linq.Queryable.wasm +0 -0
- package/dist/wasm/System.Linq.wasm +0 -0
- package/dist/wasm/System.Memory.wasm +0 -0
- package/dist/wasm/System.Net.Http.Json.wasm +0 -0
- package/dist/wasm/System.Net.Http.wasm +0 -0
- package/dist/wasm/System.Net.HttpListener.wasm +0 -0
- package/dist/wasm/System.Net.Mail.wasm +0 -0
- package/dist/wasm/System.Net.NameResolution.wasm +0 -0
- package/dist/wasm/System.Net.NetworkInformation.wasm +0 -0
- package/dist/wasm/System.Net.Ping.wasm +0 -0
- package/dist/wasm/System.Net.Primitives.wasm +0 -0
- package/dist/wasm/System.Net.Quic.wasm +0 -0
- package/dist/wasm/System.Net.Requests.wasm +0 -0
- package/dist/wasm/System.Net.Security.wasm +0 -0
- package/dist/wasm/System.Net.ServerSentEvents.wasm +0 -0
- package/dist/wasm/System.Net.ServicePoint.wasm +0 -0
- package/dist/wasm/System.Net.Sockets.wasm +0 -0
- package/dist/wasm/System.Net.WebClient.wasm +0 -0
- package/dist/wasm/System.Net.WebHeaderCollection.wasm +0 -0
- package/dist/wasm/System.Net.WebProxy.wasm +0 -0
- package/dist/wasm/System.Net.WebSockets.Client.wasm +0 -0
- package/dist/wasm/System.Net.WebSockets.wasm +0 -0
- package/dist/wasm/System.Net.wasm +0 -0
- package/dist/wasm/System.Numerics.Vectors.wasm +0 -0
- package/dist/wasm/System.Numerics.wasm +0 -0
- package/dist/wasm/System.ObjectModel.wasm +0 -0
- package/dist/wasm/System.Private.CoreLib.wasm +0 -0
- package/dist/wasm/System.Private.DataContractSerialization.wasm +0 -0
- package/dist/wasm/System.Private.Uri.wasm +0 -0
- package/dist/wasm/System.Private.Xml.Linq.wasm +0 -0
- package/dist/wasm/System.Private.Xml.wasm +0 -0
- package/dist/wasm/System.Reflection.DispatchProxy.wasm +0 -0
- package/dist/wasm/System.Reflection.Emit.ILGeneration.wasm +0 -0
- package/dist/wasm/System.Reflection.Emit.Lightweight.wasm +0 -0
- package/dist/wasm/System.Reflection.Emit.wasm +0 -0
- package/dist/wasm/System.Reflection.Extensions.wasm +0 -0
- package/dist/wasm/System.Reflection.Metadata.wasm +0 -0
- package/dist/wasm/System.Reflection.Primitives.wasm +0 -0
- package/dist/wasm/System.Reflection.TypeExtensions.wasm +0 -0
- package/dist/wasm/System.Reflection.wasm +0 -0
- package/dist/wasm/System.Resources.Reader.wasm +0 -0
- package/dist/wasm/System.Resources.ResourceManager.wasm +0 -0
- package/dist/wasm/System.Resources.Writer.wasm +0 -0
- package/dist/wasm/System.Runtime.CompilerServices.Unsafe.wasm +0 -0
- package/dist/wasm/System.Runtime.CompilerServices.VisualC.wasm +0 -0
- package/dist/wasm/System.Runtime.Extensions.wasm +0 -0
- package/dist/wasm/System.Runtime.Handles.wasm +0 -0
- package/dist/wasm/System.Runtime.InteropServices.JavaScript.wasm +0 -0
- package/dist/wasm/System.Runtime.InteropServices.RuntimeInformation.wasm +0 -0
- package/dist/wasm/System.Runtime.InteropServices.wasm +0 -0
- package/dist/wasm/System.Runtime.Intrinsics.wasm +0 -0
- package/dist/wasm/System.Runtime.Loader.wasm +0 -0
- package/dist/wasm/System.Runtime.Numerics.wasm +0 -0
- package/dist/wasm/System.Runtime.Serialization.Formatters.wasm +0 -0
- package/dist/wasm/System.Runtime.Serialization.Json.wasm +0 -0
- package/dist/wasm/System.Runtime.Serialization.Primitives.wasm +0 -0
- package/dist/wasm/System.Runtime.Serialization.Xml.wasm +0 -0
- package/dist/wasm/System.Runtime.Serialization.wasm +0 -0
- package/dist/wasm/System.Runtime.wasm +0 -0
- package/dist/wasm/System.Security.AccessControl.wasm +0 -0
- package/dist/wasm/System.Security.Claims.wasm +0 -0
- package/dist/wasm/System.Security.Cryptography.Algorithms.wasm +0 -0
- package/dist/wasm/System.Security.Cryptography.Cng.wasm +0 -0
- package/dist/wasm/System.Security.Cryptography.Csp.wasm +0 -0
- package/dist/wasm/System.Security.Cryptography.Encoding.wasm +0 -0
- package/dist/wasm/System.Security.Cryptography.OpenSsl.wasm +0 -0
- package/dist/wasm/System.Security.Cryptography.Primitives.wasm +0 -0
- package/dist/wasm/System.Security.Cryptography.X509Certificates.wasm +0 -0
- package/dist/wasm/System.Security.Cryptography.wasm +0 -0
- package/dist/wasm/System.Security.Principal.Windows.wasm +0 -0
- package/dist/wasm/System.Security.Principal.wasm +0 -0
- package/dist/wasm/System.Security.SecureString.wasm +0 -0
- package/dist/wasm/System.Security.wasm +0 -0
- package/dist/wasm/System.ServiceModel.Web.wasm +0 -0
- package/dist/wasm/System.ServiceProcess.wasm +0 -0
- package/dist/wasm/System.Text.Encoding.CodePages.wasm +0 -0
- package/dist/wasm/System.Text.Encoding.Extensions.wasm +0 -0
- package/dist/wasm/System.Text.Encoding.wasm +0 -0
- package/dist/wasm/System.Text.Encodings.Web.wasm +0 -0
- package/dist/wasm/System.Text.Json.wasm +0 -0
- package/dist/wasm/System.Text.RegularExpressions.wasm +0 -0
- package/dist/wasm/System.Threading.AccessControl.wasm +0 -0
- package/dist/wasm/System.Threading.Channels.wasm +0 -0
- package/dist/wasm/System.Threading.Overlapped.wasm +0 -0
- package/dist/wasm/System.Threading.Tasks.Dataflow.wasm +0 -0
- package/dist/wasm/System.Threading.Tasks.Extensions.wasm +0 -0
- package/dist/wasm/System.Threading.Tasks.Parallel.wasm +0 -0
- package/dist/wasm/System.Threading.Tasks.wasm +0 -0
- package/dist/wasm/System.Threading.Thread.wasm +0 -0
- package/dist/wasm/System.Threading.ThreadPool.wasm +0 -0
- package/dist/wasm/System.Threading.Timer.wasm +0 -0
- package/dist/wasm/System.Threading.wasm +0 -0
- package/dist/wasm/System.Transactions.Local.wasm +0 -0
- package/dist/wasm/System.Transactions.wasm +0 -0
- package/dist/wasm/System.ValueTuple.wasm +0 -0
- package/dist/wasm/System.Web.HttpUtility.wasm +0 -0
- package/dist/wasm/System.Web.wasm +0 -0
- package/dist/wasm/System.Windows.wasm +0 -0
- package/dist/wasm/System.Xml.Linq.wasm +0 -0
- package/dist/wasm/System.Xml.ReaderWriter.wasm +0 -0
- package/dist/wasm/System.Xml.Serialization.wasm +0 -0
- package/dist/wasm/System.Xml.XDocument.wasm +0 -0
- package/dist/wasm/System.Xml.XPath.XDocument.wasm +0 -0
- package/dist/wasm/System.Xml.XPath.wasm +0 -0
- package/dist/wasm/System.Xml.XmlDocument.wasm +0 -0
- package/dist/wasm/System.Xml.XmlSerializer.wasm +0 -0
- package/dist/wasm/System.Xml.wasm +0 -0
- package/dist/wasm/System.wasm +0 -0
- package/dist/wasm/TagDataTranslation.Wasm.wasm +0 -0
- package/dist/wasm/TagDataTranslation.wasm +0 -0
- package/dist/wasm/WindowsBase.wasm +0 -0
- package/dist/wasm/dotnet.boot.js +753 -47
- package/dist/wasm/dotnet.native.js +1168 -4
- package/dist/wasm/dotnet.native.js.symbols +12704 -5430
- package/dist/wasm/dotnet.native.wasm +0 -0
- package/dist/wasm/mscorlib.wasm +0 -0
- package/dist/wasm/netstandard.wasm +0 -0
- package/package.json +11 -4
- package/dist/wasm/dotnet.js.map +0 -1
- package/dist/wasm/dotnet.runtime.js.map +0 -1
|
@@ -30,11 +30,11 @@ Module['ready'] = new Promise((resolve, reject) => {
|
|
|
30
30
|
|
|
31
31
|
// --pre-jses are emitted after the Module integration code, so that they can
|
|
32
32
|
// refer to Module (if they choose; they can also define Module)
|
|
33
|
-
// include: /usr/
|
|
33
|
+
// include: /usr/share/dotnet/packs/Microsoft.NETCore.App.Runtime.Mono.browser-wasm/10.0.3/runtimes/browser-wasm/native/src/es6/dotnet.es6.pre.js
|
|
34
34
|
if (_nativeModuleLoaded) throw new Error("Native module already loaded");
|
|
35
35
|
_nativeModuleLoaded = true;
|
|
36
36
|
createDotnetRuntime = Module = moduleArg(Module);
|
|
37
|
-
// end include: /usr/
|
|
37
|
+
// end include: /usr/share/dotnet/packs/Microsoft.NETCore.App.Runtime.Mono.browser-wasm/10.0.3/runtimes/browser-wasm/native/src/es6/dotnet.es6.pre.js
|
|
38
38
|
|
|
39
39
|
|
|
40
40
|
// Sometimes an existing Module object exists with properties
|
|
@@ -488,6 +488,7 @@ if (!Module['noFSInit'] && !FS.init.initialized)
|
|
|
488
488
|
FS.ignorePermissions = false;
|
|
489
489
|
|
|
490
490
|
TTY.init();
|
|
491
|
+
SOCKFS.root = FS.mount(SOCKFS, {}, null);
|
|
491
492
|
callRuntimeCallbacks(__ATINIT__);
|
|
492
493
|
}
|
|
493
494
|
|
|
@@ -3446,6 +3447,952 @@ function createWasm() {
|
|
|
3446
3447
|
return stream;
|
|
3447
3448
|
},
|
|
3448
3449
|
};
|
|
3450
|
+
function ___syscall_chdir(path) {
|
|
3451
|
+
try {
|
|
3452
|
+
|
|
3453
|
+
path = SYSCALLS.getStr(path);
|
|
3454
|
+
FS.chdir(path);
|
|
3455
|
+
return 0;
|
|
3456
|
+
} catch (e) {
|
|
3457
|
+
if (typeof FS == 'undefined' || !(e.name === 'ErrnoError')) throw e;
|
|
3458
|
+
return -e.errno;
|
|
3459
|
+
}
|
|
3460
|
+
}
|
|
3461
|
+
|
|
3462
|
+
function ___syscall_chmod(path, mode) {
|
|
3463
|
+
try {
|
|
3464
|
+
|
|
3465
|
+
path = SYSCALLS.getStr(path);
|
|
3466
|
+
FS.chmod(path, mode);
|
|
3467
|
+
return 0;
|
|
3468
|
+
} catch (e) {
|
|
3469
|
+
if (typeof FS == 'undefined' || !(e.name === 'ErrnoError')) throw e;
|
|
3470
|
+
return -e.errno;
|
|
3471
|
+
}
|
|
3472
|
+
}
|
|
3473
|
+
|
|
3474
|
+
var SOCKFS = {
|
|
3475
|
+
mount(mount) {
|
|
3476
|
+
// If Module['websocket'] has already been defined (e.g. for configuring
|
|
3477
|
+
// the subprotocol/url) use that, if not initialise it to a new object.
|
|
3478
|
+
Module['websocket'] = (Module['websocket'] &&
|
|
3479
|
+
('object' === typeof Module['websocket'])) ? Module['websocket'] : {};
|
|
3480
|
+
|
|
3481
|
+
// Add the Event registration mechanism to the exported websocket configuration
|
|
3482
|
+
// object so we can register network callbacks from native JavaScript too.
|
|
3483
|
+
// For more documentation see system/include/emscripten/emscripten.h
|
|
3484
|
+
Module['websocket']._callbacks = {};
|
|
3485
|
+
Module['websocket']['on'] = /** @this{Object} */ function(event, callback) {
|
|
3486
|
+
if ('function' === typeof callback) {
|
|
3487
|
+
this._callbacks[event] = callback;
|
|
3488
|
+
}
|
|
3489
|
+
return this;
|
|
3490
|
+
};
|
|
3491
|
+
|
|
3492
|
+
Module['websocket'].emit = /** @this{Object} */ function(event, param) {
|
|
3493
|
+
if ('function' === typeof this._callbacks[event]) {
|
|
3494
|
+
this._callbacks[event].call(this, param);
|
|
3495
|
+
}
|
|
3496
|
+
};
|
|
3497
|
+
|
|
3498
|
+
// If debug is enabled register simple default logging callbacks for each Event.
|
|
3499
|
+
|
|
3500
|
+
return FS.createNode(null, '/', 16384 | 511 /* 0777 */, 0);
|
|
3501
|
+
},
|
|
3502
|
+
createSocket(family, type, protocol) {
|
|
3503
|
+
type &= ~526336; // Some applications may pass it; it makes no sense for a single process.
|
|
3504
|
+
var streaming = type == 1;
|
|
3505
|
+
if (streaming && protocol && protocol != 6) {
|
|
3506
|
+
throw new FS.ErrnoError(66); // if SOCK_STREAM, must be tcp or 0.
|
|
3507
|
+
}
|
|
3508
|
+
|
|
3509
|
+
// create our internal socket structure
|
|
3510
|
+
var sock = {
|
|
3511
|
+
family,
|
|
3512
|
+
type,
|
|
3513
|
+
protocol,
|
|
3514
|
+
server: null,
|
|
3515
|
+
error: null, // Used in getsockopt for SOL_SOCKET/SO_ERROR test
|
|
3516
|
+
peers: {},
|
|
3517
|
+
pending: [],
|
|
3518
|
+
recv_queue: [],
|
|
3519
|
+
sock_ops: SOCKFS.websocket_sock_ops
|
|
3520
|
+
};
|
|
3521
|
+
|
|
3522
|
+
// create the filesystem node to store the socket structure
|
|
3523
|
+
var name = SOCKFS.nextname();
|
|
3524
|
+
var node = FS.createNode(SOCKFS.root, name, 49152, 0);
|
|
3525
|
+
node.sock = sock;
|
|
3526
|
+
|
|
3527
|
+
// and the wrapping stream that enables library functions such
|
|
3528
|
+
// as read and write to indirectly interact with the socket
|
|
3529
|
+
var stream = FS.createStream({
|
|
3530
|
+
path: name,
|
|
3531
|
+
node,
|
|
3532
|
+
flags: 2,
|
|
3533
|
+
seekable: false,
|
|
3534
|
+
stream_ops: SOCKFS.stream_ops
|
|
3535
|
+
});
|
|
3536
|
+
|
|
3537
|
+
// map the new stream to the socket structure (sockets have a 1:1
|
|
3538
|
+
// relationship with a stream)
|
|
3539
|
+
sock.stream = stream;
|
|
3540
|
+
|
|
3541
|
+
return sock;
|
|
3542
|
+
},
|
|
3543
|
+
getSocket(fd) {
|
|
3544
|
+
var stream = FS.getStream(fd);
|
|
3545
|
+
if (!stream || !FS.isSocket(stream.node.mode)) {
|
|
3546
|
+
return null;
|
|
3547
|
+
}
|
|
3548
|
+
return stream.node.sock;
|
|
3549
|
+
},
|
|
3550
|
+
stream_ops:{
|
|
3551
|
+
poll(stream) {
|
|
3552
|
+
var sock = stream.node.sock;
|
|
3553
|
+
return sock.sock_ops.poll(sock);
|
|
3554
|
+
},
|
|
3555
|
+
ioctl(stream, request, varargs) {
|
|
3556
|
+
var sock = stream.node.sock;
|
|
3557
|
+
return sock.sock_ops.ioctl(sock, request, varargs);
|
|
3558
|
+
},
|
|
3559
|
+
read(stream, buffer, offset, length, position /* ignored */) {
|
|
3560
|
+
var sock = stream.node.sock;
|
|
3561
|
+
var msg = sock.sock_ops.recvmsg(sock, length);
|
|
3562
|
+
if (!msg) {
|
|
3563
|
+
// socket is closed
|
|
3564
|
+
return 0;
|
|
3565
|
+
}
|
|
3566
|
+
buffer.set(msg.buffer, offset);
|
|
3567
|
+
return msg.buffer.length;
|
|
3568
|
+
},
|
|
3569
|
+
write(stream, buffer, offset, length, position /* ignored */) {
|
|
3570
|
+
var sock = stream.node.sock;
|
|
3571
|
+
return sock.sock_ops.sendmsg(sock, buffer, offset, length);
|
|
3572
|
+
},
|
|
3573
|
+
close(stream) {
|
|
3574
|
+
var sock = stream.node.sock;
|
|
3575
|
+
sock.sock_ops.close(sock);
|
|
3576
|
+
},
|
|
3577
|
+
},
|
|
3578
|
+
nextname() {
|
|
3579
|
+
if (!SOCKFS.nextname.current) {
|
|
3580
|
+
SOCKFS.nextname.current = 0;
|
|
3581
|
+
}
|
|
3582
|
+
return 'socket[' + (SOCKFS.nextname.current++) + ']';
|
|
3583
|
+
},
|
|
3584
|
+
websocket_sock_ops:{
|
|
3585
|
+
createPeer(sock, addr, port) {
|
|
3586
|
+
var ws;
|
|
3587
|
+
|
|
3588
|
+
if (typeof addr == 'object') {
|
|
3589
|
+
ws = addr;
|
|
3590
|
+
addr = null;
|
|
3591
|
+
port = null;
|
|
3592
|
+
}
|
|
3593
|
+
|
|
3594
|
+
if (ws) {
|
|
3595
|
+
// for sockets that've already connected (e.g. we're the server)
|
|
3596
|
+
// we can inspect the _socket property for the address
|
|
3597
|
+
if (ws._socket) {
|
|
3598
|
+
addr = ws._socket.remoteAddress;
|
|
3599
|
+
port = ws._socket.remotePort;
|
|
3600
|
+
}
|
|
3601
|
+
// if we're just now initializing a connection to the remote,
|
|
3602
|
+
// inspect the url property
|
|
3603
|
+
else {
|
|
3604
|
+
var result = /ws[s]?:\/\/([^:]+):(\d+)/.exec(ws.url);
|
|
3605
|
+
if (!result) {
|
|
3606
|
+
throw new Error('WebSocket URL must be in the format ws(s)://address:port');
|
|
3607
|
+
}
|
|
3608
|
+
addr = result[1];
|
|
3609
|
+
port = parseInt(result[2], 10);
|
|
3610
|
+
}
|
|
3611
|
+
} else {
|
|
3612
|
+
// create the actual websocket object and connect
|
|
3613
|
+
try {
|
|
3614
|
+
// runtimeConfig gets set to true if WebSocket runtime configuration is available.
|
|
3615
|
+
var runtimeConfig = (Module['websocket'] && ('object' === typeof Module['websocket']));
|
|
3616
|
+
|
|
3617
|
+
// The default value is 'ws://' the replace is needed because the compiler replaces '//' comments with '#'
|
|
3618
|
+
// comments without checking context, so we'd end up with ws:#, the replace swaps the '#' for '//' again.
|
|
3619
|
+
var url = 'ws:#'.replace('#', '//');
|
|
3620
|
+
|
|
3621
|
+
if (runtimeConfig) {
|
|
3622
|
+
if ('string' === typeof Module['websocket']['url']) {
|
|
3623
|
+
url = Module['websocket']['url']; // Fetch runtime WebSocket URL config.
|
|
3624
|
+
}
|
|
3625
|
+
}
|
|
3626
|
+
|
|
3627
|
+
if (url === 'ws://' || url === 'wss://') { // Is the supplied URL config just a prefix, if so complete it.
|
|
3628
|
+
var parts = addr.split('/');
|
|
3629
|
+
url = url + parts[0] + ":" + port + "/" + parts.slice(1).join('/');
|
|
3630
|
+
}
|
|
3631
|
+
|
|
3632
|
+
// Make the WebSocket subprotocol (Sec-WebSocket-Protocol) default to binary if no configuration is set.
|
|
3633
|
+
var subProtocols = 'binary'; // The default value is 'binary'
|
|
3634
|
+
|
|
3635
|
+
if (runtimeConfig) {
|
|
3636
|
+
if ('string' === typeof Module['websocket']['subprotocol']) {
|
|
3637
|
+
subProtocols = Module['websocket']['subprotocol']; // Fetch runtime WebSocket subprotocol config.
|
|
3638
|
+
}
|
|
3639
|
+
}
|
|
3640
|
+
|
|
3641
|
+
// The default WebSocket options
|
|
3642
|
+
var opts = undefined;
|
|
3643
|
+
|
|
3644
|
+
if (subProtocols !== 'null') {
|
|
3645
|
+
// The regex trims the string (removes spaces at the beginning and end, then splits the string by
|
|
3646
|
+
// <any space>,<any space> into an Array. Whitespace removal is important for Websockify and ws.
|
|
3647
|
+
subProtocols = subProtocols.replace(/^ +| +$/g,"").split(/ *, */);
|
|
3648
|
+
|
|
3649
|
+
opts = subProtocols;
|
|
3650
|
+
}
|
|
3651
|
+
|
|
3652
|
+
// some webservers (azure) does not support subprotocol header
|
|
3653
|
+
if (runtimeConfig && null === Module['websocket']['subprotocol']) {
|
|
3654
|
+
subProtocols = 'null';
|
|
3655
|
+
opts = undefined;
|
|
3656
|
+
}
|
|
3657
|
+
|
|
3658
|
+
// If node we use the ws library.
|
|
3659
|
+
var WebSocketConstructor;
|
|
3660
|
+
if (ENVIRONMENT_IS_NODE) {
|
|
3661
|
+
WebSocketConstructor = /** @type{(typeof WebSocket)} */(require('ws'));
|
|
3662
|
+
} else
|
|
3663
|
+
{
|
|
3664
|
+
WebSocketConstructor = WebSocket;
|
|
3665
|
+
}
|
|
3666
|
+
ws = new WebSocketConstructor(url, opts);
|
|
3667
|
+
ws.binaryType = 'arraybuffer';
|
|
3668
|
+
} catch (e) {
|
|
3669
|
+
throw new FS.ErrnoError(23);
|
|
3670
|
+
}
|
|
3671
|
+
}
|
|
3672
|
+
|
|
3673
|
+
var peer = {
|
|
3674
|
+
addr,
|
|
3675
|
+
port,
|
|
3676
|
+
socket: ws,
|
|
3677
|
+
dgram_send_queue: []
|
|
3678
|
+
};
|
|
3679
|
+
|
|
3680
|
+
SOCKFS.websocket_sock_ops.addPeer(sock, peer);
|
|
3681
|
+
SOCKFS.websocket_sock_ops.handlePeerEvents(sock, peer);
|
|
3682
|
+
|
|
3683
|
+
// if this is a bound dgram socket, send the port number first to allow
|
|
3684
|
+
// us to override the ephemeral port reported to us by remotePort on the
|
|
3685
|
+
// remote end.
|
|
3686
|
+
if (sock.type === 2 && typeof sock.sport != 'undefined') {
|
|
3687
|
+
peer.dgram_send_queue.push(new Uint8Array([
|
|
3688
|
+
255, 255, 255, 255,
|
|
3689
|
+
'p'.charCodeAt(0), 'o'.charCodeAt(0), 'r'.charCodeAt(0), 't'.charCodeAt(0),
|
|
3690
|
+
((sock.sport & 0xff00) >> 8) , (sock.sport & 0xff)
|
|
3691
|
+
]));
|
|
3692
|
+
}
|
|
3693
|
+
|
|
3694
|
+
return peer;
|
|
3695
|
+
},
|
|
3696
|
+
getPeer(sock, addr, port) {
|
|
3697
|
+
return sock.peers[addr + ':' + port];
|
|
3698
|
+
},
|
|
3699
|
+
addPeer(sock, peer) {
|
|
3700
|
+
sock.peers[peer.addr + ':' + peer.port] = peer;
|
|
3701
|
+
},
|
|
3702
|
+
removePeer(sock, peer) {
|
|
3703
|
+
delete sock.peers[peer.addr + ':' + peer.port];
|
|
3704
|
+
},
|
|
3705
|
+
handlePeerEvents(sock, peer) {
|
|
3706
|
+
var first = true;
|
|
3707
|
+
|
|
3708
|
+
var handleOpen = function () {
|
|
3709
|
+
|
|
3710
|
+
Module['websocket'].emit('open', sock.stream.fd);
|
|
3711
|
+
|
|
3712
|
+
try {
|
|
3713
|
+
var queued = peer.dgram_send_queue.shift();
|
|
3714
|
+
while (queued) {
|
|
3715
|
+
peer.socket.send(queued);
|
|
3716
|
+
queued = peer.dgram_send_queue.shift();
|
|
3717
|
+
}
|
|
3718
|
+
} catch (e) {
|
|
3719
|
+
// not much we can do here in the way of proper error handling as we've already
|
|
3720
|
+
// lied and said this data was sent. shut it down.
|
|
3721
|
+
peer.socket.close();
|
|
3722
|
+
}
|
|
3723
|
+
};
|
|
3724
|
+
|
|
3725
|
+
function handleMessage(data) {
|
|
3726
|
+
if (typeof data == 'string') {
|
|
3727
|
+
var encoder = new TextEncoder(); // should be utf-8
|
|
3728
|
+
data = encoder.encode(data); // make a typed array from the string
|
|
3729
|
+
} else {
|
|
3730
|
+
assert(data.byteLength !== undefined); // must receive an ArrayBuffer
|
|
3731
|
+
if (data.byteLength == 0) {
|
|
3732
|
+
// An empty ArrayBuffer will emit a pseudo disconnect event
|
|
3733
|
+
// as recv/recvmsg will return zero which indicates that a socket
|
|
3734
|
+
// has performed a shutdown although the connection has not been disconnected yet.
|
|
3735
|
+
return;
|
|
3736
|
+
}
|
|
3737
|
+
data = new Uint8Array(data); // make a typed array view on the array buffer
|
|
3738
|
+
}
|
|
3739
|
+
|
|
3740
|
+
// if this is the port message, override the peer's port with it
|
|
3741
|
+
var wasfirst = first;
|
|
3742
|
+
first = false;
|
|
3743
|
+
if (wasfirst &&
|
|
3744
|
+
data.length === 10 &&
|
|
3745
|
+
data[0] === 255 && data[1] === 255 && data[2] === 255 && data[3] === 255 &&
|
|
3746
|
+
data[4] === 'p'.charCodeAt(0) && data[5] === 'o'.charCodeAt(0) && data[6] === 'r'.charCodeAt(0) && data[7] === 't'.charCodeAt(0)) {
|
|
3747
|
+
// update the peer's port and it's key in the peer map
|
|
3748
|
+
var newport = ((data[8] << 8) | data[9]);
|
|
3749
|
+
SOCKFS.websocket_sock_ops.removePeer(sock, peer);
|
|
3750
|
+
peer.port = newport;
|
|
3751
|
+
SOCKFS.websocket_sock_ops.addPeer(sock, peer);
|
|
3752
|
+
return;
|
|
3753
|
+
}
|
|
3754
|
+
|
|
3755
|
+
sock.recv_queue.push({ addr: peer.addr, port: peer.port, data: data });
|
|
3756
|
+
Module['websocket'].emit('message', sock.stream.fd);
|
|
3757
|
+
};
|
|
3758
|
+
|
|
3759
|
+
if (ENVIRONMENT_IS_NODE) {
|
|
3760
|
+
peer.socket.on('open', handleOpen);
|
|
3761
|
+
peer.socket.on('message', function(data, isBinary) {
|
|
3762
|
+
if (!isBinary) {
|
|
3763
|
+
return;
|
|
3764
|
+
}
|
|
3765
|
+
handleMessage((new Uint8Array(data)).buffer); // copy from node Buffer -> ArrayBuffer
|
|
3766
|
+
});
|
|
3767
|
+
peer.socket.on('close', function() {
|
|
3768
|
+
Module['websocket'].emit('close', sock.stream.fd);
|
|
3769
|
+
});
|
|
3770
|
+
peer.socket.on('error', function(error) {
|
|
3771
|
+
// Although the ws library may pass errors that may be more descriptive than
|
|
3772
|
+
// ECONNREFUSED they are not necessarily the expected error code e.g.
|
|
3773
|
+
// ENOTFOUND on getaddrinfo seems to be node.js specific, so using ECONNREFUSED
|
|
3774
|
+
// is still probably the most useful thing to do.
|
|
3775
|
+
sock.error = 14; // Used in getsockopt for SOL_SOCKET/SO_ERROR test.
|
|
3776
|
+
Module['websocket'].emit('error', [sock.stream.fd, sock.error, 'ECONNREFUSED: Connection refused']);
|
|
3777
|
+
// don't throw
|
|
3778
|
+
});
|
|
3779
|
+
} else {
|
|
3780
|
+
peer.socket.onopen = handleOpen;
|
|
3781
|
+
peer.socket.onclose = function() {
|
|
3782
|
+
Module['websocket'].emit('close', sock.stream.fd);
|
|
3783
|
+
};
|
|
3784
|
+
peer.socket.onmessage = function peer_socket_onmessage(event) {
|
|
3785
|
+
handleMessage(event.data);
|
|
3786
|
+
};
|
|
3787
|
+
peer.socket.onerror = function(error) {
|
|
3788
|
+
// The WebSocket spec only allows a 'simple event' to be thrown on error,
|
|
3789
|
+
// so we only really know as much as ECONNREFUSED.
|
|
3790
|
+
sock.error = 14; // Used in getsockopt for SOL_SOCKET/SO_ERROR test.
|
|
3791
|
+
Module['websocket'].emit('error', [sock.stream.fd, sock.error, 'ECONNREFUSED: Connection refused']);
|
|
3792
|
+
};
|
|
3793
|
+
}
|
|
3794
|
+
},
|
|
3795
|
+
poll(sock) {
|
|
3796
|
+
if (sock.type === 1 && sock.server) {
|
|
3797
|
+
// listen sockets should only say they're available for reading
|
|
3798
|
+
// if there are pending clients.
|
|
3799
|
+
return sock.pending.length ? (64 | 1) : 0;
|
|
3800
|
+
}
|
|
3801
|
+
|
|
3802
|
+
var mask = 0;
|
|
3803
|
+
var dest = sock.type === 1 ? // we only care about the socket state for connection-based sockets
|
|
3804
|
+
SOCKFS.websocket_sock_ops.getPeer(sock, sock.daddr, sock.dport) :
|
|
3805
|
+
null;
|
|
3806
|
+
|
|
3807
|
+
if (sock.recv_queue.length ||
|
|
3808
|
+
!dest || // connection-less sockets are always ready to read
|
|
3809
|
+
(dest && dest.socket.readyState === dest.socket.CLOSING) ||
|
|
3810
|
+
(dest && dest.socket.readyState === dest.socket.CLOSED)) { // let recv return 0 once closed
|
|
3811
|
+
mask |= (64 | 1);
|
|
3812
|
+
}
|
|
3813
|
+
|
|
3814
|
+
if (!dest || // connection-less sockets are always ready to write
|
|
3815
|
+
(dest && dest.socket.readyState === dest.socket.OPEN)) {
|
|
3816
|
+
mask |= 4;
|
|
3817
|
+
}
|
|
3818
|
+
|
|
3819
|
+
if ((dest && dest.socket.readyState === dest.socket.CLOSING) ||
|
|
3820
|
+
(dest && dest.socket.readyState === dest.socket.CLOSED)) {
|
|
3821
|
+
mask |= 16;
|
|
3822
|
+
}
|
|
3823
|
+
|
|
3824
|
+
return mask;
|
|
3825
|
+
},
|
|
3826
|
+
ioctl(sock, request, arg) {
|
|
3827
|
+
switch (request) {
|
|
3828
|
+
case 21531:
|
|
3829
|
+
var bytes = 0;
|
|
3830
|
+
if (sock.recv_queue.length) {
|
|
3831
|
+
bytes = sock.recv_queue[0].data.length;
|
|
3832
|
+
}
|
|
3833
|
+
HEAP32[((arg)>>2)] = bytes;
|
|
3834
|
+
return 0;
|
|
3835
|
+
default:
|
|
3836
|
+
return 28;
|
|
3837
|
+
}
|
|
3838
|
+
},
|
|
3839
|
+
close(sock) {
|
|
3840
|
+
// if we've spawned a listen server, close it
|
|
3841
|
+
if (sock.server) {
|
|
3842
|
+
try {
|
|
3843
|
+
sock.server.close();
|
|
3844
|
+
} catch (e) {
|
|
3845
|
+
}
|
|
3846
|
+
sock.server = null;
|
|
3847
|
+
}
|
|
3848
|
+
// close any peer connections
|
|
3849
|
+
var peers = Object.keys(sock.peers);
|
|
3850
|
+
for (var i = 0; i < peers.length; i++) {
|
|
3851
|
+
var peer = sock.peers[peers[i]];
|
|
3852
|
+
try {
|
|
3853
|
+
peer.socket.close();
|
|
3854
|
+
} catch (e) {
|
|
3855
|
+
}
|
|
3856
|
+
SOCKFS.websocket_sock_ops.removePeer(sock, peer);
|
|
3857
|
+
}
|
|
3858
|
+
return 0;
|
|
3859
|
+
},
|
|
3860
|
+
bind(sock, addr, port) {
|
|
3861
|
+
if (typeof sock.saddr != 'undefined' || typeof sock.sport != 'undefined') {
|
|
3862
|
+
throw new FS.ErrnoError(28); // already bound
|
|
3863
|
+
}
|
|
3864
|
+
sock.saddr = addr;
|
|
3865
|
+
sock.sport = port;
|
|
3866
|
+
// in order to emulate dgram sockets, we need to launch a listen server when
|
|
3867
|
+
// binding on a connection-less socket
|
|
3868
|
+
// note: this is only required on the server side
|
|
3869
|
+
if (sock.type === 2) {
|
|
3870
|
+
// close the existing server if it exists
|
|
3871
|
+
if (sock.server) {
|
|
3872
|
+
sock.server.close();
|
|
3873
|
+
sock.server = null;
|
|
3874
|
+
}
|
|
3875
|
+
// swallow error operation not supported error that occurs when binding in the
|
|
3876
|
+
// browser where this isn't supported
|
|
3877
|
+
try {
|
|
3878
|
+
sock.sock_ops.listen(sock, 0);
|
|
3879
|
+
} catch (e) {
|
|
3880
|
+
if (!(e.name === 'ErrnoError')) throw e;
|
|
3881
|
+
if (e.errno !== 138) throw e;
|
|
3882
|
+
}
|
|
3883
|
+
}
|
|
3884
|
+
},
|
|
3885
|
+
connect(sock, addr, port) {
|
|
3886
|
+
if (sock.server) {
|
|
3887
|
+
throw new FS.ErrnoError(138);
|
|
3888
|
+
}
|
|
3889
|
+
|
|
3890
|
+
// TODO autobind
|
|
3891
|
+
// if (!sock.addr && sock.type == 2) {
|
|
3892
|
+
// }
|
|
3893
|
+
|
|
3894
|
+
// early out if we're already connected / in the middle of connecting
|
|
3895
|
+
if (typeof sock.daddr != 'undefined' && typeof sock.dport != 'undefined') {
|
|
3896
|
+
var dest = SOCKFS.websocket_sock_ops.getPeer(sock, sock.daddr, sock.dport);
|
|
3897
|
+
if (dest) {
|
|
3898
|
+
if (dest.socket.readyState === dest.socket.CONNECTING) {
|
|
3899
|
+
throw new FS.ErrnoError(7);
|
|
3900
|
+
} else {
|
|
3901
|
+
throw new FS.ErrnoError(30);
|
|
3902
|
+
}
|
|
3903
|
+
}
|
|
3904
|
+
}
|
|
3905
|
+
|
|
3906
|
+
// add the socket to our peer list and set our
|
|
3907
|
+
// destination address / port to match
|
|
3908
|
+
var peer = SOCKFS.websocket_sock_ops.createPeer(sock, addr, port);
|
|
3909
|
+
sock.daddr = peer.addr;
|
|
3910
|
+
sock.dport = peer.port;
|
|
3911
|
+
|
|
3912
|
+
// always "fail" in non-blocking mode
|
|
3913
|
+
throw new FS.ErrnoError(26);
|
|
3914
|
+
},
|
|
3915
|
+
listen(sock, backlog) {
|
|
3916
|
+
if (!ENVIRONMENT_IS_NODE) {
|
|
3917
|
+
throw new FS.ErrnoError(138);
|
|
3918
|
+
}
|
|
3919
|
+
if (sock.server) {
|
|
3920
|
+
throw new FS.ErrnoError(28); // already listening
|
|
3921
|
+
}
|
|
3922
|
+
var WebSocketServer = require('ws').Server;
|
|
3923
|
+
var host = sock.saddr;
|
|
3924
|
+
sock.server = new WebSocketServer({
|
|
3925
|
+
host,
|
|
3926
|
+
port: sock.sport
|
|
3927
|
+
// TODO support backlog
|
|
3928
|
+
});
|
|
3929
|
+
Module['websocket'].emit('listen', sock.stream.fd); // Send Event with listen fd.
|
|
3930
|
+
|
|
3931
|
+
sock.server.on('connection', function(ws) {
|
|
3932
|
+
if (sock.type === 1) {
|
|
3933
|
+
var newsock = SOCKFS.createSocket(sock.family, sock.type, sock.protocol);
|
|
3934
|
+
|
|
3935
|
+
// create a peer on the new socket
|
|
3936
|
+
var peer = SOCKFS.websocket_sock_ops.createPeer(newsock, ws);
|
|
3937
|
+
newsock.daddr = peer.addr;
|
|
3938
|
+
newsock.dport = peer.port;
|
|
3939
|
+
|
|
3940
|
+
// push to queue for accept to pick up
|
|
3941
|
+
sock.pending.push(newsock);
|
|
3942
|
+
Module['websocket'].emit('connection', newsock.stream.fd);
|
|
3943
|
+
} else {
|
|
3944
|
+
// create a peer on the listen socket so calling sendto
|
|
3945
|
+
// with the listen socket and an address will resolve
|
|
3946
|
+
// to the correct client
|
|
3947
|
+
SOCKFS.websocket_sock_ops.createPeer(sock, ws);
|
|
3948
|
+
Module['websocket'].emit('connection', sock.stream.fd);
|
|
3949
|
+
}
|
|
3950
|
+
});
|
|
3951
|
+
sock.server.on('close', function() {
|
|
3952
|
+
Module['websocket'].emit('close', sock.stream.fd);
|
|
3953
|
+
sock.server = null;
|
|
3954
|
+
});
|
|
3955
|
+
sock.server.on('error', function(error) {
|
|
3956
|
+
// Although the ws library may pass errors that may be more descriptive than
|
|
3957
|
+
// ECONNREFUSED they are not necessarily the expected error code e.g.
|
|
3958
|
+
// ENOTFOUND on getaddrinfo seems to be node.js specific, so using EHOSTUNREACH
|
|
3959
|
+
// is still probably the most useful thing to do. This error shouldn't
|
|
3960
|
+
// occur in a well written app as errors should get trapped in the compiled
|
|
3961
|
+
// app's own getaddrinfo call.
|
|
3962
|
+
sock.error = 23; // Used in getsockopt for SOL_SOCKET/SO_ERROR test.
|
|
3963
|
+
Module['websocket'].emit('error', [sock.stream.fd, sock.error, 'EHOSTUNREACH: Host is unreachable']);
|
|
3964
|
+
// don't throw
|
|
3965
|
+
});
|
|
3966
|
+
},
|
|
3967
|
+
accept(listensock) {
|
|
3968
|
+
if (!listensock.server || !listensock.pending.length) {
|
|
3969
|
+
throw new FS.ErrnoError(28);
|
|
3970
|
+
}
|
|
3971
|
+
var newsock = listensock.pending.shift();
|
|
3972
|
+
newsock.stream.flags = listensock.stream.flags;
|
|
3973
|
+
return newsock;
|
|
3974
|
+
},
|
|
3975
|
+
getname(sock, peer) {
|
|
3976
|
+
var addr, port;
|
|
3977
|
+
if (peer) {
|
|
3978
|
+
if (sock.daddr === undefined || sock.dport === undefined) {
|
|
3979
|
+
throw new FS.ErrnoError(53);
|
|
3980
|
+
}
|
|
3981
|
+
addr = sock.daddr;
|
|
3982
|
+
port = sock.dport;
|
|
3983
|
+
} else {
|
|
3984
|
+
// TODO saddr and sport will be set for bind()'d UDP sockets, but what
|
|
3985
|
+
// should we be returning for TCP sockets that've been connect()'d?
|
|
3986
|
+
addr = sock.saddr || 0;
|
|
3987
|
+
port = sock.sport || 0;
|
|
3988
|
+
}
|
|
3989
|
+
return { addr, port };
|
|
3990
|
+
},
|
|
3991
|
+
sendmsg(sock, buffer, offset, length, addr, port) {
|
|
3992
|
+
if (sock.type === 2) {
|
|
3993
|
+
// connection-less sockets will honor the message address,
|
|
3994
|
+
// and otherwise fall back to the bound destination address
|
|
3995
|
+
if (addr === undefined || port === undefined) {
|
|
3996
|
+
addr = sock.daddr;
|
|
3997
|
+
port = sock.dport;
|
|
3998
|
+
}
|
|
3999
|
+
// if there was no address to fall back to, error out
|
|
4000
|
+
if (addr === undefined || port === undefined) {
|
|
4001
|
+
throw new FS.ErrnoError(17);
|
|
4002
|
+
}
|
|
4003
|
+
} else {
|
|
4004
|
+
// connection-based sockets will only use the bound
|
|
4005
|
+
addr = sock.daddr;
|
|
4006
|
+
port = sock.dport;
|
|
4007
|
+
}
|
|
4008
|
+
|
|
4009
|
+
// find the peer for the destination address
|
|
4010
|
+
var dest = SOCKFS.websocket_sock_ops.getPeer(sock, addr, port);
|
|
4011
|
+
|
|
4012
|
+
// early out if not connected with a connection-based socket
|
|
4013
|
+
if (sock.type === 1) {
|
|
4014
|
+
if (!dest || dest.socket.readyState === dest.socket.CLOSING || dest.socket.readyState === dest.socket.CLOSED) {
|
|
4015
|
+
throw new FS.ErrnoError(53);
|
|
4016
|
+
} else if (dest.socket.readyState === dest.socket.CONNECTING) {
|
|
4017
|
+
throw new FS.ErrnoError(6);
|
|
4018
|
+
}
|
|
4019
|
+
}
|
|
4020
|
+
|
|
4021
|
+
// create a copy of the incoming data to send, as the WebSocket API
|
|
4022
|
+
// doesn't work entirely with an ArrayBufferView, it'll just send
|
|
4023
|
+
// the entire underlying buffer
|
|
4024
|
+
if (ArrayBuffer.isView(buffer)) {
|
|
4025
|
+
offset += buffer.byteOffset;
|
|
4026
|
+
buffer = buffer.buffer;
|
|
4027
|
+
}
|
|
4028
|
+
|
|
4029
|
+
var data;
|
|
4030
|
+
data = buffer.slice(offset, offset + length);
|
|
4031
|
+
|
|
4032
|
+
// if we're emulating a connection-less dgram socket and don't have
|
|
4033
|
+
// a cached connection, queue the buffer to send upon connect and
|
|
4034
|
+
// lie, saying the data was sent now.
|
|
4035
|
+
if (sock.type === 2) {
|
|
4036
|
+
if (!dest || dest.socket.readyState !== dest.socket.OPEN) {
|
|
4037
|
+
// if we're not connected, open a new connection
|
|
4038
|
+
if (!dest || dest.socket.readyState === dest.socket.CLOSING || dest.socket.readyState === dest.socket.CLOSED) {
|
|
4039
|
+
dest = SOCKFS.websocket_sock_ops.createPeer(sock, addr, port);
|
|
4040
|
+
}
|
|
4041
|
+
dest.dgram_send_queue.push(data);
|
|
4042
|
+
return length;
|
|
4043
|
+
}
|
|
4044
|
+
}
|
|
4045
|
+
|
|
4046
|
+
try {
|
|
4047
|
+
// send the actual data
|
|
4048
|
+
dest.socket.send(data);
|
|
4049
|
+
return length;
|
|
4050
|
+
} catch (e) {
|
|
4051
|
+
throw new FS.ErrnoError(28);
|
|
4052
|
+
}
|
|
4053
|
+
},
|
|
4054
|
+
recvmsg(sock, length) {
|
|
4055
|
+
// http://pubs.opengroup.org/onlinepubs/7908799/xns/recvmsg.html
|
|
4056
|
+
if (sock.type === 1 && sock.server) {
|
|
4057
|
+
// tcp servers should not be recv()'ing on the listen socket
|
|
4058
|
+
throw new FS.ErrnoError(53);
|
|
4059
|
+
}
|
|
4060
|
+
|
|
4061
|
+
var queued = sock.recv_queue.shift();
|
|
4062
|
+
if (!queued) {
|
|
4063
|
+
if (sock.type === 1) {
|
|
4064
|
+
var dest = SOCKFS.websocket_sock_ops.getPeer(sock, sock.daddr, sock.dport);
|
|
4065
|
+
|
|
4066
|
+
if (!dest) {
|
|
4067
|
+
// if we have a destination address but are not connected, error out
|
|
4068
|
+
throw new FS.ErrnoError(53);
|
|
4069
|
+
}
|
|
4070
|
+
if (dest.socket.readyState === dest.socket.CLOSING || dest.socket.readyState === dest.socket.CLOSED) {
|
|
4071
|
+
// return null if the socket has closed
|
|
4072
|
+
return null;
|
|
4073
|
+
}
|
|
4074
|
+
// else, our socket is in a valid state but truly has nothing available
|
|
4075
|
+
throw new FS.ErrnoError(6);
|
|
4076
|
+
}
|
|
4077
|
+
throw new FS.ErrnoError(6);
|
|
4078
|
+
}
|
|
4079
|
+
|
|
4080
|
+
// queued.data will be an ArrayBuffer if it's unadulterated, but if it's
|
|
4081
|
+
// requeued TCP data it'll be an ArrayBufferView
|
|
4082
|
+
var queuedLength = queued.data.byteLength || queued.data.length;
|
|
4083
|
+
var queuedOffset = queued.data.byteOffset || 0;
|
|
4084
|
+
var queuedBuffer = queued.data.buffer || queued.data;
|
|
4085
|
+
var bytesRead = Math.min(length, queuedLength);
|
|
4086
|
+
var res = {
|
|
4087
|
+
buffer: new Uint8Array(queuedBuffer, queuedOffset, bytesRead),
|
|
4088
|
+
addr: queued.addr,
|
|
4089
|
+
port: queued.port
|
|
4090
|
+
};
|
|
4091
|
+
|
|
4092
|
+
// push back any unread data for TCP connections
|
|
4093
|
+
if (sock.type === 1 && bytesRead < queuedLength) {
|
|
4094
|
+
var bytesRemaining = queuedLength - bytesRead;
|
|
4095
|
+
queued.data = new Uint8Array(queuedBuffer, queuedOffset + bytesRead, bytesRemaining);
|
|
4096
|
+
sock.recv_queue.unshift(queued);
|
|
4097
|
+
}
|
|
4098
|
+
|
|
4099
|
+
return res;
|
|
4100
|
+
},
|
|
4101
|
+
},
|
|
4102
|
+
};
|
|
4103
|
+
|
|
4104
|
+
var getSocketFromFD = (fd) => {
|
|
4105
|
+
var socket = SOCKFS.getSocket(fd);
|
|
4106
|
+
if (!socket) throw new FS.ErrnoError(8);
|
|
4107
|
+
return socket;
|
|
4108
|
+
};
|
|
4109
|
+
|
|
4110
|
+
var Sockets = {
|
|
4111
|
+
BUFFER_SIZE:10240,
|
|
4112
|
+
MAX_BUFFER_SIZE:10485760,
|
|
4113
|
+
nextFd:1,
|
|
4114
|
+
fds:{
|
|
4115
|
+
},
|
|
4116
|
+
nextport:1,
|
|
4117
|
+
maxport:65535,
|
|
4118
|
+
peer:null,
|
|
4119
|
+
connections:{
|
|
4120
|
+
},
|
|
4121
|
+
portmap:{
|
|
4122
|
+
},
|
|
4123
|
+
localAddr:4261412874,
|
|
4124
|
+
addrPool:[33554442,50331658,67108874,83886090,100663306,117440522,134217738,150994954,167772170,184549386,201326602,218103818,234881034],
|
|
4125
|
+
};
|
|
4126
|
+
|
|
4127
|
+
var inetNtop4 = (addr) => {
|
|
4128
|
+
return (addr & 0xff) + '.' + ((addr >> 8) & 0xff) + '.' + ((addr >> 16) & 0xff) + '.' + ((addr >> 24) & 0xff)
|
|
4129
|
+
};
|
|
4130
|
+
|
|
4131
|
+
|
|
4132
|
+
var inetNtop6 = (ints) => {
|
|
4133
|
+
// ref: http://www.ietf.org/rfc/rfc2373.txt - section 2.5.4
|
|
4134
|
+
// Format for IPv4 compatible and mapped 128-bit IPv6 Addresses
|
|
4135
|
+
// 128-bits are split into eight 16-bit words
|
|
4136
|
+
// stored in network byte order (big-endian)
|
|
4137
|
+
// | 80 bits | 16 | 32 bits |
|
|
4138
|
+
// +-----------------------------------------------------------------+
|
|
4139
|
+
// | 10 bytes | 2 | 4 bytes |
|
|
4140
|
+
// +--------------------------------------+--------------------------+
|
|
4141
|
+
// + 5 words | 1 | 2 words |
|
|
4142
|
+
// +--------------------------------------+--------------------------+
|
|
4143
|
+
// |0000..............................0000|0000| IPv4 ADDRESS | (compatible)
|
|
4144
|
+
// +--------------------------------------+----+---------------------+
|
|
4145
|
+
// |0000..............................0000|FFFF| IPv4 ADDRESS | (mapped)
|
|
4146
|
+
// +--------------------------------------+----+---------------------+
|
|
4147
|
+
var str = "";
|
|
4148
|
+
var word = 0;
|
|
4149
|
+
var longest = 0;
|
|
4150
|
+
var lastzero = 0;
|
|
4151
|
+
var zstart = 0;
|
|
4152
|
+
var len = 0;
|
|
4153
|
+
var i = 0;
|
|
4154
|
+
var parts = [
|
|
4155
|
+
ints[0] & 0xffff,
|
|
4156
|
+
(ints[0] >> 16),
|
|
4157
|
+
ints[1] & 0xffff,
|
|
4158
|
+
(ints[1] >> 16),
|
|
4159
|
+
ints[2] & 0xffff,
|
|
4160
|
+
(ints[2] >> 16),
|
|
4161
|
+
ints[3] & 0xffff,
|
|
4162
|
+
(ints[3] >> 16)
|
|
4163
|
+
];
|
|
4164
|
+
|
|
4165
|
+
// Handle IPv4-compatible, IPv4-mapped, loopback and any/unspecified addresses
|
|
4166
|
+
|
|
4167
|
+
var hasipv4 = true;
|
|
4168
|
+
var v4part = "";
|
|
4169
|
+
// check if the 10 high-order bytes are all zeros (first 5 words)
|
|
4170
|
+
for (i = 0; i < 5; i++) {
|
|
4171
|
+
if (parts[i] !== 0) { hasipv4 = false; break; }
|
|
4172
|
+
}
|
|
4173
|
+
|
|
4174
|
+
if (hasipv4) {
|
|
4175
|
+
// low-order 32-bits store an IPv4 address (bytes 13 to 16) (last 2 words)
|
|
4176
|
+
v4part = inetNtop4(parts[6] | (parts[7] << 16));
|
|
4177
|
+
// IPv4-mapped IPv6 address if 16-bit value (bytes 11 and 12) == 0xFFFF (6th word)
|
|
4178
|
+
if (parts[5] === -1) {
|
|
4179
|
+
str = "::ffff:";
|
|
4180
|
+
str += v4part;
|
|
4181
|
+
return str;
|
|
4182
|
+
}
|
|
4183
|
+
// IPv4-compatible IPv6 address if 16-bit value (bytes 11 and 12) == 0x0000 (6th word)
|
|
4184
|
+
if (parts[5] === 0) {
|
|
4185
|
+
str = "::";
|
|
4186
|
+
//special case IPv6 addresses
|
|
4187
|
+
if (v4part === "0.0.0.0") v4part = ""; // any/unspecified address
|
|
4188
|
+
if (v4part === "0.0.0.1") v4part = "1";// loopback address
|
|
4189
|
+
str += v4part;
|
|
4190
|
+
return str;
|
|
4191
|
+
}
|
|
4192
|
+
}
|
|
4193
|
+
|
|
4194
|
+
// Handle all other IPv6 addresses
|
|
4195
|
+
|
|
4196
|
+
// first run to find the longest contiguous zero words
|
|
4197
|
+
for (word = 0; word < 8; word++) {
|
|
4198
|
+
if (parts[word] === 0) {
|
|
4199
|
+
if (word - lastzero > 1) {
|
|
4200
|
+
len = 0;
|
|
4201
|
+
}
|
|
4202
|
+
lastzero = word;
|
|
4203
|
+
len++;
|
|
4204
|
+
}
|
|
4205
|
+
if (len > longest) {
|
|
4206
|
+
longest = len;
|
|
4207
|
+
zstart = word - longest + 1;
|
|
4208
|
+
}
|
|
4209
|
+
}
|
|
4210
|
+
|
|
4211
|
+
for (word = 0; word < 8; word++) {
|
|
4212
|
+
if (longest > 1) {
|
|
4213
|
+
// compress contiguous zeros - to produce "::"
|
|
4214
|
+
if (parts[word] === 0 && word >= zstart && word < (zstart + longest) ) {
|
|
4215
|
+
if (word === zstart) {
|
|
4216
|
+
str += ":";
|
|
4217
|
+
if (zstart === 0) str += ":"; //leading zeros case
|
|
4218
|
+
}
|
|
4219
|
+
continue;
|
|
4220
|
+
}
|
|
4221
|
+
}
|
|
4222
|
+
// converts 16-bit words from big-endian to little-endian before converting to hex string
|
|
4223
|
+
str += Number(_ntohs(parts[word] & 0xffff)).toString(16);
|
|
4224
|
+
str += word < 7 ? ":" : "";
|
|
4225
|
+
}
|
|
4226
|
+
return str;
|
|
4227
|
+
};
|
|
4228
|
+
|
|
4229
|
+
var readSockaddr = (sa, salen) => {
|
|
4230
|
+
// family / port offsets are common to both sockaddr_in and sockaddr_in6
|
|
4231
|
+
var family = HEAP16[((sa)>>1)];
|
|
4232
|
+
var port = _ntohs(HEAPU16[(((sa)+(2))>>1)]);
|
|
4233
|
+
var addr;
|
|
4234
|
+
|
|
4235
|
+
switch (family) {
|
|
4236
|
+
case 2:
|
|
4237
|
+
if (salen !== 16) {
|
|
4238
|
+
return { errno: 28 };
|
|
4239
|
+
}
|
|
4240
|
+
addr = HEAP32[(((sa)+(4))>>2)];
|
|
4241
|
+
addr = inetNtop4(addr);
|
|
4242
|
+
break;
|
|
4243
|
+
case 10:
|
|
4244
|
+
if (salen !== 28) {
|
|
4245
|
+
return { errno: 28 };
|
|
4246
|
+
}
|
|
4247
|
+
addr = [
|
|
4248
|
+
HEAP32[(((sa)+(8))>>2)],
|
|
4249
|
+
HEAP32[(((sa)+(12))>>2)],
|
|
4250
|
+
HEAP32[(((sa)+(16))>>2)],
|
|
4251
|
+
HEAP32[(((sa)+(20))>>2)]
|
|
4252
|
+
];
|
|
4253
|
+
addr = inetNtop6(addr);
|
|
4254
|
+
break;
|
|
4255
|
+
default:
|
|
4256
|
+
return { errno: 5 };
|
|
4257
|
+
}
|
|
4258
|
+
|
|
4259
|
+
return { family: family, addr: addr, port: port };
|
|
4260
|
+
};
|
|
4261
|
+
|
|
4262
|
+
|
|
4263
|
+
var inetPton4 = (str) => {
|
|
4264
|
+
var b = str.split('.');
|
|
4265
|
+
for (var i = 0; i < 4; i++) {
|
|
4266
|
+
var tmp = Number(b[i]);
|
|
4267
|
+
if (isNaN(tmp)) return null;
|
|
4268
|
+
b[i] = tmp;
|
|
4269
|
+
}
|
|
4270
|
+
return (b[0] | (b[1] << 8) | (b[2] << 16) | (b[3] << 24)) >>> 0;
|
|
4271
|
+
};
|
|
4272
|
+
|
|
4273
|
+
|
|
4274
|
+
/** @suppress {checkTypes} */
|
|
4275
|
+
var jstoi_q = (str) => parseInt(str);
|
|
4276
|
+
var inetPton6 = (str) => {
|
|
4277
|
+
var words;
|
|
4278
|
+
var w, offset, z, i;
|
|
4279
|
+
/* http://home.deds.nl/~aeron/regex/ */
|
|
4280
|
+
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
|
|
4281
|
+
var parts = [];
|
|
4282
|
+
if (!valid6regx.test(str)) {
|
|
4283
|
+
return null;
|
|
4284
|
+
}
|
|
4285
|
+
if (str === "::") {
|
|
4286
|
+
return [0, 0, 0, 0, 0, 0, 0, 0];
|
|
4287
|
+
}
|
|
4288
|
+
// Z placeholder to keep track of zeros when splitting the string on ":"
|
|
4289
|
+
if (str.startsWith("::")) {
|
|
4290
|
+
str = str.replace("::", "Z:"); // leading zeros case
|
|
4291
|
+
} else {
|
|
4292
|
+
str = str.replace("::", ":Z:");
|
|
4293
|
+
}
|
|
4294
|
+
|
|
4295
|
+
if (str.indexOf(".") > 0) {
|
|
4296
|
+
// parse IPv4 embedded stress
|
|
4297
|
+
str = str.replace(new RegExp('[.]', 'g'), ":");
|
|
4298
|
+
words = str.split(":");
|
|
4299
|
+
words[words.length-4] = jstoi_q(words[words.length-4]) + jstoi_q(words[words.length-3])*256;
|
|
4300
|
+
words[words.length-3] = jstoi_q(words[words.length-2]) + jstoi_q(words[words.length-1])*256;
|
|
4301
|
+
words = words.slice(0, words.length-2);
|
|
4302
|
+
} else {
|
|
4303
|
+
words = str.split(":");
|
|
4304
|
+
}
|
|
4305
|
+
|
|
4306
|
+
offset = 0; z = 0;
|
|
4307
|
+
for (w=0; w < words.length; w++) {
|
|
4308
|
+
if (typeof words[w] == 'string') {
|
|
4309
|
+
if (words[w] === 'Z') {
|
|
4310
|
+
// compressed zeros - write appropriate number of zero words
|
|
4311
|
+
for (z = 0; z < (8 - words.length+1); z++) {
|
|
4312
|
+
parts[w+z] = 0;
|
|
4313
|
+
}
|
|
4314
|
+
offset = z-1;
|
|
4315
|
+
} else {
|
|
4316
|
+
// parse hex to field to 16-bit value and write it in network byte-order
|
|
4317
|
+
parts[w+offset] = _htons(parseInt(words[w],16));
|
|
4318
|
+
}
|
|
4319
|
+
} else {
|
|
4320
|
+
// parsed IPv4 words
|
|
4321
|
+
parts[w+offset] = words[w];
|
|
4322
|
+
}
|
|
4323
|
+
}
|
|
4324
|
+
return [
|
|
4325
|
+
(parts[1] << 16) | parts[0],
|
|
4326
|
+
(parts[3] << 16) | parts[2],
|
|
4327
|
+
(parts[5] << 16) | parts[4],
|
|
4328
|
+
(parts[7] << 16) | parts[6]
|
|
4329
|
+
];
|
|
4330
|
+
};
|
|
4331
|
+
var DNS = {
|
|
4332
|
+
address_map:{
|
|
4333
|
+
id:1,
|
|
4334
|
+
addrs:{
|
|
4335
|
+
},
|
|
4336
|
+
names:{
|
|
4337
|
+
},
|
|
4338
|
+
},
|
|
4339
|
+
lookup_name(name) {
|
|
4340
|
+
// If the name is already a valid ipv4 / ipv6 address, don't generate a fake one.
|
|
4341
|
+
var res = inetPton4(name);
|
|
4342
|
+
if (res !== null) {
|
|
4343
|
+
return name;
|
|
4344
|
+
}
|
|
4345
|
+
res = inetPton6(name);
|
|
4346
|
+
if (res !== null) {
|
|
4347
|
+
return name;
|
|
4348
|
+
}
|
|
4349
|
+
|
|
4350
|
+
// See if this name is already mapped.
|
|
4351
|
+
var addr;
|
|
4352
|
+
|
|
4353
|
+
if (DNS.address_map.addrs[name]) {
|
|
4354
|
+
addr = DNS.address_map.addrs[name];
|
|
4355
|
+
} else {
|
|
4356
|
+
var id = DNS.address_map.id++;
|
|
4357
|
+
assert(id < 65535, 'exceeded max address mappings of 65535');
|
|
4358
|
+
|
|
4359
|
+
addr = '172.29.' + (id & 0xff) + '.' + (id & 0xff00);
|
|
4360
|
+
|
|
4361
|
+
DNS.address_map.names[addr] = name;
|
|
4362
|
+
DNS.address_map.addrs[name] = addr;
|
|
4363
|
+
}
|
|
4364
|
+
|
|
4365
|
+
return addr;
|
|
4366
|
+
},
|
|
4367
|
+
lookup_addr(addr) {
|
|
4368
|
+
if (DNS.address_map.names[addr]) {
|
|
4369
|
+
return DNS.address_map.names[addr];
|
|
4370
|
+
}
|
|
4371
|
+
|
|
4372
|
+
return null;
|
|
4373
|
+
},
|
|
4374
|
+
};
|
|
4375
|
+
/** @param {boolean=} allowNull */
|
|
4376
|
+
var getSocketAddress = (addrp, addrlen, allowNull) => {
|
|
4377
|
+
if (allowNull && addrp === 0) return null;
|
|
4378
|
+
var info = readSockaddr(addrp, addrlen);
|
|
4379
|
+
if (info.errno) throw new FS.ErrnoError(info.errno);
|
|
4380
|
+
info.addr = DNS.lookup_addr(info.addr) || info.addr;
|
|
4381
|
+
return info;
|
|
4382
|
+
};
|
|
4383
|
+
function ___syscall_connect(fd, addr, addrlen, d1, d2, d3) {
|
|
4384
|
+
try {
|
|
4385
|
+
|
|
4386
|
+
var sock = getSocketFromFD(fd);
|
|
4387
|
+
var info = getSocketAddress(addr, addrlen);
|
|
4388
|
+
sock.sock_ops.connect(sock, info.addr, info.port);
|
|
4389
|
+
return 0;
|
|
4390
|
+
} catch (e) {
|
|
4391
|
+
if (typeof FS == 'undefined' || !(e.name === 'ErrnoError')) throw e;
|
|
4392
|
+
return -e.errno;
|
|
4393
|
+
}
|
|
4394
|
+
}
|
|
4395
|
+
|
|
3449
4396
|
function ___syscall_faccessat(dirfd, path, amode, flags) {
|
|
3450
4397
|
try {
|
|
3451
4398
|
|
|
@@ -3478,6 +4425,17 @@ function createWasm() {
|
|
|
3478
4425
|
return 0; // your advice is important to us (but we can't use it)
|
|
3479
4426
|
};
|
|
3480
4427
|
|
|
4428
|
+
function ___syscall_fchmod(fd, mode) {
|
|
4429
|
+
try {
|
|
4430
|
+
|
|
4431
|
+
FS.fchmod(fd, mode);
|
|
4432
|
+
return 0;
|
|
4433
|
+
} catch (e) {
|
|
4434
|
+
if (typeof FS == 'undefined' || !(e.name === 'ErrnoError')) throw e;
|
|
4435
|
+
return -e.errno;
|
|
4436
|
+
}
|
|
4437
|
+
}
|
|
4438
|
+
|
|
3481
4439
|
function ___syscall_fcntl64(fd, cmd, varargs) {
|
|
3482
4440
|
SYSCALLS.varargs = varargs;
|
|
3483
4441
|
try {
|
|
@@ -3764,6 +4722,23 @@ function createWasm() {
|
|
|
3764
4722
|
}
|
|
3765
4723
|
}
|
|
3766
4724
|
|
|
4725
|
+
function ___syscall_mkdirat(dirfd, path, mode) {
|
|
4726
|
+
try {
|
|
4727
|
+
|
|
4728
|
+
path = SYSCALLS.getStr(path);
|
|
4729
|
+
path = SYSCALLS.calculateAt(dirfd, path);
|
|
4730
|
+
// remove a trailing slash, if one - /a/b/ has basename of '', but
|
|
4731
|
+
// we want to create b in the context of this function
|
|
4732
|
+
path = PATH.normalize(path);
|
|
4733
|
+
if (path[path.length-1] === '/') path = path.substr(0, path.length-1);
|
|
4734
|
+
FS.mkdir(path, mode, 0);
|
|
4735
|
+
return 0;
|
|
4736
|
+
} catch (e) {
|
|
4737
|
+
if (typeof FS == 'undefined' || !(e.name === 'ErrnoError')) throw e;
|
|
4738
|
+
return -e.errno;
|
|
4739
|
+
}
|
|
4740
|
+
}
|
|
4741
|
+
|
|
3767
4742
|
function ___syscall_newfstatat(dirfd, path, buf, flags) {
|
|
3768
4743
|
try {
|
|
3769
4744
|
|
|
@@ -3816,6 +4791,62 @@ function createWasm() {
|
|
|
3816
4791
|
}
|
|
3817
4792
|
}
|
|
3818
4793
|
|
|
4794
|
+
function ___syscall_renameat(olddirfd, oldpath, newdirfd, newpath) {
|
|
4795
|
+
try {
|
|
4796
|
+
|
|
4797
|
+
oldpath = SYSCALLS.getStr(oldpath);
|
|
4798
|
+
newpath = SYSCALLS.getStr(newpath);
|
|
4799
|
+
oldpath = SYSCALLS.calculateAt(olddirfd, oldpath);
|
|
4800
|
+
newpath = SYSCALLS.calculateAt(newdirfd, newpath);
|
|
4801
|
+
FS.rename(oldpath, newpath);
|
|
4802
|
+
return 0;
|
|
4803
|
+
} catch (e) {
|
|
4804
|
+
if (typeof FS == 'undefined' || !(e.name === 'ErrnoError')) throw e;
|
|
4805
|
+
return -e.errno;
|
|
4806
|
+
}
|
|
4807
|
+
}
|
|
4808
|
+
|
|
4809
|
+
function ___syscall_rmdir(path) {
|
|
4810
|
+
try {
|
|
4811
|
+
|
|
4812
|
+
path = SYSCALLS.getStr(path);
|
|
4813
|
+
FS.rmdir(path);
|
|
4814
|
+
return 0;
|
|
4815
|
+
} catch (e) {
|
|
4816
|
+
if (typeof FS == 'undefined' || !(e.name === 'ErrnoError')) throw e;
|
|
4817
|
+
return -e.errno;
|
|
4818
|
+
}
|
|
4819
|
+
}
|
|
4820
|
+
|
|
4821
|
+
|
|
4822
|
+
function ___syscall_sendto(fd, message, length, flags, addr, addr_len) {
|
|
4823
|
+
try {
|
|
4824
|
+
|
|
4825
|
+
var sock = getSocketFromFD(fd);
|
|
4826
|
+
var dest = getSocketAddress(addr, addr_len, true);
|
|
4827
|
+
if (!dest) {
|
|
4828
|
+
// send, no address provided
|
|
4829
|
+
return FS.write(sock.stream, HEAP8, message, length);
|
|
4830
|
+
}
|
|
4831
|
+
// sendto an address
|
|
4832
|
+
return sock.sock_ops.sendmsg(sock, HEAP8, message, length, dest.addr, dest.port);
|
|
4833
|
+
} catch (e) {
|
|
4834
|
+
if (typeof FS == 'undefined' || !(e.name === 'ErrnoError')) throw e;
|
|
4835
|
+
return -e.errno;
|
|
4836
|
+
}
|
|
4837
|
+
}
|
|
4838
|
+
|
|
4839
|
+
function ___syscall_socket(domain, type, protocol) {
|
|
4840
|
+
try {
|
|
4841
|
+
|
|
4842
|
+
var sock = SOCKFS.createSocket(domain, type, protocol);
|
|
4843
|
+
return sock.stream.fd;
|
|
4844
|
+
} catch (e) {
|
|
4845
|
+
if (typeof FS == 'undefined' || !(e.name === 'ErrnoError')) throw e;
|
|
4846
|
+
return -e.errno;
|
|
4847
|
+
}
|
|
4848
|
+
}
|
|
4849
|
+
|
|
3819
4850
|
function ___syscall_stat64(path, buf) {
|
|
3820
4851
|
try {
|
|
3821
4852
|
|
|
@@ -3827,6 +4858,19 @@ function createWasm() {
|
|
|
3827
4858
|
}
|
|
3828
4859
|
}
|
|
3829
4860
|
|
|
4861
|
+
function ___syscall_symlink(target, linkpath) {
|
|
4862
|
+
try {
|
|
4863
|
+
|
|
4864
|
+
target = SYSCALLS.getStr(target);
|
|
4865
|
+
linkpath = SYSCALLS.getStr(linkpath);
|
|
4866
|
+
FS.symlink(target, linkpath);
|
|
4867
|
+
return 0;
|
|
4868
|
+
} catch (e) {
|
|
4869
|
+
if (typeof FS == 'undefined' || !(e.name === 'ErrnoError')) throw e;
|
|
4870
|
+
return -e.errno;
|
|
4871
|
+
}
|
|
4872
|
+
}
|
|
4873
|
+
|
|
3830
4874
|
function ___syscall_unlinkat(dirfd, path, flags) {
|
|
3831
4875
|
try {
|
|
3832
4876
|
|
|
@@ -3846,9 +4890,56 @@ function createWasm() {
|
|
|
3846
4890
|
}
|
|
3847
4891
|
}
|
|
3848
4892
|
|
|
4893
|
+
var readI53FromI64 = (ptr) => {
|
|
4894
|
+
return HEAPU32[((ptr)>>2)] + HEAP32[(((ptr)+(4))>>2)] * 4294967296;
|
|
4895
|
+
};
|
|
4896
|
+
|
|
4897
|
+
function ___syscall_utimensat(dirfd, path, times, flags) {
|
|
4898
|
+
try {
|
|
4899
|
+
|
|
4900
|
+
path = SYSCALLS.getStr(path);
|
|
4901
|
+
path = SYSCALLS.calculateAt(dirfd, path, true);
|
|
4902
|
+
if (!times) {
|
|
4903
|
+
var atime = Date.now();
|
|
4904
|
+
var mtime = atime;
|
|
4905
|
+
} else {
|
|
4906
|
+
var seconds = readI53FromI64(times);
|
|
4907
|
+
var nanoseconds = HEAP32[(((times)+(8))>>2)];
|
|
4908
|
+
atime = (seconds*1000) + (nanoseconds/(1000*1000));
|
|
4909
|
+
times += 16;
|
|
4910
|
+
seconds = readI53FromI64(times);
|
|
4911
|
+
nanoseconds = HEAP32[(((times)+(8))>>2)];
|
|
4912
|
+
mtime = (seconds*1000) + (nanoseconds/(1000*1000));
|
|
4913
|
+
}
|
|
4914
|
+
FS.utime(path, atime, mtime);
|
|
4915
|
+
return 0;
|
|
4916
|
+
} catch (e) {
|
|
4917
|
+
if (typeof FS == 'undefined' || !(e.name === 'ErrnoError')) throw e;
|
|
4918
|
+
return -e.errno;
|
|
4919
|
+
}
|
|
4920
|
+
}
|
|
4921
|
+
|
|
3849
4922
|
var nowIsMonotonic = 1;
|
|
3850
4923
|
var __emscripten_get_now_is_monotonic = () => nowIsMonotonic;
|
|
3851
4924
|
|
|
4925
|
+
function __gmtime_js(time, tmPtr) {
|
|
4926
|
+
time = bigintToI53Checked(time);
|
|
4927
|
+
|
|
4928
|
+
|
|
4929
|
+
var date = new Date(time * 1000);
|
|
4930
|
+
HEAP32[((tmPtr)>>2)] = date.getUTCSeconds();
|
|
4931
|
+
HEAP32[(((tmPtr)+(4))>>2)] = date.getUTCMinutes();
|
|
4932
|
+
HEAP32[(((tmPtr)+(8))>>2)] = date.getUTCHours();
|
|
4933
|
+
HEAP32[(((tmPtr)+(12))>>2)] = date.getUTCDate();
|
|
4934
|
+
HEAP32[(((tmPtr)+(16))>>2)] = date.getUTCMonth();
|
|
4935
|
+
HEAP32[(((tmPtr)+(20))>>2)] = date.getUTCFullYear()-1900;
|
|
4936
|
+
HEAP32[(((tmPtr)+(24))>>2)] = date.getUTCDay();
|
|
4937
|
+
var start = Date.UTC(date.getUTCFullYear(), 0, 1, 0, 0, 0, 0);
|
|
4938
|
+
var yday = ((date.getTime() - start) / (1000 * 60 * 60 * 24))|0;
|
|
4939
|
+
HEAP32[(((tmPtr)+(28))>>2)] = yday;
|
|
4940
|
+
;
|
|
4941
|
+
}
|
|
4942
|
+
|
|
3852
4943
|
var isLeapYear = (year) => year%4 === 0 && (year%100 !== 0 || year%400 === 0);
|
|
3853
4944
|
|
|
3854
4945
|
var MONTH_DAYS_LEAP_CUMULATIVE = [0,31,60,91,121,152,182,213,244,274,305,335];
|
|
@@ -3914,6 +5005,23 @@ function createWasm() {
|
|
|
3914
5005
|
}
|
|
3915
5006
|
|
|
3916
5007
|
|
|
5008
|
+
function __msync_js(addr, len, prot, flags, fd, offset) {
|
|
5009
|
+
offset = bigintToI53Checked(offset);
|
|
5010
|
+
|
|
5011
|
+
|
|
5012
|
+
try {
|
|
5013
|
+
|
|
5014
|
+
if (isNaN(offset)) return 61;
|
|
5015
|
+
SYSCALLS.doMsync(addr, SYSCALLS.getStreamFromFD(fd), len, flags, offset);
|
|
5016
|
+
return 0;
|
|
5017
|
+
} catch (e) {
|
|
5018
|
+
if (typeof FS == 'undefined' || !(e.name === 'ErrnoError')) throw e;
|
|
5019
|
+
return -e.errno;
|
|
5020
|
+
}
|
|
5021
|
+
;
|
|
5022
|
+
}
|
|
5023
|
+
|
|
5024
|
+
|
|
3917
5025
|
function __munmap_js(addr, len, prot, flags, fd, offset) {
|
|
3918
5026
|
offset = bigintToI53Checked(offset);
|
|
3919
5027
|
|
|
@@ -4180,6 +5288,32 @@ function createWasm() {
|
|
|
4180
5288
|
}
|
|
4181
5289
|
}
|
|
4182
5290
|
|
|
5291
|
+
function _fd_fdstat_get(fd, pbuf) {
|
|
5292
|
+
try {
|
|
5293
|
+
|
|
5294
|
+
var rightsBase = 0;
|
|
5295
|
+
var rightsInheriting = 0;
|
|
5296
|
+
var flags = 0;
|
|
5297
|
+
{
|
|
5298
|
+
var stream = SYSCALLS.getStreamFromFD(fd);
|
|
5299
|
+
// All character devices are terminals (other things a Linux system would
|
|
5300
|
+
// assume is a character device, like the mouse, we have special APIs for).
|
|
5301
|
+
var type = stream.tty ? 2 :
|
|
5302
|
+
FS.isDir(stream.mode) ? 3 :
|
|
5303
|
+
FS.isLink(stream.mode) ? 7 :
|
|
5304
|
+
4;
|
|
5305
|
+
}
|
|
5306
|
+
HEAP8[pbuf] = type;
|
|
5307
|
+
HEAP16[(((pbuf)+(2))>>1)] = flags;
|
|
5308
|
+
HEAP64[(((pbuf)+(8))>>3)] = BigInt(rightsBase);
|
|
5309
|
+
HEAP64[(((pbuf)+(16))>>3)] = BigInt(rightsInheriting);
|
|
5310
|
+
return 0;
|
|
5311
|
+
} catch (e) {
|
|
5312
|
+
if (typeof FS == 'undefined' || !(e.name === 'ErrnoError')) throw e;
|
|
5313
|
+
return e.errno;
|
|
5314
|
+
}
|
|
5315
|
+
}
|
|
5316
|
+
|
|
4183
5317
|
/** @param {number=} offset */
|
|
4184
5318
|
var doReadv = (stream, iov, iovcnt, offset) => {
|
|
4185
5319
|
var ret = 0;
|
|
@@ -5112,10 +6246,18 @@ var wasmImports = {
|
|
|
5112
6246
|
/** @export */
|
|
5113
6247
|
__assert_fail: ___assert_fail,
|
|
5114
6248
|
/** @export */
|
|
6249
|
+
__syscall_chdir: ___syscall_chdir,
|
|
6250
|
+
/** @export */
|
|
6251
|
+
__syscall_chmod: ___syscall_chmod,
|
|
6252
|
+
/** @export */
|
|
6253
|
+
__syscall_connect: ___syscall_connect,
|
|
6254
|
+
/** @export */
|
|
5115
6255
|
__syscall_faccessat: ___syscall_faccessat,
|
|
5116
6256
|
/** @export */
|
|
5117
6257
|
__syscall_fadvise64: ___syscall_fadvise64,
|
|
5118
6258
|
/** @export */
|
|
6259
|
+
__syscall_fchmod: ___syscall_fchmod,
|
|
6260
|
+
/** @export */
|
|
5119
6261
|
__syscall_fcntl64: ___syscall_fcntl64,
|
|
5120
6262
|
/** @export */
|
|
5121
6263
|
__syscall_fstat64: ___syscall_fstat64,
|
|
@@ -5132,22 +6274,40 @@ var wasmImports = {
|
|
|
5132
6274
|
/** @export */
|
|
5133
6275
|
__syscall_lstat64: ___syscall_lstat64,
|
|
5134
6276
|
/** @export */
|
|
6277
|
+
__syscall_mkdirat: ___syscall_mkdirat,
|
|
6278
|
+
/** @export */
|
|
5135
6279
|
__syscall_newfstatat: ___syscall_newfstatat,
|
|
5136
6280
|
/** @export */
|
|
5137
6281
|
__syscall_openat: ___syscall_openat,
|
|
5138
6282
|
/** @export */
|
|
5139
6283
|
__syscall_readlinkat: ___syscall_readlinkat,
|
|
5140
6284
|
/** @export */
|
|
6285
|
+
__syscall_renameat: ___syscall_renameat,
|
|
6286
|
+
/** @export */
|
|
6287
|
+
__syscall_rmdir: ___syscall_rmdir,
|
|
6288
|
+
/** @export */
|
|
6289
|
+
__syscall_sendto: ___syscall_sendto,
|
|
6290
|
+
/** @export */
|
|
6291
|
+
__syscall_socket: ___syscall_socket,
|
|
6292
|
+
/** @export */
|
|
5141
6293
|
__syscall_stat64: ___syscall_stat64,
|
|
5142
6294
|
/** @export */
|
|
6295
|
+
__syscall_symlink: ___syscall_symlink,
|
|
6296
|
+
/** @export */
|
|
5143
6297
|
__syscall_unlinkat: ___syscall_unlinkat,
|
|
5144
6298
|
/** @export */
|
|
6299
|
+
__syscall_utimensat: ___syscall_utimensat,
|
|
6300
|
+
/** @export */
|
|
5145
6301
|
_emscripten_get_now_is_monotonic: __emscripten_get_now_is_monotonic,
|
|
5146
6302
|
/** @export */
|
|
6303
|
+
_gmtime_js: __gmtime_js,
|
|
6304
|
+
/** @export */
|
|
5147
6305
|
_localtime_js: __localtime_js,
|
|
5148
6306
|
/** @export */
|
|
5149
6307
|
_mmap_js: __mmap_js,
|
|
5150
6308
|
/** @export */
|
|
6309
|
+
_msync_js: __msync_js,
|
|
6310
|
+
/** @export */
|
|
5151
6311
|
_munmap_js: __munmap_js,
|
|
5152
6312
|
/** @export */
|
|
5153
6313
|
_tzset_js: __tzset_js,
|
|
@@ -5174,6 +6334,8 @@ var wasmImports = {
|
|
|
5174
6334
|
/** @export */
|
|
5175
6335
|
fd_close: _fd_close,
|
|
5176
6336
|
/** @export */
|
|
6337
|
+
fd_fdstat_get: _fd_fdstat_get,
|
|
6338
|
+
/** @export */
|
|
5177
6339
|
fd_pread: _fd_pread,
|
|
5178
6340
|
/** @export */
|
|
5179
6341
|
fd_pwrite: _fd_pwrite,
|
|
@@ -5408,10 +6570,12 @@ var _mono_wasm_gc_lock = Module['_mono_wasm_gc_lock'] = () => (_mono_wasm_gc_loc
|
|
|
5408
6570
|
var _mono_wasm_gc_unlock = Module['_mono_wasm_gc_unlock'] = () => (_mono_wasm_gc_unlock = Module['_mono_wasm_gc_unlock'] = wasmExports['mono_wasm_gc_unlock'])();
|
|
5409
6571
|
var _mono_print_method_from_ip = Module['_mono_print_method_from_ip'] = (a0) => (_mono_print_method_from_ip = Module['_mono_print_method_from_ip'] = wasmExports['mono_print_method_from_ip'])(a0);
|
|
5410
6572
|
var _mono_wasm_execute_timer = Module['_mono_wasm_execute_timer'] = () => (_mono_wasm_execute_timer = Module['_mono_wasm_execute_timer'] = wasmExports['mono_wasm_execute_timer'])();
|
|
5411
|
-
var
|
|
6573
|
+
var _mono_wasm_load_icu_data = Module['_mono_wasm_load_icu_data'] = (a0) => (_mono_wasm_load_icu_data = Module['_mono_wasm_load_icu_data'] = wasmExports['mono_wasm_load_icu_data'])(a0);
|
|
6574
|
+
var _ntohs = Module['_ntohs'] = (a0) => (_ntohs = Module['_ntohs'] = wasmExports['ntohs'])(a0);
|
|
5412
6575
|
var _htons = Module['_htons'] = (a0) => (_htons = Module['_htons'] = wasmExports['htons'])(a0);
|
|
6576
|
+
var ___funcs_on_exit = () => (___funcs_on_exit = wasmExports['__funcs_on_exit'])();
|
|
6577
|
+
var _htonl = (a0) => (_htonl = wasmExports['htonl'])(a0);
|
|
5413
6578
|
var _emscripten_builtin_memalign = (a0, a1) => (_emscripten_builtin_memalign = wasmExports['emscripten_builtin_memalign'])(a0, a1);
|
|
5414
|
-
var _ntohs = Module['_ntohs'] = (a0) => (_ntohs = Module['_ntohs'] = wasmExports['ntohs'])(a0);
|
|
5415
6579
|
var _memalign = Module['_memalign'] = (a0, a1) => (_memalign = Module['_memalign'] = wasmExports['memalign'])(a0, a1);
|
|
5416
6580
|
var ___trap = () => (___trap = wasmExports['__trap'])();
|
|
5417
6581
|
var stackSave = Module['stackSave'] = () => (stackSave = Module['stackSave'] = wasmExports['stackSave'])();
|