Skip to content

Commit 365269a

Browse files
committed
Merge 'tokio-1.39.x' into master (#6788)
2 parents 5ea3c63 + 3d439ab commit 365269a

File tree

7 files changed

+65
-7
lines changed

7 files changed

+65
-7
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Make sure you activated the full features of the tokio crate on Cargo.toml:
5656

5757
```toml
5858
[dependencies]
59-
tokio = { version = "1.39.2", features = ["full"] }
59+
tokio = { version = "1.39.3", features = ["full"] }
6060
```
6161
Then, on your main.rs:
6262

tokio/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# 1.39.3 (August 17th, 2024)
2+
3+
This release fixes a regression where the unix socket api stopped accepting
4+
the abstract socket namespace. ([#6772])
5+
6+
[#6772]: https://github.com/tokio-rs/tokio/pull/6772
7+
18
# 1.39.2 (July 27th, 2024)
29

310
This release fixes a regression where the `select!` macro stopped accepting

tokio/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ name = "tokio"
66
# - README.md
77
# - Update CHANGELOG.md.
88
# - Create "v1.x.y" git tag.
9-
version = "1.39.2"
9+
version = "1.39.3"
1010
edition = "2021"
1111
rust-version = "1.70"
1212
authors = ["Tokio Contributors <[email protected]>"]

tokio/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Make sure you activated the full features of the tokio crate on Cargo.toml:
5656

5757
```toml
5858
[dependencies]
59-
tokio = { version = "1.39.2", features = ["full"] }
59+
tokio = { version = "1.39.3", features = ["full"] }
6060
```
6161
Then, on your main.rs:
6262

tokio/src/net/unix/listener.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,14 @@ use crate::net::unix::{SocketAddr, UnixStream};
33

44
use std::fmt;
55
use std::io;
6+
#[cfg(target_os = "android")]
7+
use std::os::android::net::SocketAddrExt;
8+
#[cfg(target_os = "linux")]
9+
use std::os::linux::net::SocketAddrExt;
10+
#[cfg(any(target_os = "linux", target_os = "android"))]
11+
use std::os::unix::ffi::OsStrExt;
612
use std::os::unix::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, RawFd};
7-
use std::os::unix::net;
13+
use std::os::unix::net::{self, SocketAddr as StdSocketAddr};
814
use std::path::Path;
915
use std::task::{Context, Poll};
1016

@@ -70,7 +76,20 @@ impl UnixListener {
7076
where
7177
P: AsRef<Path>,
7278
{
73-
let listener = mio::net::UnixListener::bind(path)?;
79+
// For now, we handle abstract socket paths on linux here.
80+
#[cfg(any(target_os = "linux", target_os = "android"))]
81+
let addr = {
82+
let os_str_bytes = path.as_ref().as_os_str().as_bytes();
83+
if os_str_bytes.starts_with(b"\0") {
84+
StdSocketAddr::from_abstract_name(os_str_bytes)?
85+
} else {
86+
StdSocketAddr::from_pathname(path)?
87+
}
88+
};
89+
#[cfg(not(any(target_os = "linux", target_os = "android")))]
90+
let addr = StdSocketAddr::from_pathname(path)?;
91+
92+
let listener = mio::net::UnixListener::bind_addr(&addr)?;
7493
let io = PollEvented::new(listener)?;
7594
Ok(UnixListener { io })
7695
}

tokio/src/net/unix/stream.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,14 @@ use crate::net::unix::SocketAddr;
88
use std::fmt;
99
use std::io::{self, Read, Write};
1010
use std::net::Shutdown;
11+
#[cfg(target_os = "android")]
12+
use std::os::android::net::SocketAddrExt;
13+
#[cfg(target_os = "linux")]
14+
use std::os::linux::net::SocketAddrExt;
15+
#[cfg(any(target_os = "linux", target_os = "android"))]
16+
use std::os::unix::ffi::OsStrExt;
1117
use std::os::unix::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, RawFd};
12-
use std::os::unix::net;
18+
use std::os::unix::net::{self, SocketAddr as StdSocketAddr};
1319
use std::path::Path;
1420
use std::pin::Pin;
1521
use std::task::{Context, Poll};
@@ -66,7 +72,20 @@ impl UnixStream {
6672
where
6773
P: AsRef<Path>,
6874
{
69-
let stream = mio::net::UnixStream::connect(path)?;
75+
// On linux, abstract socket paths need to be considered.
76+
#[cfg(any(target_os = "linux", target_os = "android"))]
77+
let addr = {
78+
let os_str_bytes = path.as_ref().as_os_str().as_bytes();
79+
if os_str_bytes.starts_with(b"\0") {
80+
StdSocketAddr::from_abstract_name(os_str_bytes)?
81+
} else {
82+
StdSocketAddr::from_pathname(path)?
83+
}
84+
};
85+
#[cfg(not(any(target_os = "linux", target_os = "android")))]
86+
let addr = StdSocketAddr::from_pathname(path)?;
87+
88+
let stream = mio::net::UnixStream::connect_addr(&addr)?;
7089
let stream = UnixStream::new(stream)?;
7190

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

tokio/tests/uds_stream.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,3 +420,16 @@ async fn epollhup() -> io::Result<()> {
420420
);
421421
Ok(())
422422
}
423+
424+
// test for https://github.com/tokio-rs/tokio/issues/6767
425+
#[tokio::test]
426+
#[cfg(any(target_os = "linux", target_os = "android"))]
427+
async fn abstract_socket_name() {
428+
let socket_path = "\0aaa";
429+
let listener = UnixListener::bind(socket_path).unwrap();
430+
431+
let accept = listener.accept();
432+
let connect = UnixStream::connect(&socket_path);
433+
434+
try_join(accept, connect).await.unwrap();
435+
}

0 commit comments

Comments
 (0)