Expand description
Frames over a Unix socket: length-prefixed, so one read is one frame.
The server listens and each host connects. A profile’s service binds the socket before spawning its host, and a host that finds no socket keeps painting into its ring and tries again rather than failing.
Re-exports§
use std::io::ErrorKind;🔒use std::io::Read as _;🔒use std::io::Write as _;🔒use std::os::unix::net::UnixListener;🔒use std::os::unix::net::UnixStream;🔒use std::path::Path;🔒use std::path::PathBuf;🔒use std::sync::atomic::AtomicBool;🔒use std::sync::atomic::Ordering;🔒use std::sync::Arc;🔒use std::sync::Mutex;🔒use std::thread::JoinHandle;🔒use std::time::Duration;🔒use crate::frame::Frame;🔒
Structs§
- Audio
- One audio packet from the page: interleaved 16-bit PCM.
- Reader
- One profile’s frame reader, as the server holds it.
Enums§
- Channel
Message - One message from a host’s socket, as the server routes it.
- Filled 🔒
- What one
read_fullproduced. - Reception
- What one read from a host’s socket produced.
Constants§
- ACCEPT_
POLL 🔒 - How long the accept loop sleeps while no host is connected. One Hz: a host that dies leaves the reader idling until its relaunch, and a hundred wakeups a second for nothing was the cost of a 10 ms poll.
- KIND_
AUDIO - KIND_
FRAME - The kind byte a message’s body carries: one frame, or one audio packet.
- MAX_
FRAME_ LEN - The largest frame the channel accepts: a 4K lossless WebP fits under it, and anything past it is a corrupt length rather than a frame.
- READ_
POLL 🔒 - How long a read waits before the loop looks at its stop flag again.
- STALL 🔒
- How long a frame may stall mid-read before the connection is treated as gone. The host’s own write is bounded at two seconds, so five is a wedge.
- WRITE_
TIMEOUT 🔒 - How long a write may block before the host treats the reader as gone. It
bounds one syscall;
write()bounds the whole frame besides, so a reader draining a byte at a time cannot stretch a frame out for ever.
Functions§
- connect
- Connect to a profile’s socket as the writing side.
- frame_
socket_ path - The frame socket the server binds for one profile: a short path, with the server’s pid so two instances never share one.
- private_
dir - The private directory short sockets live in:
/tmp/forge-<uid>/. - read
- Read one message from a host’s socket.
- read_
connection 🔒 - Read one host connection until it closes or the profile’s reader stops.
- read_
full 🔒 - Fill
buffrom the stream. - serve
- Bind
pathand hand every frame a host writes tosink. - socket_
path - The socket a profile’s host writes frames to, under the profile itself.
- write
- Write one frame.
- write_
audio - Write one audio packet.
- write_
message 🔒 - Write one message: its length, its kind, then the body.