Age | Commit message (Collapse) | Author |
|
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
Make all functions clear the last error information on success in order to
ensure that `error()` never reports stale information.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
Add bindings for the new uloop interval and signal handling APIs and extend
the CMake logic to properly detect the presence of these facilities.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
Signed-off-by: Felix Fietkau <nbd@nbd.name>
|
|
Get rid of most __APPLE__ guards by introducing a central platform.c unit
providing drop-in replacements for missing APIs.
Also move system signal definitions into the new platform file to be able
to share them with the upcoming debug library.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
When the VM instance loading the uloop module has signal dispatching
enabled, implicitly register the signal pipe as file descriptor in the
global uloop and dispatch received signals to the VM instance.
This ensures that the respective managed ucode signal handlers are
invoked immediately and not just after `uloop_run()` returns.
Also end the uloop in case any invoked signal handler threw an
exception, to match the expected behaviour with other kinds of
callbacks.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
Ensure that the main process uloop is terminated within task child
processes. Before this fix, using uloop in a task function would
trigger invalid memory accesses in the parent process by notifying
non-existing fd slots in the parent through the inherited shared
epoll descriptor.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
Both input and output callbacks for uloop tasks are optional, but the
low level io callback implementation did not properly deal with an absent
ucode output callback, triggering an exception in managed code due to
invoking a null value as function.
Fix this issue by checking for the availability of a callable output
function and simply discarding the received task message otherwise.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
Instead of silently continuing, end the uloop when encountering exceptions
in ucode callbacks to let those exceptions propagate to the host program.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
Tasks are similar to processes but instead of executing a new process, an
ucode function is invoked instead, running independently of the main
process.
Example usage:
uloop.init();
let t = uloop.task(
// program function
function(pipe) {
let input = pipe.receive();
pipe.send({ got_input: input });
return { result: true };
},
// parent recv function, invoked when task function calls pipe.send()
function(res) {
printf("Received output message: %.J\n", res);
},
// parent send function, invoked when task function calls pipe.receive()
function() {
let input = { test: "Example" };
printf("Sending input message: %.J\n", input);
return input;
}
);
uloop.run();
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
Since `execvpe()` is a GNU extension, fall back to using `execve()` on OS X.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
In some cases, errno contains stale values from prior function invocations
which might lead to random failures in uc_uloop_run(), uc_uloop_timer_set()
and uc_uloop_timer().
Solve this issue by explicitly initializing errno to 0.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
The uloop module allows controlling the uloop event loop and supports adding
timeouts, processes and file descriptors.
Example:
#!ucode -RS
let fs = require("fs");
let uloop = require("uloop");
let fd1 = fs.popen("echo 1; sleep 1; echo 2; sleep 1; echo 3", "r");
let fd2 = fs.popen("echo 4; sleep 1; echo 5; sleep 1; echo 6", "r");
function fd_read_callback(flags) {
if (flags & uloop.ULOOP_READ) {
let line = this.handle().read("line");
printf("Line from fd <%s/%d>: <%s>\n",
this, this.fileno(),
trim(line));
}
}
uloop.init();
uloop.timer(1500, function() {
printf("Timeout after 1500ms\n");
});
uloop.handle(fd1, fd_read_callback, uloop.ULOOP_READ);
uloop.handle(fd2, fd_read_callback, uloop.ULOOP_READ);
uloop.process("date", [ "+%s" ], { LC_ALL: "C" }, function(exitcode) {
printf("Date command exited with code %d\n", exitcode);
});
uloop.run();
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|