@@ -8,6 +8,8 @@ use tokio_core::io::{Io, Codec, EasyBuf, Framed};
8
8
use tokio_core:: net:: TcpStream ;
9
9
use tokio_core:: reactor:: Handle ;
10
10
use tokio_dns;
11
+
12
+ #[ cfg( unix) ]
11
13
use tokio_uds:: UnixStream ;
12
14
13
15
use TlsMode ;
@@ -26,12 +28,17 @@ pub fn connect(host: Host,
26
28
Either :: A ( tokio_dns:: tcp_connect ( ( & * * host, port) , handle. remote ( ) . clone ( ) )
27
29
. map ( |s| Stream ( InnerStream :: Tcp ( s) ) ) )
28
30
}
31
+ #[ cfg( unix) ]
29
32
Host :: Unix ( ref host) => {
30
33
let addr = host. join ( format ! ( ".s.PGSQL.{}" , port) ) ;
31
34
Either :: B ( UnixStream :: connect ( addr, handle)
32
35
. map ( |s| Stream ( InnerStream :: Unix ( s) ) )
33
36
. into_future ( ) )
34
37
}
38
+ #[ cfg( not( unix) ) ]
39
+ Host :: Unix ( _) => {
40
+ Either :: B ( Err ( ConnectError :: ConnectParams ( "unix sockets are not supported on this platform" ) ) . into_future ( ) )
41
+ }
35
42
} ;
36
43
37
44
let ( required, handshaker) = match tls_mode {
@@ -84,13 +91,15 @@ pub struct Stream(InnerStream);
84
91
85
92
enum InnerStream {
86
93
Tcp ( TcpStream ) ,
94
+ #[ cfg( unix) ]
87
95
Unix ( UnixStream ) ,
88
96
}
89
97
90
98
impl Read for Stream {
91
99
fn read ( & mut self , buf : & mut [ u8 ] ) -> io:: Result < usize > {
92
100
match self . 0 {
93
101
InnerStream :: Tcp ( ref mut s) => s. read ( buf) ,
102
+ #[ cfg( unix) ]
94
103
InnerStream :: Unix ( ref mut s) => s. read ( buf) ,
95
104
}
96
105
}
@@ -100,13 +109,15 @@ impl Write for Stream {
100
109
fn write ( & mut self , buf : & [ u8 ] ) -> io:: Result < usize > {
101
110
match self . 0 {
102
111
InnerStream :: Tcp ( ref mut s) => s. write ( buf) ,
112
+ #[ cfg( unix) ]
103
113
InnerStream :: Unix ( ref mut s) => s. write ( buf) ,
104
114
}
105
115
}
106
116
107
117
fn flush ( & mut self ) -> io:: Result < ( ) > {
108
118
match self . 0 {
109
119
InnerStream :: Tcp ( ref mut s) => s. flush ( ) ,
120
+ #[ cfg( unix) ]
110
121
InnerStream :: Unix ( ref mut s) => s. flush ( ) ,
111
122
}
112
123
}
@@ -116,13 +127,15 @@ impl Io for Stream {
116
127
fn poll_read ( & mut self ) -> Async < ( ) > {
117
128
match self . 0 {
118
129
InnerStream :: Tcp ( ref mut s) => s. poll_read ( ) ,
130
+ #[ cfg( unix) ]
119
131
InnerStream :: Unix ( ref mut s) => s. poll_read ( ) ,
120
132
}
121
133
}
122
134
123
135
fn poll_write ( & mut self ) -> Async < ( ) > {
124
136
match self . 0 {
125
137
InnerStream :: Tcp ( ref mut s) => s. poll_write ( ) ,
138
+ #[ cfg( unix) ]
126
139
InnerStream :: Unix ( ref mut s) => s. poll_write ( ) ,
127
140
}
128
141
}
0 commit comments