1- use crate :: { AsyncIOHandle , Executor , IOHandle , Reactor , RuntimeKit , Task , sys:: IO } ;
1+ use crate :: {
2+ AsyncIOHandle , AsyncToSocketAddrs , Executor , IOHandle , Reactor , RuntimeKit , Task , sys:: IO ,
3+ } ;
24use async_trait:: async_trait;
35use futures_core:: Stream ;
46use std:: {
57 fmt,
68 future:: Future ,
79 io,
8- net:: SocketAddr ,
10+ net:: { SocketAddr , ToSocketAddrs } ,
911 pin:: Pin ,
1012 time:: { Duration , Instant } ,
1113} ;
@@ -21,6 +23,20 @@ impl<RK: RuntimeKit + 'static> Runtime<RK> {
2123 pub fn new ( kit : RK ) -> Self {
2224 Self { kit }
2325 }
26+
27+ /// Asynchronously resolve the given domain name
28+ pub fn to_socket_addrs < A : ToSocketAddrs + Send + ' static > (
29+ & self ,
30+ addrs : A ,
31+ ) -> impl AsyncToSocketAddrs
32+ where
33+ <A as std:: net:: ToSocketAddrs >:: Iter : Iterator < Item = SocketAddr > + Send + ' static ,
34+ {
35+ SocketAddrsResolver {
36+ runtime : self ,
37+ addrs,
38+ }
39+ }
2440}
2541
2642impl < RK : RuntimeKit + ' static > From < RK > for Runtime < RK > {
@@ -131,3 +147,21 @@ impl<E: Executor + Sync, R: Reactor + Sync> Reactor for RuntimeParts<E, R> {
131147 self . reactor . tcp_connect ( addr) . await
132148 }
133149}
150+
151+ struct SocketAddrsResolver < ' a , RK : RuntimeKit + ' static , A : ToSocketAddrs + Send + ' static > {
152+ runtime : & ' a Runtime < RK > ,
153+ addrs : A ,
154+ }
155+
156+ impl < ' a , RK : RuntimeKit + ' static , A : ToSocketAddrs + Send + ' static > AsyncToSocketAddrs
157+ for SocketAddrsResolver < ' a , RK , A >
158+ where
159+ <A as ToSocketAddrs >:: Iter : Iterator < Item = SocketAddr > + Send + ' static ,
160+ {
161+ fn to_socket_addrs (
162+ self ,
163+ ) -> impl Future < Output = io:: Result < impl Iterator < Item = SocketAddr > + Send > > + Send {
164+ let SocketAddrsResolver { runtime, addrs } = self ;
165+ runtime. spawn_blocking ( move || addrs. to_socket_addrs ( ) )
166+ }
167+ }
0 commit comments