@@ -8,6 +8,8 @@ use tokio_core::io::{Io, Codec, EasyBuf, Framed};
88use tokio_core:: net:: TcpStream ;
99use tokio_core:: reactor:: Handle ;
1010use tokio_dns;
11+
12+ #[ cfg( unix) ]
1113use tokio_uds:: UnixStream ;
1214
1315use TlsMode ;
@@ -26,12 +28,17 @@ pub fn connect(host: Host,
2628 Either :: A ( tokio_dns:: tcp_connect ( ( & * * host, port) , handle. remote ( ) . clone ( ) )
2729 . map ( |s| Stream ( InnerStream :: Tcp ( s) ) ) )
2830 }
31+ #[ cfg( unix) ]
2932 Host :: Unix ( ref host) => {
3033 let addr = host. join ( format ! ( ".s.PGSQL.{}" , port) ) ;
3134 Either :: B ( UnixStream :: connect ( addr, handle)
3235 . map ( |s| Stream ( InnerStream :: Unix ( s) ) )
3336 . into_future ( ) )
3437 }
38+ #[ cfg( not( unix) ) ]
39+ Host :: Unix ( _) => {
40+ Either :: B ( Err ( ConnectError :: ConnectParams ( "unix sockets are not supported on this platform" ) ) . into_future ( ) )
41+ }
3542 } ;
3643
3744 let ( required, handshaker) = match tls_mode {
@@ -84,13 +91,15 @@ pub struct Stream(InnerStream);
8491
8592enum InnerStream {
8693 Tcp ( TcpStream ) ,
94+ #[ cfg( unix) ]
8795 Unix ( UnixStream ) ,
8896}
8997
9098impl Read for Stream {
9199 fn read ( & mut self , buf : & mut [ u8 ] ) -> io:: Result < usize > {
92100 match self . 0 {
93101 InnerStream :: Tcp ( ref mut s) => s. read ( buf) ,
102+ #[ cfg( unix) ]
94103 InnerStream :: Unix ( ref mut s) => s. read ( buf) ,
95104 }
96105 }
@@ -100,13 +109,15 @@ impl Write for Stream {
100109 fn write ( & mut self , buf : & [ u8 ] ) -> io:: Result < usize > {
101110 match self . 0 {
102111 InnerStream :: Tcp ( ref mut s) => s. write ( buf) ,
112+ #[ cfg( unix) ]
103113 InnerStream :: Unix ( ref mut s) => s. write ( buf) ,
104114 }
105115 }
106116
107117 fn flush ( & mut self ) -> io:: Result < ( ) > {
108118 match self . 0 {
109119 InnerStream :: Tcp ( ref mut s) => s. flush ( ) ,
120+ #[ cfg( unix) ]
110121 InnerStream :: Unix ( ref mut s) => s. flush ( ) ,
111122 }
112123 }
@@ -116,13 +127,15 @@ impl Io for Stream {
116127 fn poll_read ( & mut self ) -> Async < ( ) > {
117128 match self . 0 {
118129 InnerStream :: Tcp ( ref mut s) => s. poll_read ( ) ,
130+ #[ cfg( unix) ]
119131 InnerStream :: Unix ( ref mut s) => s. poll_read ( ) ,
120132 }
121133 }
122134
123135 fn poll_write ( & mut self ) -> Async < ( ) > {
124136 match self . 0 {
125137 InnerStream :: Tcp ( ref mut s) => s. poll_write ( ) ,
138+ #[ cfg( unix) ]
126139 InnerStream :: Unix ( ref mut s) => s. poll_write ( ) ,
127140 }
128141 }
0 commit comments