Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ec86a35

Browse files
committed
uds pass tests
1 parent e6d66a2 commit ec86a35

File tree

3 files changed

+24
-23
lines changed

3 files changed

+24
-23
lines changed

‎src/lib.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
33
#![warn(missing_docs)]
44

5-
pub use stream::AsyncStream;
5+
pub use socket::Socket;
66
pub use tokio_postgres::*;
77

8+
use socket::connect_socket;
89
use std::io;
9-
use stream::connect_stream;
1010
use tokio_postgres::tls::{NoTls, NoTlsStream, TlsConnect};
1111
use tokio_postgres::{Client, Connection};
1212

@@ -31,7 +31,7 @@ use tokio_postgres::{Client, Connection};
3131
#[inline]
3232
pub async fn connect(
3333
config: Config,
34-
) -> io::Result<(Client, Connection<AsyncStream, NoTlsStream>)> {
34+
) -> io::Result<(Client, Connection<Socket, NoTlsStream>)> {
3535
connect_tls(config, NoTls).await
3636
}
3737

@@ -57,11 +57,11 @@ pub async fn connect(
5757
pub async fn connect_tls<T>(
5858
config: Config,
5959
tls: T,
60-
) -> io::Result<(Client, Connection<AsyncStream, T::Stream>)>
60+
) -> io::Result<(Client, Connection<Socket, T::Stream>)>
6161
where
62-
T: TlsConnect<AsyncStream>,
62+
T: TlsConnect<Socket>,
6363
{
64-
let stream = connect_stream(&config).await?;
64+
let stream = connect_socket(&config).await?;
6565
connect_raw(stream, config, tls).await
6666
}
6767

@@ -88,15 +88,15 @@ pub async fn connect_raw<S, T>(
8888
stream: S,
8989
config: Config,
9090
tls: T,
91-
) -> io::Result<(Client, Connection<AsyncStream, T::Stream>)>
91+
) -> io::Result<(Client, Connection<Socket, T::Stream>)>
9292
where
93-
S: Into<AsyncStream>,
94-
T: TlsConnect<AsyncStream>,
93+
S: Into<Socket>,
94+
T: TlsConnect<Socket>,
9595
{
9696
config
9797
.connect_raw(stream.into(), tls)
9898
.await
9999
.map_err(|err| io::Error::new(io::ErrorKind::Other, err))
100100
}
101101

102-
mod stream;
102+
mod socket;

‎src/stream.rs renamed to ‎src/socket.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ pub trait AsyncReadWriter: 'static + Unpin + Send + Read + Write {}
1818
impl<T> AsyncReadWriter for T where T: 'static + Unpin + Send + Read + Write {}
1919

2020
/// A adaptor between futures::io::{AsyncRead, AsyncWrite} and tokio::io::{AsyncRead, AsyncWrite}.
21-
pub struct AsyncStream(Box<dyn AsyncReadWriter>);
21+
pub struct Socket(Box<dyn AsyncReadWriter>);
2222

23-
impl<T> From<T> for AsyncStream
23+
impl<T> From<T> for Socket
2424
where
2525
T: AsyncReadWriter,
2626
{
@@ -29,7 +29,7 @@ where
2929
}
3030
}
3131

32-
impl AsyncRead for AsyncStream {
32+
impl AsyncRead for Socket {
3333
#[inline]
3434
unsafe fn prepare_uninitialized_buffer(&self, _buf: &mut [MaybeUninit<u8>]) -> bool {
3535
false
@@ -45,7 +45,7 @@ impl AsyncRead for AsyncStream {
4545
}
4646
}
4747

48-
impl AsyncWrite for AsyncStream {
48+
impl AsyncWrite for Socket {
4949
#[inline]
5050
fn poll_write(
5151
mut self: Pin<&mut Self>,
@@ -76,19 +76,20 @@ impl AsyncWrite for AsyncStream {
7676
///
7777
///
7878
#[inline]
79-
pub async fn connect_stream(config: &Config) -> io::Result<AsyncStream> {
79+
pub async fn connect_socket(config: &Config) -> io::Result<Socket> {
8080
let mut error = io::Error::new(io::ErrorKind::Other, "host missing");
8181
let mut ports = config.get_ports().iter().cloned();
8282
for host in config.get_hosts() {
83+
let port = ports.next().unwrap_or(DEFAULT_PORT);
8384
let result = match host {
8485
#[cfg(unix)]
85-
Host::Unix(path) => UnixStream::connect(path).await.map(Into::into),
86-
Host::Tcp(tcp) => {
87-
let port = ports.next().unwrap_or(DEFAULT_PORT);
88-
TcpStream::connect((tcp.as_str(), port))
89-
.await
90-
.map(Into::into)
86+
Host::Unix(path) => {
87+
let sock = path.join(format!(".s.PGSQL.{}", port));
88+
UnixStream::connect(sock).await.map(Into::into)
9189
}
90+
Host::Tcp(tcp) => TcpStream::connect((tcp.as_str(), port))
91+
.await
92+
.map(Into::into),
9293
#[cfg(not(unix))]
9394
Host::Unix(_) => {
9495
io::Error::new(io::ErrorKind::Other, "unix domain socket is unsupported")

‎tests/benchmark.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ fn benchmark() -> Result<(), Box<dyn Error>> {
2828
println!(" - tokio_postgres on tokio runtime:");
2929
let elapsed = tokio_rr.block_on(tokio_postgres(&tcp_url))?;
3030
println!(" - tcp: {} us/q", elapsed.as_micros() / queries);
31-
// let elapsed = tokio_rr.block_on(tokio_postgres(&uds_url))?;
32-
// println!(" - uds: {} us/q", elapsed.as_micros() / queries);
31+
let elapsed = tokio_rr.block_on(tokio_postgres(&uds_url))?;
32+
println!(" - uds: {} us/q", elapsed.as_micros() / queries);
3333
Ok(())
3434
}
3535

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /