@@ -18,9 +18,9 @@ pub trait AsyncReadWriter: 'static + Unpin + Send + Read + Write {}
18
18
impl < T > AsyncReadWriter for T where T : ' static + Unpin + Send + Read + Write { }
19
19
20
20
/// 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 > ) ;
22
22
23
- impl < T > From < T > for AsyncStream
23
+ impl < T > From < T > for Socket
24
24
where
25
25
T : AsyncReadWriter ,
26
26
{
29
29
}
30
30
}
31
31
32
- impl AsyncRead for AsyncStream {
32
+ impl AsyncRead for Socket {
33
33
#[ inline]
34
34
unsafe fn prepare_uninitialized_buffer ( & self , _buf : & mut [ MaybeUninit < u8 > ] ) -> bool {
35
35
false
@@ -45,7 +45,7 @@ impl AsyncRead for AsyncStream {
45
45
}
46
46
}
47
47
48
- impl AsyncWrite for AsyncStream {
48
+ impl AsyncWrite for Socket {
49
49
#[ inline]
50
50
fn poll_write (
51
51
mut self : Pin < & mut Self > ,
@@ -76,19 +76,20 @@ impl AsyncWrite for AsyncStream {
76
76
///
77
77
///
78
78
#[ inline]
79
- pub async fn connect_stream ( config : & Config ) -> io:: Result < AsyncStream > {
79
+ pub async fn connect_socket ( config : & Config ) -> io:: Result < Socket > {
80
80
let mut error = io:: Error :: new ( io:: ErrorKind :: Other , "host missing" ) ;
81
81
let mut ports = config. get_ports ( ) . iter ( ) . cloned ( ) ;
82
82
for host in config. get_hosts ( ) {
83
+ let port = ports. next ( ) . unwrap_or ( DEFAULT_PORT ) ;
83
84
let result = match host {
84
85
#[ 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)
91
89
}
90
+ Host :: Tcp ( tcp) => TcpStream :: connect ( ( tcp. as_str ( ) , port) )
91
+ . await
92
+ . map ( Into :: into) ,
92
93
#[ cfg( not( unix) ) ]
93
94
Host :: Unix ( _) => {
94
95
io:: Error :: new ( io:: ErrorKind :: Other , "unix domain socket is unsupported" )
0 commit comments