8
8
// option. This file may not be copied, modified, or distributed
9
9
// except according to those terms.
10
10
11
- use ai = std:: io:: net:: addrinfo;
12
11
use libc:: { c_char, c_int} ;
13
12
use libc;
14
13
use std:: c_str:: CString ;
15
- use std:: io:: IoError ;
16
14
use std:: mem;
17
15
use std:: ptr:: { null, mut_null} ;
16
+ use std:: rt:: rtio;
17
+ use std:: rt:: rtio:: IoError ;
18
18
19
- use super :: net:: sockaddr_to_addr ;
19
+ use super :: net;
20
20
21
21
pub struct GetAddrInfoRequest ;
22
22
23
23
impl GetAddrInfoRequest {
24
24
pub fn run ( host : Option < & str > , servname : Option < & str > ,
25
- hint : Option < ai:: Hint > ) -> Result < Vec < ai:: Info > , IoError > {
25
+ hint : Option < rtio:: AddrinfoHint > )
26
+ -> Result < Vec < rtio:: AddrinfoInfo > , IoError >
27
+ {
26
28
assert ! ( host. is_some( ) || servname. is_some( ) ) ;
27
29
28
30
let c_host = host. map_or ( unsafe { CString :: new ( null ( ) , true ) } , |x| x. to_c_str ( ) ) ;
@@ -61,16 +63,16 @@ impl GetAddrInfoRequest {
61
63
let mut rp = res;
62
64
while rp. is_not_null ( ) {
63
65
unsafe {
64
- let addr = match sockaddr_to_addr ( mem:: transmute ( ( * rp) . ai_addr ) ,
65
- ( * rp) . ai_addrlen as uint ) {
66
+ let addr = match net :: sockaddr_to_addr ( mem:: transmute ( ( * rp) . ai_addr ) ,
67
+ ( * rp) . ai_addrlen as uint ) {
66
68
Ok ( a) => a,
67
69
Err ( e) => return Err ( e)
68
70
} ;
69
- addrs. push ( ai :: Info {
71
+ addrs. push ( rtio :: AddrinfoInfo {
70
72
address : addr,
71
73
family : ( * rp) . ai_family as uint ,
72
- socktype : None ,
73
- protocol : None ,
74
+ socktype : 0 ,
75
+ protocol : 0 ,
74
76
flags : ( * rp) . ai_flags as uint
75
77
} ) ;
76
78
@@ -96,21 +98,18 @@ extern "system" {
96
98
97
99
#[ cfg( windows) ]
98
100
fn get_error ( _: c_int ) -> IoError {
99
- unsafe {
100
- IoError :: from_errno ( WSAGetLastError ( ) as uint , true )
101
- }
101
+ net:: last_error ( )
102
102
}
103
103
104
104
#[ cfg( not( windows) ) ]
105
105
fn get_error ( s : c_int ) -> IoError {
106
- use std:: io;
107
106
108
107
let err_str = unsafe {
109
108
CString :: new ( gai_strerror ( s) , false ) . as_str ( ) . unwrap ( ) . to_string ( )
110
109
} ;
111
110
IoError {
112
- kind : io :: OtherIoError ,
113
- desc : "unable to resolve host" ,
111
+ code : s as uint ,
112
+ extra : 0 ,
114
113
detail : Some ( err_str) ,
115
114
}
116
115
}
0 commit comments