mirror of
https://github.com/async-rs/async-std.git
synced 2025-04-17 05:46:44 +00:00
tests: add test case for UnixStream::into_raw_fd
Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
parent
dbc98faf1f
commit
59874d639c
1 changed files with 18 additions and 1 deletions
19
tests/uds.rs
19
tests/uds.rs
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue