add native async fn methods to async-std UdpSocket
This commit is contained in:
parent
ecaf8c92d5
commit
ec1513c59a
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -152,6 +152,7 @@ dependencies = [
|
||||
"async-trait",
|
||||
"futures-io",
|
||||
"futures-util",
|
||||
"pin-utils",
|
||||
"trust-dns-resolver",
|
||||
]
|
||||
|
||||
|
@ -68,6 +68,7 @@ async-std = "1.6"
|
||||
async-trait = "0.1.36"
|
||||
futures-io = { version = "0.3.5", default-features = false, features = ["std"] }
|
||||
futures-util = { version = "0.3.5", default-features = false, features = ["std"] }
|
||||
pin-utils = "0.1.0"
|
||||
trust-dns-resolver = { version = "0.20.0-alpha.3", path = "../resolver", default-features = false }
|
||||
|
||||
[dev-dependencies]
|
||||
|
@ -13,6 +13,7 @@ use std::task::{Context, Poll};
|
||||
use async_trait::async_trait;
|
||||
use futures_io::{AsyncRead, AsyncWrite};
|
||||
use futures_util::future::FutureExt;
|
||||
use pin_utils::pin_mut;
|
||||
use trust_dns_resolver::proto::tcp::{Connect, DnsTcpStream};
|
||||
use trust_dns_resolver::proto::udp::UdpSocket;
|
||||
|
||||
@ -35,7 +36,14 @@ impl UdpSocket for AsyncStdUdpSocket {
|
||||
cx: &mut Context,
|
||||
buf: &mut [u8],
|
||||
) -> Poll<io::Result<(usize, SocketAddr)>> {
|
||||
Box::pin(self.0.recv_from(buf)).poll_unpin(cx)
|
||||
let fut = self.0.recv_from(buf);
|
||||
pin_mut!(fut);
|
||||
|
||||
fut.poll_unpin(cx)
|
||||
}
|
||||
|
||||
async fn recv_from(&self, buf: &mut [u8]) -> io::Result<(usize, SocketAddr)> {
|
||||
self.0.recv_from(buf).await
|
||||
}
|
||||
|
||||
fn poll_send_to(
|
||||
@ -44,7 +52,14 @@ impl UdpSocket for AsyncStdUdpSocket {
|
||||
buf: &[u8],
|
||||
target: &SocketAddr,
|
||||
) -> Poll<io::Result<usize>> {
|
||||
Box::pin(self.0.send_to(buf, target)).poll_unpin(cx)
|
||||
let fut = self.0.send_to(buf, target);
|
||||
pin_mut!(fut);
|
||||
|
||||
fut.poll_unpin(cx)
|
||||
}
|
||||
|
||||
async fn send_to(&self, buf: &[u8], target: &SocketAddr) -> io::Result<usize> {
|
||||
self.0.send_to(buf, target).await
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user