Only enable unix socket stuff on unix with nightly
This commit is contained in:
parent
9768c2e7d5
commit
d48fa83c19
12
src/lib.rs
12
src/lib.rs
@ -41,7 +41,7 @@
|
||||
#![doc(html_root_url="https://sfackler.github.io/rust-postgres/doc/v0.11.4")]
|
||||
#![warn(missing_docs)]
|
||||
#![allow(unknown_lints, needless_lifetimes)] // for clippy
|
||||
#![cfg_attr(feature = "nightly", feature(unix_socket))]
|
||||
#![cfg_attr(all(unix, feature = "nightly"), feature(unix_socket))]
|
||||
|
||||
extern crate bufstream;
|
||||
extern crate byteorder;
|
||||
@ -69,7 +69,7 @@ use std::mem;
|
||||
use std::result;
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
#[cfg(any(feature = "unix_socket", feature = "nightly"))]
|
||||
#[cfg(any(feature = "unix_socket", all(unix, feature = "nightly")))]
|
||||
use std::path::PathBuf;
|
||||
|
||||
// FIXME remove in 0.12
|
||||
@ -117,7 +117,7 @@ pub enum ConnectTarget {
|
||||
/// Connect via a Unix domain socket in the specified directory.
|
||||
///
|
||||
/// Requires the `unix_socket` or `nightly` feature.
|
||||
#[cfg(any(feature = "unix_socket", feature = "nightly"))]
|
||||
#[cfg(any(feature = "unix_socket", all(unix, feature = "nightly")))]
|
||||
Unix(PathBuf),
|
||||
}
|
||||
|
||||
@ -174,14 +174,14 @@ impl<'a> IntoConnectParams for &'a str {
|
||||
|
||||
impl IntoConnectParams for Url {
|
||||
fn into_connect_params(self) -> result::Result<ConnectParams, Box<StdError + StdSync + Send>> {
|
||||
#[cfg(any(feature = "unix_socket", feature = "nightly"))]
|
||||
#[cfg(any(feature = "unix_socket", all(unix, feature = "nightly")))]
|
||||
fn make_unix(maybe_path: String)
|
||||
-> result::Result<ConnectTarget, Box<StdError + StdSync + Send>> {
|
||||
Ok(ConnectTarget::Unix(PathBuf::from(maybe_path)))
|
||||
}
|
||||
#[cfg(not(any(feature = "unix_socket", feature = "nightly")))]
|
||||
#[cfg(not(any(feature = "unix_socket", all(unix, feature = "nightly"))))]
|
||||
fn make_unix(_: String) -> result::Result<ConnectTarget, Box<StdError + StdSync + Send>> {
|
||||
Err("unix socket support requires the `unix_socket` feature".into())
|
||||
Err("unix socket support requires the `unix_socket` or `nightly` features".into())
|
||||
}
|
||||
|
||||
let Url { host, port, user, path: url::Path { mut path, query: options, .. }, .. } = self;
|
||||
|
@ -9,7 +9,7 @@ use std::time::Duration;
|
||||
use bufstream::BufStream;
|
||||
#[cfg(feature = "unix_socket")]
|
||||
use unix_socket::UnixStream;
|
||||
#[cfg(all(not(feature = "unix_socket"), feature = "nightly"))]
|
||||
#[cfg(all(not(feature = "unix_socket"), all(unix, feature = "nightly")))]
|
||||
use std::os::unix::net::UnixStream;
|
||||
#[cfg(unix)]
|
||||
use std::os::unix::io::{AsRawFd, RawFd};
|
||||
@ -34,7 +34,7 @@ impl StreamOptions for BufStream<Box<StreamWrapper>> {
|
||||
fn set_read_timeout(&self, timeout: Option<Duration>) -> io::Result<()> {
|
||||
match self.get_ref().get_ref().0 {
|
||||
InternalStream::Tcp(ref s) => s.set_read_timeout(timeout),
|
||||
#[cfg(any(feature = "unix_socket", feature = "nightly"))]
|
||||
#[cfg(any(feature = "unix_socket", all(unix, feature = "nightly")))]
|
||||
InternalStream::Unix(ref s) => s.set_read_timeout(timeout),
|
||||
}
|
||||
}
|
||||
@ -42,7 +42,7 @@ impl StreamOptions for BufStream<Box<StreamWrapper>> {
|
||||
fn set_nonblocking(&self, nonblock: bool) -> io::Result<()> {
|
||||
match self.get_ref().get_ref().0 {
|
||||
InternalStream::Tcp(ref s) => s.set_nonblocking(nonblock),
|
||||
#[cfg(any(feature = "unix_socket", feature = "nightly"))]
|
||||
#[cfg(any(feature = "unix_socket", all(unix, feature = "nightly")))]
|
||||
InternalStream::Unix(ref s) => s.set_nonblocking(nonblock),
|
||||
}
|
||||
}
|
||||
@ -58,7 +58,7 @@ impl fmt::Debug for Stream {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self.0 {
|
||||
InternalStream::Tcp(ref s) => fmt::Debug::fmt(s, fmt),
|
||||
#[cfg(any(feature = "unix_socket", feature = "nightly"))]
|
||||
#[cfg(any(feature = "unix_socket", all(unix, feature = "nightly")))]
|
||||
InternalStream::Unix(ref s) => fmt::Debug::fmt(s, fmt),
|
||||
}
|
||||
}
|
||||
@ -95,7 +95,7 @@ impl AsRawFd for Stream {
|
||||
fn as_raw_fd(&self) -> RawFd {
|
||||
match self.0 {
|
||||
InternalStream::Tcp(ref s) => s.as_raw_fd(),
|
||||
#[cfg(any(feature = "unix_socket", feature = "nightly"))]
|
||||
#[cfg(any(feature = "unix_socket", all(unix, feature = "nightly")))]
|
||||
InternalStream::Unix(ref s) => s.as_raw_fd(),
|
||||
}
|
||||
}
|
||||
@ -113,7 +113,7 @@ impl AsRawSocket for Stream {
|
||||
|
||||
enum InternalStream {
|
||||
Tcp(TcpStream),
|
||||
#[cfg(any(feature = "unix_socket", feature = "nightly"))]
|
||||
#[cfg(any(feature = "unix_socket", all(unix, feature = "nightly")))]
|
||||
Unix(UnixStream),
|
||||
}
|
||||
|
||||
@ -121,7 +121,7 @@ impl Read for InternalStream {
|
||||
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
|
||||
match *self {
|
||||
InternalStream::Tcp(ref mut s) => s.read(buf),
|
||||
#[cfg(any(feature = "unix_socket", feature = "nightly"))]
|
||||
#[cfg(any(feature = "unix_socket", all(unix, feature = "nightly")))]
|
||||
InternalStream::Unix(ref mut s) => s.read(buf),
|
||||
}
|
||||
}
|
||||
@ -131,7 +131,7 @@ impl Write for InternalStream {
|
||||
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
|
||||
match *self {
|
||||
InternalStream::Tcp(ref mut s) => s.write(buf),
|
||||
#[cfg(any(feature = "unix_socket", feature = "nightly"))]
|
||||
#[cfg(any(feature = "unix_socket", all(unix, feature = "nightly")))]
|
||||
InternalStream::Unix(ref mut s) => s.write(buf),
|
||||
}
|
||||
}
|
||||
@ -139,7 +139,7 @@ impl Write for InternalStream {
|
||||
fn flush(&mut self) -> io::Result<()> {
|
||||
match *self {
|
||||
InternalStream::Tcp(ref mut s) => s.flush(),
|
||||
#[cfg(any(feature = "unix_socket", feature = "nightly"))]
|
||||
#[cfg(any(feature = "unix_socket", all(unix, feature = "nightly")))]
|
||||
InternalStream::Unix(ref mut s) => s.flush(),
|
||||
}
|
||||
}
|
||||
@ -151,7 +151,7 @@ fn open_socket(params: &ConnectParams) -> Result<InternalStream, ConnectError> {
|
||||
ConnectTarget::Tcp(ref host) => {
|
||||
Ok(try!(TcpStream::connect(&(&**host, port)).map(InternalStream::Tcp)))
|
||||
}
|
||||
#[cfg(any(feature = "unix_socket", feature = "nightly"))]
|
||||
#[cfg(any(feature = "unix_socket", all(unix, feature = "nightly")))]
|
||||
ConnectTarget::Unix(ref path) => {
|
||||
let path = path.join(&format!(".s.PGSQL.{}", port));
|
||||
Ok(try!(UnixStream::connect(&path).map(InternalStream::Unix)))
|
||||
@ -185,7 +185,7 @@ pub fn initialize_stream(params: &ConnectParams,
|
||||
// Postgres doesn't support SSL over unix sockets
|
||||
let host = match params.target {
|
||||
ConnectTarget::Tcp(ref host) => host,
|
||||
#[cfg(any(feature = "unix_socket", feature = "nightly"))]
|
||||
#[cfg(any(feature = "unix_socket", all(unix, feature = "nightly")))]
|
||||
ConnectTarget::Unix(_) => return Err(ConnectError::Io(::bad_response())),
|
||||
};
|
||||
|
||||
|
@ -75,7 +75,7 @@ fn test_connection_finish() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg_attr(not(any(feature = "unix_socket", feature = "nightly")), ignore)]
|
||||
#[cfg_attr(not(any(feature = "unix_socket", all(unix, feature = "nightly"))), ignore)]
|
||||
fn test_unix_connection() {
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", SslMode::None));
|
||||
let stmt = or_panic!(conn.prepare("SHOW unix_socket_directories"));
|
||||
|
Loading…
Reference in New Issue
Block a user