Skip to content

Fix #855 #856

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 28, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://book.async.rs/overview

## [Unreleased]

## Fixed

- Ensure `UnixStream::into_raw_fd` doesn't close the file descriptor ([#855](https://github.com/async-rs/async-std/issues/855))

# [1.6.3] - 2020-07-31

## Added
2 changes: 1 addition & 1 deletion src/os/unix/net/stream.rs
Original file line number Diff line number Diff line change
@@ -252,6 +252,6 @@ impl FromRawFd for UnixStream {

impl IntoRawFd for UnixStream {
fn into_raw_fd(self) -> RawFd {
self.as_raw_fd()
(*self.watcher).get_ref().try_clone().unwrap().into_raw_fd()
}
}
19 changes: 18 additions & 1 deletion tests/uds.rs
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@ fn send_recv() -> io::Result<()> {
}

#[test]
fn into_raw_fd() -> io::Result<()> {
fn into_raw_fd_datagram() -> io::Result<()> {
use async_std::os::unix::io::{FromRawFd, IntoRawFd};
task::block_on(async {
let (socket1, socket2) = UnixDatagram::pair().unwrap();
@@ -45,6 +45,23 @@ fn into_raw_fd() -> io::Result<()> {
})
}

#[test]
fn into_raw_fd_stream() -> io::Result<()> {
use async_std::os::unix::io::{FromRawFd, IntoRawFd};
task::block_on(async {
let (mut socket1, socket2) = UnixStream::pair().unwrap();
socket1.write(JULIUS_CAESAR).await?;

let mut buf = vec![0; 1024];

let mut socket2 = unsafe { UnixStream::from_raw_fd(socket2.into_raw_fd()) };
let n = socket2.read(&mut buf).await?;
assert_eq!(&buf[..n], JULIUS_CAESAR);

Ok(())
})
}

const PING: &[u8] = b"ping";
const PONG: &[u8] = b"pong";
const TEST_TIMEOUT: Duration = Duration::from_secs(3);