Skip to content

Commit 682a45b

Browse files
committed
Don't depend on tokio-uds on Windows
Closes #236
1 parent 8f1d076 commit 682a45b

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

tokio-postgres/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ postgres-shared = { version = "0.2", path = "../postgres-shared" }
2828
postgres-protocol = "0.2"
2929
tokio-core = "0.1"
3030
tokio-dns-unofficial = "0.1"
31-
tokio-uds = "0.1"
3231

3332
tokio-openssl = { version = "0.1", optional = true }
3433
openssl = { version = "0.9", optional = true }
34+
35+
[target.'cfg(unix)'.dependencies]
36+
tokio-uds = "0.1"

tokio-postgres/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ extern crate postgres_shared;
5959
extern crate postgres_protocol;
6060
extern crate tokio_core;
6161
extern crate tokio_dns;
62+
63+
#[cfg(unix)]
6264
extern crate tokio_uds;
6365

6466
#[cfg(feature = "tokio-openssl")]

tokio-postgres/src/stream.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ use tokio_core::io::{Io, Codec, EasyBuf, Framed};
88
use tokio_core::net::TcpStream;
99
use tokio_core::reactor::Handle;
1010
use tokio_dns;
11+
12+
#[cfg(unix)]
1113
use tokio_uds::UnixStream;
1214

1315
use 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

8592
enum InnerStream {
8693
Tcp(TcpStream),
94+
#[cfg(unix)]
8795
Unix(UnixStream),
8896
}
8997

9098
impl 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

Comments
 (0)