@@ -38,7 +38,10 @@ Postgres server will listen on a Unix socket located at
38
38
` /run/postgresql/.s.PGSQL.5432 ` in some configurations. However, the
39
39
` socketpair ` function can make a pair of * unnamed* connected Unix sockets not
40
40
associated 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.
42
45
43
46
A ` std::os::unix::net ` module will be created with the following contents:
44
47
@@ -51,11 +54,7 @@ pub struct UnixStream {
51
54
impl UnixStream {
52
55
/// Connects to the socket named by `path`.
53
56
///
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.
59
58
pub fn connect <P : AsRef <Path >>(path : P ) -> io :: Result <UnixStream > {
60
59
...
61
60
}
@@ -196,15 +195,6 @@ impl SocketAddr {
196
195
}
197
196
```
198
197
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
-
208
198
The ` UnixListener ` type mirrors the ` TcpListener ` type:
209
199
``` rust
210
200
pub struct UnixListener {
@@ -214,11 +204,7 @@ pub struct UnixListener {
214
204
impl UnixListener {
215
205
/// Creates a new `UnixListener` bound to the specified socket.
216
206
///
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.
222
208
pub fn bind <P : AsRef <Path >>(path : P ) -> io :: Result <UnixListener > {
223
209
...
224
210
}
@@ -294,11 +280,7 @@ pub struct UnixDatagram {
294
280
impl UnixDatagram {
295
281
/// Creates a Unix datagram socket bound to the given path.
296
282
///
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.
302
284
pub fn bind <P : AsRef <Path >>(path : P ) -> io :: Result <UnixDatagram > {
303
285
...
304
286
}
@@ -329,6 +311,8 @@ impl UnixDatagram {
329
311
///
330
312
/// The `send` method may be used to send data to the specified address.
331
313
/// `recv` and `recv_from` will only receive data from that address.
314
+ ///
315
+ /// `path` may not contain any null bytes.
332
316
pub fn connect <P : AsRef <Path >>(& self , path : P ) -> io :: Result <()> {
333
317
...
334
318
}
@@ -363,6 +347,8 @@ impl UnixDatagram {
363
347
/// Sends data on the socket to the specified address.
364
348
///
365
349
/// On success, returns the number of bytes written.
350
+ ///
351
+ /// `path` may not contain any null bytes.
366
352
pub fn send_to <P : AsRef <Path >>(& self , buf : & [u8 ], path : P ) -> io :: Result <usize > {
367
353
...
368
354
}
@@ -454,6 +440,8 @@ Differences from `UdpSocket`:
454
440
455
441
Some functionality is notably absent from this proposal:
456
442
443
+ * Linux's abstract namespace is not supported. Functionality may be added in
444
+ the future via extension traits in ` std::os::linux::net ` .
457
445
* No support for ` SOCK_SEQPACKET ` sockets is proposed, as it has not yet been
458
446
implemented. Since it is connection oriented, there will be a socket type
459
447
` UnixSeqPacket ` and a listener type ` UnixSeqListener ` . The naming of the
@@ -481,15 +469,6 @@ The naming convention of `UnixStream` and `UnixDatagram` doesn't perfectly
481
469
mirror ` TcpStream ` and ` UdpSocket ` , but ` UnixStream ` and ` UnixSocket ` seems way
482
470
too confusing.
483
471
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
-
493
472
# Unresolved questions
494
473
[ unresolved ] : #unresolved-questions
495
474
0 commit comments