WIP: many underlying type except mdns

This commit is contained in:
XOR-op
2023-01-07 23:24:39 +08:00
committed by Benjamin Fry
parent 778ce0ccff
commit 53bf976f00
17 changed files with 517 additions and 72 deletions

View File

@@ -18,38 +18,15 @@ use pin_utils::pin_mut;
use socket2::{Domain, Protocol, Socket, Type};
use trust_dns_resolver::proto::tcp::{Connect, DnsTcpStream};
use trust_dns_resolver::proto::udp::UdpSocket;
use crate::proto::udp::DnsUdpSocket;
use crate::time::AsyncStdTime;
pub struct AsyncStdUdpSocket(async_std::net::UdpSocket);
#[async_trait]
impl UdpSocket for AsyncStdUdpSocket {
impl DnsUdpSocket for AsyncStdUdpSocket {
type Time = AsyncStdTime;
async fn connect_with_bind(_addr: SocketAddr, bind_addr: SocketAddr) -> io::Result<Self> {
let socket = async_std::net::UdpSocket::bind(bind_addr).await?;
// TODO: research connect more, it appears to break receive tests on UDP
// socket.connect(addr).await?;
Ok(Self(socket))
}
async fn connect(addr: SocketAddr) -> io::Result<Self> {
let bind_addr: SocketAddr = match addr {
SocketAddr::V4(_addr) => (Ipv4Addr::UNSPECIFIED, 0).into(),
SocketAddr::V6(_addr) => (Ipv6Addr::UNSPECIFIED, 0).into(),
};
Self::connect_with_bind(addr, bind_addr).await
}
async fn bind(addr: SocketAddr) -> io::Result<Self> {
async_std::net::UdpSocket::bind(addr)
.await
.map(AsyncStdUdpSocket)
}
fn poll_recv_from(
&self,
cx: &mut Context<'_>,
@@ -82,6 +59,34 @@ impl UdpSocket for AsyncStdUdpSocket {
}
}
#[async_trait]
impl UdpSocket for AsyncStdUdpSocket{
async fn connect(addr: SocketAddr) -> io::Result<Self> {
let bind_addr: SocketAddr = match addr {
SocketAddr::V4(_addr) => (Ipv4Addr::UNSPECIFIED, 0).into(),
SocketAddr::V6(_addr) => (Ipv6Addr::UNSPECIFIED, 0).into(),
};
Self::connect_with_bind(addr, bind_addr).await
}
async fn connect_with_bind(_addr: SocketAddr, bind_addr: SocketAddr) -> io::Result<Self> {
let socket = async_std::net::UdpSocket::bind(bind_addr).await?;
// TODO: research connect more, it appears to break receive tests on UDP
// socket.connect(addr).await?;
Ok(Self(socket))
}
async fn bind(addr: SocketAddr) -> io::Result<Self> {
async_std::net::UdpSocket::bind(addr)
.await
.map(AsyncStdUdpSocket)
}
}
pub struct AsyncStdTcpStream(async_std::net::TcpStream);
impl DnsTcpStream for AsyncStdTcpStream {