eh_signal.dhover×37all
#!/usr/bin/env dub
/+ dub.sdl:
    name "eh_signal"
    dependency "sparkles:event-horizon" path="../../../../.."
    buildType "checked" {
        buildOptions "optimize" "inline" "debugInfo"
    }
    platforms "linux"
+/
import 
(package) core
core
.
(package) core.sys
sys
.
(package) core.sys.posix
posix
.
(module) core.sys.posix.signal

D header file for POSIX.

Source

core/sys/posix/signal.d

@copyrightCopyright Sean Kelly 2005 - 2009.@licenseBoost License 1.0@authorsSean Kelly, Alex Rønne Petersen@standardsThe Open Group Base Specifications Issue 6, IEEE Std 1003.1, 2004 Edition
signal
:
(alias constant) eh_signal.SIGUSR1 = int core.sys.posix.signal.SIGUSR1 = 10
SIGUSR1
,
(alias) eh_signal.kill = int core.sys.posix.signal.kill(int, int) nothrow @nogc
kill
;
import
(package) core
core
.
(package) core.sys
sys
.
(package) core.sys.posix
posix
.
(module) core.sys.posix.unistd

D header file for POSIX.

@copyrightCopyright Sean Kelly 2005 - 2009.@licenseBoost License 1.0.@authorsSean Kelly@standardsThe Open Group Base Specifications Issue 8, IEEE Std 1003.1, 2024 Edition
unistd
:
(alias) eh_signal.getpid = int core.sys.posix.unistd.getpid() nothrow @nogc @trusted
getpid
;
import
(package) std
std
.
(module) std.stdio
Category 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:

  1. The lowest layer is the operating system layer. The two main schemes are Windows and Posix.

  2. C's stdio.h which unifies the two operating system schemes.

  3. std.stdio, this module, unifies the various stdio.h implementations into a high level package for D programs.

Source

std/stdio.d

@copyrightCopyright The D Language Foundation 2007-.@licenseBoost License 1.0.@authorsWalter Bright, Andrei Alexandrescu, Alex Rønne Petersen
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);
    }
}
@paramargs the items to write to stdout@throwsIn case of an I/O error, throws an StdioException.
writeln
;
import
(package) sparkles
sparkles
.
(module) sparkles.event_horizon

sparkles: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.SignalFd

A signalfd bound to a blocked signal set.

SignalFd
(local variable) sparkles.event_horizon.signals.SignalFd signals
signals
;
if (
(struct) sparkles.event_horizon.signals.SignalFd

A 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 @trusted

Blocks signals process-wide and opens a signalfd for them (the standard signalfd discipline: blocked-then-read).

create
(
(local variable) sparkles.event_horizon.signals.SignalFd signals
signals
, [
(constant) int core.sys.posix.signal.SIGUSR1 = 10
SIGUSR1
]).
bool sparkles.base.expected.Expected!(void, sparkles.base.io.errors.IoError, sparkles.base.text.errors.NoGcHook).hasError!()() const pure nothrow @nogc @property @safe

Checks if Expected has error

hasError
)
assert(false, "signalfd unavailable");
(struct) sparkles.event_horizon.group.LoopGroup

A running loop group. Non-copyable; owns its worker scheduler(s).

LoopGroup
(local variable) sparkles.event_horizon.group.LoopGroup group
group
;
if (
(struct) sparkles.event_horizon.group.LoopGroup

A 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 group
group
).
bool sparkles.base.expected.Expected!(void, sparkles.base.io.errors.IoError, sparkles.base.text.errors.NoGcHook).hasError!()() const pure nothrow @nogc @property @safe

Checks if Expected has error

hasError
)
assert(false, "no completion backend"); scope (exit)
(local variable) sparkles.event_horizon.group.LoopGroup group
group
.
sparkles.base.expected.Expected!(void, IoError, NoGcHook) sparkles.event_horizon.group.LoopGroup.shutdown(core.time.Duration grace = dur(5L)) nothrow @trusted

Tears 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_ run
run
=
(local variable) sparkles.event_horizon.group.LoopGroup group
group
.
(void) void
run
((ref RootScope sc, ref Env env) {
ref Sched
_error_ s
s
= currentScheduler();
assert(kill(getpid(), SIGUSR1) == 0); auto
_error_ got
got
= 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); }