File tree Expand file tree Collapse file tree 2 files changed +130
-227
lines changed Expand file tree Collapse file tree 2 files changed +130
-227
lines changed Original file line number Diff line number Diff line change 10
10
11
11
//! Networking I/O
12
12
13
+ use io:: { IoError , InvalidInput } ;
14
+ use option:: None ;
15
+ use result:: { Result , Ok , Err } ;
13
16
use rt:: rtio;
14
- use self :: ip:: { Ipv4Addr , Ipv6Addr , IpAddr } ;
17
+ use self :: ip:: { Ipv4Addr , Ipv6Addr , IpAddr , ToSocketAddr } ;
15
18
16
19
pub use self :: addrinfo:: get_host_addresses;
17
20
@@ -38,3 +41,25 @@ fn from_rtio(ip: rtio::IpAddr) -> IpAddr {
38
41
}
39
42
}
40
43
}
44
+
45
+ fn with_addresses < A : ToSocketAddr , T > (
46
+ addr : A ,
47
+ action : |& mut rtio:: IoFactory , rtio:: SocketAddr | -> Result < T , rtio:: IoError >
48
+ ) -> Result < T , IoError > {
49
+ const DEFAULT_ERROR : IoError = IoError {
50
+ kind : InvalidInput ,
51
+ desc: "no addresses found for hostname" ,
52
+ detail : None
53
+ } ;
54
+
55
+ let addresses = try!( addr. to_socket_addr_all ( ) ) ;
56
+ let mut err = DEFAULT_ERROR ;
57
+ for addr in addresses. into_iter ( ) {
58
+ let addr = rtio:: SocketAddr { ip : to_rtio ( addr. ip ) , port : addr. port } ;
59
+ match rtio:: LocalIo :: maybe_raise ( |io| action ( io, addr) ) {
60
+ Ok ( r) => return Ok ( r) ,
61
+ Err ( e) => err = IoError :: from_rtio_error ( e)
62
+ }
63
+ }
64
+ Err ( err)
65
+ }
You can’t perform that action at this time.
0 commit comments