Skip to content

Commit 59874d6

Browse files
committed
tests: add test case for UnixStream::into_raw_fd
Signed-off-by: Yuxuan Shui <[email protected]>
1 parent dbc98fa commit 59874d6

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

Diff for: tests/uds.rs

+18-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ fn send_recv() -> io::Result<()> {
2929
}
3030

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

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

0 commit comments

Comments
 (0)