2
0
Fork 1
mirror of https://github.com/async-rs/async-std.git synced 2025-01-16 18:59:55 +00:00
async-std/tests/udp.rs
Yoshua Wuyts 63ad786768
remove async_await feature gate
Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
2019-08-21 00:29:35 -07:00

29 lines
798 B
Rust

use async_std::io;
use async_std::net::UdpSocket;
use async_std::task;
const THE_MERCHANT_OF_VENICE: &[u8] = b"
If you prick us, do we not bleed?
If you tickle us, do we not laugh?
If you poison us, do we not die?
And if you wrong us, shall we not revenge?
";
#[test]
fn send_recv() -> io::Result<()> {
task::block_on(async {
let socket1 = UdpSocket::bind("127.0.0.1:0").await?;
let socket2 = UdpSocket::bind("127.0.0.1:0").await?;
socket1.connect(socket2.local_addr()?).await?;
socket2.connect(socket1.local_addr()?).await?;
socket1.send(THE_MERCHANT_OF_VENICE).await?;
let mut buf = [0u8; 1024];
let n = socket2.recv(&mut buf).await?;
assert_eq!(&buf[..n], THE_MERCHANT_OF_VENICE);
Ok(())
})
}