Skip to content

Commit bd29747

Browse files
authored
Merge pull request #856 from yshui/master
Fix #855
2 parents 1319def + b0ac73c commit bd29747

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://book.async.rs/overview
77

88
## [Unreleased]
99

10+
## Fixed
11+
12+
- Ensure `UnixStream::into_raw_fd` doesn't close the file descriptor ([#855](https://github.com/async-rs/async-std/issues/855))
13+
1014
# [1.6.3] - 2020-07-31
1115

1216
## Added

src/os/unix/net/stream.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,6 @@ impl FromRawFd for UnixStream {
252252

253253
impl IntoRawFd for UnixStream {
254254
fn into_raw_fd(self) -> RawFd {
255-
self.as_raw_fd()
255+
(*self.watcher).get_ref().try_clone().unwrap().into_raw_fd()
256256
}
257257
}

tests/uds.rs

+18-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ fn send_recv() -> io::Result<()> {
2727
}
2828

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

46+
#[test]
47+
fn into_raw_fd_stream() -> io::Result<()> {
48+
use async_std::os::unix::io::{FromRawFd, IntoRawFd};
49+
task::block_on(async {
50+
let (mut socket1, socket2) = UnixStream::pair().unwrap();
51+
socket1.write(JULIUS_CAESAR).await?;
52+
53+
let mut buf = vec![0; 1024];
54+
55+
let mut socket2 = unsafe { UnixStream::from_raw_fd(socket2.into_raw_fd()) };
56+
let n = socket2.read(&mut buf).await?;
57+
assert_eq!(&buf[..n], JULIUS_CAESAR);
58+
59+
Ok(())
60+
})
61+
}
62+
4663
const PING: &[u8] = b"ping";
4764
const PONG: &[u8] = b"pong";
4865
const TEST_TIMEOUT: Duration = Duration::from_secs(3);

0 commit comments

Comments
 (0)