rust/library/std/src/os
bors 6cc0a764e0 Auto merge of #85379 - mdaverde:uds-abstract, r=joshtriplett
Add abstract namespace support for Unix domain sockets

Hello! The other day I wanted to mess around with UDS in Rust and found that abstract namespaces ([unix(7)](https://man7.org/linux/man-pages/man7/unix.7.html)) on Linux still needed development. I took the approach of adding `_addr` specific public functions to reduce conflicts.

Feature name: `unix_socket_abstract`
Tracking issue: #85410
Further context: #42048

## 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

`SocketAddr::from_abstract_namespace(&[u8]) -> SocketAddr`

`SockerAddr::as_abstract_namespace() -> Option<&[u8]>`

## Example

```rust
#![feature(unix_socket_abstract)]
use std::os::unix::net::{UnixListener, SocketAddr};

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(())
}
```

## Further Details

The main inspiration for the implementation came from the [nix-rust](https://github.com/nix-rust/nix/blob/master/src/sys/socket/addr.rs#L558) crate but there are also other [historical](c4db0685b1) [attempts](https://github.com/tormol/uds/blob/master/src/addr.rs#L324) with similar approaches.

A comment I did have was with this change, we now allow a `SocketAddr` to be constructed explicitly rather than just used almost as a handle for the return of `peer_addr` and `local_addr`. We could consider adding other explicit constructors (e.g. `SocketAddr::from_pathname`, `SockerAddr::from_unnamed`).

Cheers!
2021-10-15 22:31:53 +00:00
..
android Switch to intra-doc links in library/std/src/os/*/fs.rs 2020-08-11 15:20:01 +05:30
dragonfly Switch to intra-doc links in library/std/src/os/*/fs.rs 2020-08-11 15:20:01 +05:30
emscripten Remove an invalid #[doc(inline)] 2021-05-11 00:03:44 +02:00
espidf STD support for the ESP-IDF framework 2021-08-10 12:09:00 +03:00
fd Fix doc test failures on Windows. 2021-08-19 16:15:29 -07:00
fortanix_sgx Rollup merge of #85054 - jethrogb:jb/sgx-inline-asm, r=Amanieu 2021-06-22 07:37:42 +09:00
freebsd Auto merge of #74576 - myfreeweb:freebsd-sanitizers, r=oli-obk 2020-08-15 11:38:24 +00:00
fuchsia Switch to intra-doc links in library/std/src/os/*/fs.rs 2020-08-11 15:20:01 +05:30
haiku Deprecate std::os::haiku::raw 2021-03-16 17:43:33 -04:00
hermit Move OsStringExt and OsStrExt to std::os 2021-06-20 11:55:01 +02:00
illumos Switch to intra-doc links in library/std/src/os/*/fs.rs 2020-08-11 15:20:01 +05:30
ios Switch to intra-doc links in library/std/src/os/*/fs.rs 2020-08-11 15:20:01 +05:30
linux Auto merge of #88321 - glaubitz:m68k-linux, r=wesleywiser 2021-09-20 07:21:05 +00:00
macos Switch to intra-doc links in library/std/src/os/*/fs.rs 2020-08-11 15:20:01 +05:30
netbsd Switch to intra-doc links in library/std/src/os/*/fs.rs 2020-08-11 15:20:01 +05:30
openbsd Switch to intra-doc links in library/std/src/os/*/fs.rs 2020-08-11 15:20:01 +05:30
raw Suppress some cfg from being shown in the stdlib docs 2021-10-05 18:15:29 +02:00
redox Cleanup std::os 2021-05-03 16:56:20 +02:00
solaris Switch to intra-doc links in library/std/src/os/*/fs.rs 2020-08-11 15:20:01 +05:30
solid Add SOLID targets 2021-09-28 11:31:47 +09:00
unix Auto merge of #85379 - mdaverde:uds-abstract, r=joshtriplett 2021-10-15 22:31:53 +00:00
vxworks Take sys/vxworks/{fd,fs,io} from sys/unix instead. 2020-10-16 06:19:00 +02:00
wasi modify std::os docs to be more consistent 2021-09-17 23:23:21 +05:30
windows Suppress some cfg from being shown in the stdlib docs 2021-10-05 18:15:29 +02:00
mod.rs Add SOLID targets 2021-09-28 11:31:47 +09:00