App::OpenHAP::Host(3p) Perl Library Manual App::OpenHAP::Host(3p)

App::OpenHAP::Host - the host of the Protocol::HAP engine

    use App::OpenHAP::Host;
    my $server = App::OpenHAP::Host->new(
        port         => 51827,
        pin          => '123-45-678',
        name         => 'My Bridge',
        storage_path => '/var/db/openhapd',
    );
    $server->add_accessory($accessory);
    $server->update_config_number;
    $server->run;    # returns when a signal stops the loop
    $server->shutdown;

This module hosts the sans-IO Protocol::HAP::Server engine on OpenBSD-style daemon plumbing. The engine owns the protocol; this module owns everything the operating system hands out: the listening socket, per-connection reads and writes, the event loop and its timers, the MQTT client, and the mDNS advertisement.

The host builds the engine over "Protocol::HAP::Store::File", the process default logger, an output contract that writes through the connection map, the one-shot timers of Fugu::EventLoop, and an "on_pairing_changed" hook that re-advertises the mDNS TXT record.

Each connection is filed under its session id: the session and its socket together. A fileno index resolves reads to the session id. The kernel reuses descriptors; session ids never repeat.

"port", "pin", "name", "storage_path", and "setup_id".

engine()

The Protocol::HAP::Server engine of this host.

run(), shutdown(), listen()

The service lifecycle. "run" serves until a signal ends the loop; "shutdown" closes the listener and every client connection afterwards.

Attach the MQTT client and the mDNS handle. The MQTT client ticks on the loop and reconnects on its own schedule; the mDNS handle receives a fresh TXT record when the engine reports a pairing change.

mdns_txt_string()

The TXT records of the engine in the format that mdnsd publishes, through "Fugu::Mdnsd::format_txt".

Pass-throughs to the engine, for "bin/openhapd" and the device loader.

control_status(), control_devices()

What the control socket answers: engine introspection composed with host state (uptime, MQTT, mDNS, connection count). Nothing here is a secret.

Protocol::HAP::Server, Protocol::HAP::Store::File, openhapd(8), hapctl(8)

2026-08-18 OpenBSD