2
0
Fork 1
mirror of https://github.com/async-rs/async-std.git synced 2025-01-30 17:25:32 +00:00

Merge pull request #856 from yshui/master

Fix #855
This commit is contained in:
Yoshua Wuyts 2020-08-28 16:00:09 +02:00 committed by GitHub
commit bd297473cc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 2 deletions

View file

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

View file

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

View file

@ -27,7 +27,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();
@ -43,6 +43,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);