@@ -38,7 +38,10 @@ Postgres server will listen on a Unix socket located at
3838` /run/postgresql/.s.PGSQL.5432 ` in some configurations. However, the
3939` socketpair ` function can make a pair of * unnamed* connected Unix sockets not
4040associated with a filesystem path. In addition, Linux provides a separate
41- * abstract* namespace not associated with the filesystem.
41+ * abstract* namespace not associated with the filesystem, indicated by a leading
42+ null byte in the address. In the initial implementation, the abstract namespace
43+ will not be supported - the various socket constructors will check for and
44+ reject addresses with interior null bytes.
4245
4346A ` std::os::unix::net ` module will be created with the following contents:
4447
@@ -51,11 +54,7 @@ pub struct UnixStream {
5154impl UnixStream {
5255 /// Connects to the socket named by `path`.
5356 ///
54- /// Linux provides, as a nonportable extension, a separate "abstract"
55- /// address namespace as opposed to filesystem-based addressing. If `path`
56- /// begins with a null byte, it will be interpreted as an "abstract"
57- /// address. Otherwise, it will be interpreted as a "pathname" address,
58- /// corresponding to a path on the filesystem.
57+ /// `path` may not contain any null bytes.
5958 pub fn connect <P : AsRef <Path >>(path : P ) -> io :: Result <UnixStream > {
6059 ...
6160 }
@@ -196,15 +195,6 @@ impl SocketAddr {
196195}
197196```
198197
199- A Linux-specific extension trait is provided for the abstract namespace:
200- ``` rust
201- pub trait SocketAddrExt {
202- /// Returns the contents of this address (without the leading null byte) if
203- /// it is an abstract address.
204- fn as_abstract (& self ) -> Option <& [u8 ]>
205- }
206- ```
207-
208198The ` UnixListener ` type mirrors the ` TcpListener ` type:
209199``` rust
210200pub struct UnixListener {
@@ -214,11 +204,7 @@ pub struct UnixListener {
214204impl UnixListener {
215205 /// Creates a new `UnixListener` bound to the specified socket.
216206 ///
217- /// Linux provides, as a nonportable extension, a separate "abstract"
218- /// address namespace as opposed to filesystem-based addressing. If `path`
219- /// begins with a null byte, it will be interpreted as an "abstract"
220- /// address. Otherwise, it will be interpreted as a "pathname" address,
221- /// corresponding to a path on the filesystem.
207+ /// `path` may not contain any null bytes.
222208 pub fn bind <P : AsRef <Path >>(path : P ) -> io :: Result <UnixListener > {
223209 ...
224210 }
@@ -294,11 +280,7 @@ pub struct UnixDatagram {
294280impl UnixDatagram {
295281 /// Creates a Unix datagram socket bound to the given path.
296282 ///
297- /// Linux provides, as a nonportable extension, a separate "abstract"
298- /// address namespace as opposed to filesystem-based addressing. If `path`
299- /// begins with a null byte, it will be interpreted as an "abstract"
300- /// address. Otherwise, it will be interpreted as a "pathname" address,
301- /// corresponding to a path on the filesystem.
283+ /// `path` may not contain any null bytes.
302284 pub fn bind <P : AsRef <Path >>(path : P ) -> io :: Result <UnixDatagram > {
303285 ...
304286 }
@@ -329,6 +311,8 @@ impl UnixDatagram {
329311 ///
330312 /// The `send` method may be used to send data to the specified address.
331313 /// `recv` and `recv_from` will only receive data from that address.
314+ ///
315+ /// `path` may not contain any null bytes.
332316 pub fn connect <P : AsRef <Path >>(& self , path : P ) -> io :: Result <()> {
333317 ...
334318 }
@@ -363,6 +347,8 @@ impl UnixDatagram {
363347 /// Sends data on the socket to the specified address.
364348 ///
365349 /// On success, returns the number of bytes written.
350+ ///
351+ /// `path` may not contain any null bytes.
366352 pub fn send_to <P : AsRef <Path >>(& self , buf : & [u8 ], path : P ) -> io :: Result <usize > {
367353 ...
368354 }
@@ -454,6 +440,8 @@ Differences from `UdpSocket`:
454440
455441Some functionality is notably absent from this proposal:
456442
443+ * Linux's abstract namespace is not supported. Functionality may be added in
444+ the future via extension traits in ` std::os::linux::net ` .
457445* No support for ` SOCK_SEQPACKET ` sockets is proposed, as it has not yet been
458446 implemented. Since it is connection oriented, there will be a socket type
459447 ` UnixSeqPacket ` and a listener type ` UnixSeqListener ` . The naming of the
@@ -481,15 +469,6 @@ The naming convention of `UnixStream` and `UnixDatagram` doesn't perfectly
481469mirror ` TcpStream ` and ` UdpSocket ` , but ` UnixStream ` and ` UnixSocket ` seems way
482470too confusing.
483471
484- Constructors for the various socket types take an ` AsRef<Path> ` , which makes
485- construction of sockets associated with Linux abstract namespaces somewhat
486- nonobvious, as the leading null byte has to be explicitly added. However, it is
487- still possible, either via ` &str ` for UTF8 names or via ` &OsStr ` and
488- ` std::os::unix::ffi::OsStrExt ` for arbitrary names. Use of the abstract
489- namespace appears to be very obscure, so it seems best to optimize for
490- ergonomics of normal pathname addresses. We can add extension traits providing
491- methods taking ` &[u8] ` in the future if deemed necessary.
492-
493472# Unresolved questions
494473[ unresolved ] : #unresolved-questions
495474
0 commit comments