88// option. This file may not be copied, modified, or distributed
99// except according to those terms.
1010
11- use ai = std:: io:: net:: addrinfo;
1211use libc:: { c_char, c_int} ;
1312use libc;
1413use std:: c_str:: CString ;
15- use std:: io:: IoError ;
1614use std:: mem;
1715use std:: ptr:: { null, mut_null} ;
16+ use std:: rt:: rtio;
17+ use std:: rt:: rtio:: IoError ;
1818
19- use super :: net:: sockaddr_to_addr ;
19+ use super :: net;
2020
2121pub struct GetAddrInfoRequest ;
2222
2323impl GetAddrInfoRequest {
2424 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+ {
2628 assert ! ( host. is_some( ) || servname. is_some( ) ) ;
2729
2830 let c_host = host. map_or ( unsafe { CString :: new ( null ( ) , true ) } , |x| x. to_c_str ( ) ) ;
@@ -61,16 +63,16 @@ impl GetAddrInfoRequest {
6163 let mut rp = res;
6264 while rp. is_not_null ( ) {
6365 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 ) {
6668 Ok ( a) => a,
6769 Err ( e) => return Err ( e)
6870 } ;
69- addrs. push ( ai :: Info {
71+ addrs. push ( rtio :: AddrinfoInfo {
7072 address : addr,
7173 family : ( * rp) . ai_family as uint ,
72- socktype : None ,
73- protocol : None ,
74+ socktype : 0 ,
75+ protocol : 0 ,
7476 flags : ( * rp) . ai_flags as uint
7577 } ) ;
7678
@@ -96,21 +98,18 @@ extern "system" {
9698
9799#[ cfg( windows) ]
98100fn get_error ( _: c_int ) -> IoError {
99- unsafe {
100- IoError :: from_errno ( WSAGetLastError ( ) as uint , true )
101- }
101+ net:: last_error ( )
102102}
103103
104104#[ cfg( not( windows) ) ]
105105fn get_error ( s : c_int ) -> IoError {
106- use std:: io;
107106
108107 let err_str = unsafe {
109108 CString :: new ( gai_strerror ( s) , false ) . as_str ( ) . unwrap ( ) . to_string ( )
110109 } ;
111110 IoError {
112- kind : io :: OtherIoError ,
113- desc : "unable to resolve host" ,
111+ code : s as uint ,
112+ extra : 0 ,
114113 detail : Some ( err_str) ,
115114 }
116115}
0 commit comments