Replies: 6 comments 3 replies
-
Have you started with some of the examples? It's not clear from your question where the server is running - is in a moddable host? Here is a pull request with an example that implements a websocket on a moddable host with a browser front end that might be useful for you: |
Beta Was this translation helpful? Give feedback.
-
Yes it is in a moddable host, running in the CLI mode, not in the
simulator! That's where the problem is, as the program terminates
immediately after initialization. No errors however, and server is running
for a moment!
I am looking for a way to keep the event processing indefinitely....
Thanks!
Chris
…On Fri., Feb. 18, 2022, 6:22 p.m. wilberforce ***@***.***> wrote:
Have you started with some of the examples?
It's not clear from your question where the server is running - is in a
moddable host?
Here is a pull request with an example that implements a websocket on a
moddable host with a browser front end that might be useful for you:
#755 <#755>
—
Reply to this email directly, view it on GitHub
<#850 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AE6FESFEDNNS4YOFJE3VX2LU33IELANCNFSM5OZCUVAA>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
You are receiving this because you authored the thread.Message ID:
***@***.***
.com>
|
Beta Was this translation helpful? Give feedback.
-
NOTE: This is a special x-cli-lin target which did not exist before, and NOT run in the simulator. It is compiled without -fPIC and -shared, as a linux executable linked to the various shared libraries of XS. Main.c does the job the simulator would do to load the machine and setup a basic event loop. Don't take this code as gospel because it is a work in progress. But it works. There are a number of other hacks required to allow running without the simulator that I won't get into now, but they are #include's, minor #define's and replacements of a couple functions. In addition, I updated the http module in my case, which needed refactoring to accommodate callbacks (promises didn't work) so that workers could asynchrnously post back http and websocket responses that integrate into the regular this.state and message progression of callbacks within those modules. I have finally solved the issue of the event loop using glib, to keep the main machine running and allow compartments and workers to do their job with network and other IO. Without the event loop, Timers and promises will not work, as there is no way to stop the control flow from ending on the main thread. The key section for the event loop is:
I am not certain on the correctness of the machine loading code, but it is based on the simulator code. However it is working for now, though I have a segmentation fault happening inside a worker, which may or may not be related. Memory may need to be released properly on the machine. Instrumentation is disabled here, but can be restored with the appropriate includes, as the xsbug and full debugging capability is enabled under this scheme! ----------------------------------- main.c ----------------------------------
#include "xsAll.h"
#include "mc.xs.h"
#include "xs.h"
#include "xsHost.h"
extern txPreparation* xsPreparation;
/**/
void fxAbort(xsMachine* the, int status)
{
exit(status);
}
int main(int argc, char* argv[])
{
fprintf(stdout, "%s\n", "Starting Server");
static txMachine root;
int error = 0;
txMachine* machine = &root;
txPreparation* preparation = xsPreparation();
c_memset(machine, 0, sizeof(txMachine));
machine->preparation = preparation;
machine->keyArray = preparation->keys;
machine->keyCount = (txID)preparation->keyCount + (txID)preparation->creation.keyCount;
machine->keyIndex = (txID)preparation->keyCount;
machine->nameModulo = preparation->nameModulo;
machine->nameTable = preparation->names;
machine->symbolModulo = preparation->symbolModulo;
machine->symbolTable = preparation->symbols;
machine->stack = &preparation->stack[0];
machine->stackBottom = &preparation->stack[0];
machine->stackTop = &preparation->stack[preparation->stackCount];
machine->firstHeap = &preparation->heap[0];
machine->freeHeap = &preparation->heap[preparation->heapCount - 1];
machine->aliasCount = (txID)preparation->aliasCount;
machine = fxCloneMachine(&preparation->creation, machine, "tool", NULL);
//#ifdef mxInstrument
// fxDescribeInstrumentation(machine, 0, NULL, NULL);
//#endif
xsBeginHost(machine);
{
xsVars(2);
//#ifdef mxInstrument
// fxSampleInstrumentation(the, 0, NULL);
//#endif
{
xsTry {
xsResult = xsAwaitImport("main", XS_IMPORT_NAMESPACE);
}
xsCatch {
xsStringValue message = xsToString(xsException);
fprintf(stderr, "### %s\n", message);
error = 1;
}
}
GMainContext* main_context = g_main_context_default();
GMainLoop* main_loop = g_main_loop_new(main_context, FALSE);
g_main_loop_run(main_loop);
}
xsEndHost(the);
xsDeleteMachine(machine);
return error;
} |
Beta Was this translation helpful? Give feedback.
-
Thank-you! The placement of the event loop was indeed the issue. The application is now running with promises, workers, and nicely multi-threaded RSA and AES encryption/decryption workloads for authentication purposes on my Vultr cloud servers under Debian. I am connecting 100 WebSocket connections concurrently (with 100 compartments running separate 100 workers for crypto), and it is using less than 5MB ram, with a 2MB standalone executable. This is going places. Is there any reason I should be hitting a limit at about 106-128 compartments/workers? The next steps are:
Thanks again to those who guided me in the right directions and provided help making the Linux CLI target possible! Regards, Chris Batt |
Beta Was this translation helpful? Give feedback.
-
Congratulations on getting that working! XS is remarkably light.
No reason. What are you seeing?
Why not just use JavaScript's built-in |
Beta Was this translation helpful? Give feedback.
-
I have updated the encryption to using BigInt and have seen a remarkable improvement of about 80x! The connection limits I was seeing may have been due to browser/network stack limits on the client side, not XS. |
Beta Was this translation helpful? Give feedback.
-
How to I keep the event loop running in a CLI target (which I have successfully created for Linux), so that my server can stay alive to handle requests? Solution either in JS or C please. Without the simulator running, it doesn't happen, for some reason loading the .so in the simulator keeps it all alive and my server works fine, even for persistent WebSocket connections.
I have tried looping while(1){}, which obviously doesn't work, and also looping an IO bound asynchronous task of several types.
Also tried running the server on another thread in a Worker, and that doesn't work either.
Requests to the server ARE being connected on the socket when I use sleep(10) and then die after 10 seconds, to be expected, so the server part is listening while it lasts. But my JS code event handlers for the requests don't run because of the sleep.
Thanks all....
Beta Was this translation helpful? Give feedback.
All reactions