Skip to content

Commit b0bed6a

Browse files
committed
Add a nightly feature
Currently uses the UnixStream from the standard library
1 parent bd60ecf commit b0bed6a

File tree

5 files changed

+23
-16
lines changed

5 files changed

+23
-16
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ before_script:
1111
script:
1212
- cargo test
1313
- cargo test --features "uuid rustc-serialize time unix_socket serde_json chrono openssl bit-vec eui48"
14+
- (test $TRAVIS_RUST_VERSION != "nightly" || cargo test --features nightly)

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ bench = false
2020
name = "test"
2121
path = "tests/test.rs"
2222

23+
[features]
24+
nightly = []
25+
2326
[dependencies]
2427
bufstream = "0.1"
2528
byteorder = "0.5"

src/lib.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#![doc(html_root_url="https://sfackler.github.io/rust-postgres/doc/v0.11.4")]
4242
#![warn(missing_docs)]
4343
#![allow(unknown_lints, needless_lifetimes)] // for clippy
44+
#![cfg_attr(feature = "nightly", feature(unix_socket))]
4445

4546
extern crate bufstream;
4647
extern crate byteorder;
@@ -68,7 +69,7 @@ use std::mem;
6869
use std::result;
6970
use std::sync::Arc;
7071
use std::time::Duration;
71-
#[cfg(feature = "unix_socket")]
72+
#[cfg(any(feature = "unix_socket", feature = "nightly"))]
7273
use std::path::PathBuf;
7374

7475
// FIXME remove in 0.12
@@ -115,8 +116,8 @@ pub enum ConnectTarget {
115116
Tcp(String),
116117
/// Connect via a Unix domain socket in the specified directory.
117118
///
118-
/// Requires the `unix_socket` feature.
119-
#[cfg(feature = "unix_socket")]
119+
/// Requires the `unix_socket` or `nightly` feature.
120+
#[cfg(any(feature = "unix_socket", feature = "nightly"))]
120121
Unix(PathBuf),
121122
}
122123

@@ -173,12 +174,12 @@ impl<'a> IntoConnectParams for &'a str {
173174

174175
impl IntoConnectParams for Url {
175176
fn into_connect_params(self) -> result::Result<ConnectParams, Box<StdError + StdSync + Send>> {
176-
#[cfg(feature = "unix_socket")]
177+
#[cfg(any(feature = "unix_socket", feature = "nightly"))]
177178
fn make_unix(maybe_path: String)
178179
-> result::Result<ConnectTarget, Box<StdError + StdSync + Send>> {
179180
Ok(ConnectTarget::Unix(PathBuf::from(maybe_path)))
180181
}
181-
#[cfg(not(feature = "unix_socket"))]
182+
#[cfg(not(any(feature = "unix_socket", feature = "nightly")))]
182183
fn make_unix(_: String) -> result::Result<ConnectTarget, Box<StdError + StdSync + Send>> {
183184
Err("unix socket support requires the `unix_socket` feature".into())
184185
}

src/priv_io.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ use std::time::Duration;
99
use bufstream::BufStream;
1010
#[cfg(feature = "unix_socket")]
1111
use unix_socket::UnixStream;
12+
#[cfg(all(not(feature = "unix_socket"), feature = "nightly"))]
13+
use std::os::unix::net::UnixStream;
1214
#[cfg(unix)]
1315
use std::os::unix::io::{AsRawFd, RawFd};
1416
#[cfg(windows)]
@@ -32,15 +34,15 @@ impl StreamOptions for BufStream<Box<StreamWrapper>> {
3234
fn set_read_timeout(&self, timeout: Option<Duration>) -> io::Result<()> {
3335
match self.get_ref().get_ref().0 {
3436
InternalStream::Tcp(ref s) => s.set_read_timeout(timeout),
35-
#[cfg(feature = "unix_socket")]
37+
#[cfg(any(feature = "unix_socket", feature = "nightly"))]
3638
InternalStream::Unix(ref s) => s.set_read_timeout(timeout),
3739
}
3840
}
3941

4042
fn set_nonblocking(&self, nonblock: bool) -> io::Result<()> {
4143
match self.get_ref().get_ref().0 {
4244
InternalStream::Tcp(ref s) => s.set_nonblocking(nonblock),
43-
#[cfg(feature = "unix_socket")]
45+
#[cfg(any(feature = "unix_socket", feature = "nightly"))]
4446
InternalStream::Unix(ref s) => s.set_nonblocking(nonblock),
4547
}
4648
}
@@ -56,7 +58,7 @@ impl fmt::Debug for Stream {
5658
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
5759
match self.0 {
5860
InternalStream::Tcp(ref s) => fmt::Debug::fmt(s, fmt),
59-
#[cfg(feature = "unix_socket")]
61+
#[cfg(any(feature = "unix_socket", feature = "nightly"))]
6062
InternalStream::Unix(ref s) => fmt::Debug::fmt(s, fmt),
6163
}
6264
}
@@ -93,7 +95,7 @@ impl AsRawFd for Stream {
9395
fn as_raw_fd(&self) -> RawFd {
9496
match self.0 {
9597
InternalStream::Tcp(ref s) => s.as_raw_fd(),
96-
#[cfg(feature = "unix_socket")]
98+
#[cfg(any(feature = "unix_socket", feature = "nightly"))]
9799
InternalStream::Unix(ref s) => s.as_raw_fd(),
98100
}
99101
}
@@ -111,15 +113,15 @@ impl AsRawSocket for Stream {
111113

112114
enum InternalStream {
113115
Tcp(TcpStream),
114-
#[cfg(feature = "unix_socket")]
116+
#[cfg(any(feature = "unix_socket", feature = "nightly"))]
115117
Unix(UnixStream),
116118
}
117119

118120
impl Read for InternalStream {
119121
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
120122
match *self {
121123
InternalStream::Tcp(ref mut s) => s.read(buf),
122-
#[cfg(feature = "unix_socket")]
124+
#[cfg(any(feature = "unix_socket", feature = "nightly"))]
123125
InternalStream::Unix(ref mut s) => s.read(buf),
124126
}
125127
}
@@ -129,15 +131,15 @@ impl Write for InternalStream {
129131
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
130132
match *self {
131133
InternalStream::Tcp(ref mut s) => s.write(buf),
132-
#[cfg(feature = "unix_socket")]
134+
#[cfg(any(feature = "unix_socket", feature = "nightly"))]
133135
InternalStream::Unix(ref mut s) => s.write(buf),
134136
}
135137
}
136138

137139
fn flush(&mut self) -> io::Result<()> {
138140
match *self {
139141
InternalStream::Tcp(ref mut s) => s.flush(),
140-
#[cfg(feature = "unix_socket")]
142+
#[cfg(any(feature = "unix_socket", feature = "nightly"))]
141143
InternalStream::Unix(ref mut s) => s.flush(),
142144
}
143145
}
@@ -149,7 +151,7 @@ fn open_socket(params: &ConnectParams) -> Result<InternalStream, ConnectError> {
149151
ConnectTarget::Tcp(ref host) => {
150152
Ok(try!(TcpStream::connect(&(&**host, port)).map(InternalStream::Tcp)))
151153
}
152-
#[cfg(feature = "unix_socket")]
154+
#[cfg(any(feature = "unix_socket", feature = "nightly"))]
153155
ConnectTarget::Unix(ref path) => {
154156
let path = path.join(&format!(".s.PGSQL.{}", port));
155157
Ok(try!(UnixStream::connect(&path).map(InternalStream::Unix)))
@@ -183,7 +185,7 @@ pub fn initialize_stream(params: &ConnectParams,
183185
// Postgres doesn't support SSL over unix sockets
184186
let host = match params.target {
185187
ConnectTarget::Tcp(ref host) => host,
186-
#[cfg(feature = "unix_socket")]
188+
#[cfg(any(feature = "unix_socket", feature = "nightly"))]
187189
ConnectTarget::Unix(_) => return Err(ConnectError::Io(::bad_response())),
188190
};
189191

tests/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ fn test_connection_finish() {
7575
}
7676

7777
#[test]
78-
#[cfg_attr(not(feature = "unix_socket"), ignore)]
78+
#[cfg_attr(not(any(feature = "unix_socket", feature = "nightly")), ignore)]
7979
fn test_unix_connection() {
8080
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", SslMode::None));
8181
let stmt = or_panic!(conn.prepare("SHOW unix_socket_directories"));

0 commit comments

Comments
 (0)