Skip to main content

Module channel

Module channel 

Source
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§

ChannelMessage
One message from a host’s socket, as the server routes it.
Filled 🔒
What one read_full produced.
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 buf from the stream.
serve
Bind path and hand every frame a host writes to sink.
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.