Expand description
Local (Unix-domain) sockets named by a path of any length. The kernel takes a
socket’s path in a fixed buffer (sun_path: 108 bytes on Linux, 104 on macOS), so a
socket in a deep enough directory cannot be bound or reached by its path at all; a
path that does not fit is reached through its directory, opened first and named by
its descriptor (/proc/self/fd/<fd>/<name>), so only the socket’s own name has to
fit. A path that fits is used as it is. Elsewhere than Linux and Android a path that
does not fit is refused with io::ErrorKind::InvalidInput naming the limit, never
silently.
Windows names a local service with a named pipe instead (windows): the same
bind, connect, Listener and Stream, kept to this account by the
pipe’s DACL and a check of the peer’s token. [tokio] is the same for an async
caller.
On Unix the crate adds nothing to std but libc for one call: three bytes of a
peek, so a server can tell a client that left from one still there. The
tilo_files::native::socket re-export and a tool that must stay small to start
quickly (the cargo desktop launcher) bind and connect through the same code
without taking on a dependency graph.
Re-exports§
pub use datagram::Datagram;pub use descriptor::Descriptor;
Modules§
- datagram
- Two connected ends that carry whole datagrams: a Unix datagram socket pair, or on Windows a
pipe only this process joined ([
crate::link::pair]) with each datagram written behind its length, so a datagram is read whole however the pipe splits its bytes. A caller hands one end to a process or thread it starts and keeps the other; [crate::tokio::Datagram] drives an end on a runtime. - descriptor
- A descriptor a local connection carries: an open file, or one end of a connection.
Structs§
- Socket
Addr - An address associated with a Unix socket.
Constants§
- MAX_
PATH - The longest socket path the kernel takes, without its terminating NUL.
Functions§
- bind
- Listens on a new socket at
path, whatever its length. - connect
- Connects to the socket at
path, whatever its length. - connected
- Whether the peer at the other end of
streamis still connected, without consuming what it sent: a peek that finds the connection over says it is not, and one that finds bytes waiting or nothing yet says it is. - is_
bound - Whether something is bound at
pathnow, without connecting to it: a socket file on Unix, a pipe with an instance on Windows. One a run left behind on Unix still reads as bound;connectsays whether it answers. - pair
- Two connected ends, both in this process: one is handed to another process or thread, as a
connection made without a listener. A Unix stream pair; on Windows a pipe only this process
joined ([
link::pair]), which reads as a byte stream as a socket does. - peek
- What the peer at the other end of
streamhas sent so far, up tobuffer’s length, without consuming it: the next read gets the same bytes. Waits up towithinfor the first of them;0when the peer sent nothing by then, or closed.