#!/usr/bin/env dub
/+ dub.sdl:
name "eh_signal"
dependency "sparkles:event-horizon" path="../../../../.."
buildType "checked" {
buildOptions "optimize" "inline" "debugInfo"
}
platforms "linux"
+/
import (package) corecore.(package) core.syssys.(package) core.sys.posixposix.(module) core.sys.posix.signalD header file for POSIX.
Source
core/sys/posix/signal.d
signal : (alias constant) eh_signal.SIGUSR1 = int core.sys.posix.signal.SIGUSR1 = 10SIGUSR1, (alias) eh_signal.kill = int core.sys.posix.signal.kill(int, int) nothrow @nogckill;
import (package) corecore.(package) core.syssys.(package) core.sys.posixposix.(module) core.sys.posix.unistdD header file for POSIX.
unistd : (alias) eh_signal.getpid = int core.sys.posix.unistd.getpid() nothrow @nogc @trustedgetpid;
import (package) stdstd.(module) std.stdioCategory Symbols File handles _popen File isFileHandle openNetwork stderr stdin stdout Reading chunks lines readf readfln readln Writing toFile write writef writefln writeln Misc KeepTerminator LockType StdioException
Standard I/O functions that extend core.stdc.stdio. core.stdc.stdio
is publically imported when importing std.stdio.
There are three layers of I/O:
The lowest layer is the operating system layer. The two main schemes are Windows and Posix.
C's stdio.h which unifies the two operating system schemes.
std.stdio, this module, unifies the various stdio.h implementations into
a high level package for D programs.
Source
std/stdio.d
stdio : (alias template) eh_signal.writeln = std.stdio.writeln(T...)(T args)Equivalent to write(args, '\n'). Calling writeln without
arguments is valid and just prints a newline to the standard
output.
Example
Reads stdin and writes it to stdout with an argument
counter.
import std.stdio;
void main()
{
string line;
for (size_t count = 0; (line = readln) !is null; count++)
{
writeln("Input ", count, ": ", line);
}
}
writeln;
import (package) sparklessparkles.(module) sparkles.event_horizonsparkles:event-horizon — the completion-first event loop with a native
algebraic-effect layer. This package module re-exports the public surface
(SPEC §16); import sparkles.event_horizon`` for the whole API, or a specific
module for a narrower dependency.
event_horizon;
void void D main()main()
{
(struct) sparkles.event_horizon.signals.SignalFdA signalfd bound to a blocked signal set.
SignalFd (local variable) sparkles.event_horizon.signals.SignalFd signalssignals;
if ((struct) sparkles.event_horizon.signals.SignalFdA signalfd bound to a blocked signal set.
SignalFd.sparkles.base.expected.Expected!(void, IoError, NoGcHook) sparkles.event_horizon.signals.SignalFd.create(out sparkles.event_horizon.signals.SignalFd s, scope const(int[]) signals) nothrow @nogc @trustedBlocks signals process-wide and opens a signalfd for them (the
standard signalfd discipline: blocked-then-read).
create((local variable) sparkles.event_horizon.signals.SignalFd signalssignals, [(constant) int core.sys.posix.signal.SIGUSR1 = 10SIGUSR1]).bool sparkles.base.expected.Expected!(void, sparkles.base.io.errors.IoError, sparkles.base.text.errors.NoGcHook).hasError!()() const pure nothrow @nogc @property @safeChecks if Expected has error
hasError)
assert(false, "signalfd unavailable");
(struct) sparkles.event_horizon.group.LoopGroupA running loop group. Non-copyable; owns its worker scheduler(s).
LoopGroup (local variable) sparkles.event_horizon.group.LoopGroup groupgroup;
if ((struct) sparkles.event_horizon.group.LoopGroupA running loop group. Non-copyable; owns its worker scheduler(s).
LoopGroup.sparkles.base.expected.Expected!(void, IoError, NoGcHook) sparkles.event_horizon.group.LoopGroup.start(out sparkles.event_horizon.group.LoopGroup group, in sparkles.event_horizon.group.LoopGroupConfig cfg = LoopGroupConfig(Topology.single, 0u, 256u, Flag.yes, Flag.yes, FiberPark.auto_, 256u, Flag.no))Probes the kernel and starts the group. io_uring probe failure is a
hard error (SPEC §3.4 — no epoll fallback).
start((local variable) sparkles.event_horizon.group.LoopGroup groupgroup).bool sparkles.base.expected.Expected!(void, sparkles.base.io.errors.IoError, sparkles.base.text.errors.NoGcHook).hasError!()() const pure nothrow @nogc @property @safeChecks if Expected has error
hasError)
assert(false, "no completion backend");
scope (exit) (local variable) sparkles.event_horizon.group.LoopGroup groupgroup.sparkles.base.expected.Expected!(void, IoError, NoGcHook) sparkles.event_horizon.group.LoopGroup.shutdown(core.time.Duration grace = dur(5L)) nothrow @trustedTears down the group's workers. A worker whose run a requested
shutdown's grace period outlived (requestShutdown) was leaked, not
freed (fiber-parker.md EFP21), and shutdown then returns ETIMEDOUT.
Idempotent.
shutdown();
auto (local variable) _error_ runrun = (local variable) sparkles.event_horizon.group.LoopGroup groupgroup.(void) voidrun((ref RootScope sc, ref Env env) {
ref Sched _error_ ss = currentScheduler();
assert(kill(getpid(), SIGUSR1) == 0);
auto _error_ gotgot = signals.nextSignal(s); // parks until the signal completes
assert(got.hasValue && got.value == SIGUSR1);
writeln("got signal ", got.value == SIGUSR1 ? "SIGUSR1" : "other");
return 0;
});
assert(run.hasValue);
}