Add tests for UnixDatagram from_raw_fd/into_raw_fd

pull/148/head
Yuxuan Shui 5 years ago
parent bac74c2d7f
commit 2ca9c46b4b
No known key found for this signature in database
GPG Key ID: 37C999F617EA1A47

@ -22,3 +22,21 @@ fn send_recv() -> io::Result<()> {
Ok(()) Ok(())
}) })
} }
#[test]
fn into_raw_fd() -> io::Result<()> {
use async_std::os::unix::io::{FromRawFd, IntoRawFd};
task::block_on(async {
let (socket1, socket2) = UnixDatagram::pair().unwrap();
socket1.send(JULIUS_CAESAR).await?;
let mut buf = vec![0; 1024];
let socket2 = unsafe { UnixDatagram::from_raw_fd(socket2.into_raw_fd()) };
let n = socket2.recv(&mut buf).await?;
assert_eq!(&buf[..n], JULIUS_CAESAR);
Ok(())
})
}

Loading…
Cancel
Save