pub struct SharedState {
pub tx_ring: ArrayQueue<Vec<u8>>,
pub rx_ring: ArrayQueue<Vec<u8>>,
pub rx_wake: WakePipe,
pub tx_wake: WakePipe,
pub proxy_wake: WakePipe,
/* private fields */
}Expand description
All shared state between the three threads:
- NetWorker (libkrun) — pushes guest frames to
tx_ring, pops response frames fromrx_ring. - smoltcp poll thread — pops from
tx_ring, processes through smoltcp, pushes responses torx_ring. - tokio proxy tasks — relay data between smoltcp sockets and real network connections.
Queue naming follows the guest’s perspective (matching libkrun’s
convention): tx_ring = “transmit from guest”, rx_ring = “receive at
guest”.
Fields§
§tx_ring: ArrayQueue<Vec<u8>>Frames from guest → smoltcp (NetWorker writes, smoltcp reads).
rx_ring: ArrayQueue<Vec<u8>>Frames from smoltcp → guest (smoltcp writes, NetWorker reads).
rx_wake: WakePipeWakes NetWorker: “rx_ring has frames for the guest.”
Written by SmoltcpDevice::transmit(). Read end polled by NetWorker’s
epoll loop.
tx_wake: WakePipeWakes smoltcp poll thread: “tx_ring has frames from the guest.”
Written by SmoltcpBackend::write_frame(). Read end polled by the
poll loop.
proxy_wake: WakePipeWakes smoltcp poll thread: “proxy task has data to write to a smoltcp socket.” Written by proxy tasks via channels. Read end polled by the poll loop.
Implementations§
Sourcepub fn set_termination_hook(&self, hook: Arc<dyn Fn() + Send + Sync>)
pub fn set_termination_hook(&self, hook: Arc<dyn Fn() + Send + Sync>)
Install a host-side termination hook.
Sourcepub fn trigger_termination(&self)
pub fn trigger_termination(&self)
Trigger host-side termination if a hook is installed.
Sourcepub fn add_tx_bytes(&self, bytes: usize)
pub fn add_tx_bytes(&self, bytes: usize)
Increment the guest -> runtime byte counter.
Sourcepub fn add_rx_bytes(&self, bytes: usize)
pub fn add_rx_bytes(&self, bytes: usize)
Increment the runtime -> guest byte counter.