@@ -21,22 +21,6 @@ use message::{SslRequest, WriteMessage};
2121
2222static DEFAULT_PORT : Port = 5432 ;
2323
24- fn open_tcp_socket ( host : & str , port : Port ) -> Result < TcpStream ,
25- PostgresConnectError > {
26- TcpStream :: connect ( host, port) . map_err ( |e| SocketError ( e) )
27- }
28-
29- fn open_unix_socket ( path : & Path , port : Port ) -> Result < UnixStream ,
30- PostgresConnectError > {
31- let mut socket = path. clone ( ) ;
32- socket. push ( format ! ( ".s.PGSQL.{}" , port) ) ;
33-
34- match UnixStream :: connect ( & socket) {
35- Ok ( unix) => Ok ( unix) ,
36- Err ( err) => Err ( SocketError ( err) )
37- }
38- }
39-
4024pub enum MaybeSslStream < S > {
4125 SslStream ( SslStream < S > ) ,
4226 NormalStream ( S ) ,
@@ -100,12 +84,16 @@ impl Writer for InternalStream {
10084fn open_socket ( params : & PostgresConnectParams )
10185 -> Result < InternalStream , PostgresConnectError > {
10286 let port = params. port . unwrap_or ( DEFAULT_PORT ) ;
103- match params. target {
104- TargetTcp ( ref host) => open_tcp_socket ( host. as_slice ( ) , port)
105- . map ( |s| TcpStream ( s) ) ,
106- TargetUnix ( ref path) => open_unix_socket ( path, port)
107- . map ( |s| UnixStream ( s) ) ,
108- }
87+ let socket = match params. target {
88+ TargetTcp ( ref host) =>
89+ TcpStream :: connect ( host. as_slice ( ) , port) . map ( |s| TcpStream ( s) ) ,
90+ TargetUnix ( ref path) => {
91+ let mut path = path. clone ( ) ;
92+ path. push ( format ! ( ".s.PGSQL.{}" , port) ) ;
93+ UnixStream :: connect ( & path) . map ( |s| UnixStream ( s) )
94+ }
95+ } ;
96+ socket. map_err ( |e| SocketError ( e) )
10997}
11098
11199pub fn initialize_stream ( params : & PostgresConnectParams , ssl : & SslMode )
0 commit comments