@@ -18,9 +18,9 @@ pub trait AsyncReadWriter: 'static + Unpin + Send + Read + Write {}
1818impl < 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
2424where
2525 T : AsyncReadWriter ,
2626{
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" )
0 commit comments