# `Alternera.PluginWasmFramework.Runtime.Port`
[🔗](https://github.com/10e-ab/alternera-wasm/blob/v0.9.1/alternera_plugin_wasm_framework/lib/alternera/plugin_wasm_framework/runtime/port.ex#L1)

`PluginWasmFramework.Runtime` in OS processes: the package's own host
program, `alternera_wasm_host` (`native/alternera_wasm_host/`, Wasmtime
51.0.0, the version wasmex 0.18.1 carries), run as Erlang ports by
`Runtime.Port.Pool`. A fault, a hang or a compiler bug costs one OS
process, never the node.

    config :alternera_plugin_wasm_framework, runtime: :port

`prepare/1` compiles in a process of its own into the node's cache of
compiled modules (`Runtime.Port.Compiler`) and answers a handle to the
file. `call/5`:

  1. checks a process out of the pool (the caller becomes its port's
     owner), or, for a call made while a holder up the caller's chain is
     parked in a host call, borrows that holder's port
     (`Pool.held_port/0`): a nested call runs in a second instance in the
     same process. The port is lent only for the host call's length,
     and taken back only once every borrow deeper ended (`Pool.lend/3`,
     `Pool.reclaim/4`);
  2. takes a slot (`PluginWasmFramework.Slots`);
  3. sends one `C` frame and serves what the guest asks for until its
     result: host calls with `host.call` (the slot goes back meanwhile,
     as with wasmex), body pieces with `host.body`, and growth past the
     call's free floor, claimed through `Plugin.Host.claim_held_bytes/2`
     when the limits say `claim: true`;
  4. hands the port back. The host drops the instance after it answered,
     so Wasmtime resets its slot while the node already has the result.

The time a slot is held is the guest's running time, reported as
`guest_us`: the guest's work outside the BEAM, which its reductions
leave out.

A module a process has not loaded answers "not loaded" and is loaded
from its compiled file and called again, once. The host interrupts a
guest at its deadline itself (an epoch ticker on a thread of its own) and
answers a time-out; past the deadline the caller cancels a host call it
cannot resume, and kills the OS process when no result came
`@backstop_ms` after the deadline (or after its last answer, when a host
call ran past the deadline). A host function that raises or exits kills
the process too, since its guest waits for an answer that will not come,
and the error goes on.

# `t`

```elixir
@type t() :: %Alternera.PluginWasmFramework.Runtime.Port{
  digest: String.t(),
  initialize?: boolean(),
  path: Path.t(),
  raw: binary()
}
```

A compiled module: its digest (hex and raw) and its compiled file.

# `free_bytes`

```elixir
@spec free_bytes() :: non_neg_integer()
```

The bytes of guest memory a call may take before its growth is claimed
(`:guest_free_mib` in the framework's env, 8: the Body × floor).

---

*Consult [api-reference.md](api-reference.md) for complete listing*
