Expand description
Unix socket paths that fit, checked where names and directories are chosen.
A Unix socket address has a fixed-size path field, and the OS reports an
overflow only as an invalid argument, at bind or connect time, naming
neither the length nor the limit. A service usually derives several sockets
from one directory, so the one that overflows is often not the one anybody
checked. Here a name is checked when it is written, as a const, and a
directory once, against every socket it will hold.
use kunobi_daemon::socket_path::{SocketDir, SocketName};
const DAEMON: SocketName = SocketName::new("daemon.sock");
const CONTROL: SocketName = SocketName::new("daemon.ctl");
let dir = SocketDir::new("/tmp/kache-1f2e", &[DAEMON, CONTROL])?;
let control = dir.path(CONTROL)?;Windows names a pipe after the path, which has no such limit, so every check passes there.
Structs§
- Socket
Dir - A directory checked once against every socket it will hold.
- Socket
Name - A socket file name, checked when it is constructed.
Constants§
- MAX_
NAME_ BYTES - Longest socket name
SocketName::newaccepts. A name is a file name, not a place to spend the directory’s budget. - MAX_
SOCKET_ PATH_ BYTES - Longest Unix socket path, in bytes, on this platform:
sockaddr_un.sun_pathless the NUL that terminates it.Nonewhere local endpoints are not Unix sockets.
Functions§
- check_
socket_ path - Fails when
socketis too long to bind or connect to as a Unix socket. - max_
dir_ bytes - Longest directory, in bytes, that still fits every socket in
names, orNoneon a platform without the limit.