Skip to content

Commit

Permalink
net: add handling for abstract socket name
Browse files Browse the repository at this point in the history
  • Loading branch information
mox692 committed Aug 13, 2024
1 parent 1077b0b commit 00d08ac
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions tokio/src/net/unix/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ use crate::net::unix::split_owned::{split_owned, OwnedReadHalf, OwnedWriteHalf};
use crate::net::unix::ucred::{self, UCred};
use crate::net::unix::SocketAddr;

use std::ffi::OsStr;
use std::fmt;
use std::io::{self, Read, Write};
use std::net::Shutdown;
use std::os::unix::ffi::OsStrExt;
use std::os::unix::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, RawFd};
use std::os::unix::net;
use std::os::unix::net::{self, SocketAddr as StdSocketAddr};
use std::path::Path;
use std::pin::Pin;
use std::task::{Context, Poll};
Expand Down Expand Up @@ -66,7 +68,15 @@ impl UnixStream {
where
P: AsRef<Path>,
{
let stream = mio::net::UnixStream::connect(path)?;
use std::os::linux::net::SocketAddrExt;
let os_str_bytes = path.as_ref().as_os_str().as_bytes();

let addr = if os_str_bytes.starts_with(b"\0") {
StdSocketAddr::from_abstract_name(os_str_bytes)?
} else {
StdSocketAddr::from_pathname(path)?
};
let stream = mio::net::UnixStream::connect_addr(&addr)?;
let stream = UnixStream::new(stream)?;

poll_fn(|cx| stream.io.registration().poll_write_ready(cx)).await?;
Expand Down

0 comments on commit 00d08ac

Please sign in to comment.