Description
openedon May 17, 2021
Feature gate: #![feature(unix_socket_abstract)]
This is a tracking issue for adding abstract namespace support for Unix domain sockets on Linux.
Traditionally, Unix domain sockets (UDS) use a file to coordinate socket binding and connecting. On Linux, though, a specific extension exists to allow domain sockets to be created from a namespace which does not use the filesystem. With these changes, we extend Rust's UDS support to create sockets directly from a SocketAddr
which can be itself used to create an abstract namespace.
More information
Previous discussion: #42048
Linux man page: unix(7)
Public API
Non-platform specific additions
UnixListener::bind_addr(&SocketAddr) -> Result<UnixListener>
UnixStream::connect_addr(&SocketAddr) -> Result<()>
UnixDatagram::bind_addr(&SocketAddr) -> Result<UnixDatagram>
UnixDatagram::connect_addr(&SocketAddr) -> Result<()>
UnixDatagram::send_to_addr(&self, &[u8], &SocketAddr) -> Result<usize>
Platform-specific (Linux) additions
SocketAddrExt::from_abstract_name(&[u8]) -> Result<SocketAddr>
SockerAddrExt::as_abstract_name(&self) -> Option<&[u8]>
Example
#![feature(unix_socket_abstract)]
use std::os::unix::net::{UnixListener, SocketAddr};
use std::os::linux::net::SocketAddrExt;
fn main() -> std::io::Result<()> {
let addr = SocketAddr::from_abstract_namespace(b"namespace")?; // Linux only
let listener = match UnixListener::bind_addr(&addr) {
Ok(sock) => sock,
Err(err) => {
println!("Couldn't bind: {:?}", err);
return Err(err);
}
};
Ok(())
}
Steps / History
- Implementation: Add abstract namespace support for Unix domain sockets #85379
- Rework to use an extension trait: Move
unix_socket_abstract
feature API toSocketAddrExt
. #101967 - Final commenting period (FCP)
- Stabilization PR
Unresolved Questions
- None yet.