summaryrefslogtreecommitdiffhomepage
path: root/lib/uloop.c
AgeCommit message (Collapse)Author
2024-04-25uloop: add documentationJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-02-21uloop: automatically clear error informationJo-Philipp Wich
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>
2023-11-03uloop: support new interval and signal APIsJo-Philipp Wich
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>
2023-10-09uloop: rename environ variable to avoid clashing with system macro on macOSFelix Fietkau
Signed-off-by: Felix Fietkau <nbd@nbd.name>
2023-08-09treewide: consolidate platform specific code in platform.cJo-Philipp Wich
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>
2023-07-27uloop: interrupt on VM signalsJo-Philipp Wich
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>
2022-11-29uloop: terminate parent uloop in task child processesJo-Philipp Wich
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>
2022-09-29uloop: task: gracefully handle absent output callbackJo-Philipp Wich
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>
2022-06-29uloop: end uloop on exceptions in managed codeJo-Philipp Wich
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>
2022-03-21uloop: add support for tasksJo-Philipp Wich
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>
2022-03-15uloop: use execvp() on OS XJo-Philipp Wich
Since `execvpe()` is a GNU extension, fall back to using `execve()` on OS X. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-03-06uloop: clear errno before integer conversion attemptsJo-Philipp Wich
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>
2022-03-02lib: introduce uloop bindingJo-Philipp Wich
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>