@@ -328,13 +328,6 @@ fn open_socket(host: &str, port: Port)
328328 Err ( SocketError ( err. unwrap ( ) ) )
329329}
330330
331- fn open_unix ( path : & Path ) -> Result < UnixStream , PostgresConnectError > {
332- match UnixStream :: connect ( path) {
333- Ok ( unix) => Ok ( unix) ,
334- Err ( err) => Err ( SocketError ( err) )
335- }
336- }
337-
338331fn initialize_stream ( host : & str , port : Port , ssl : & SslMode )
339332 -> Result < InternalStream , PostgresConnectError > {
340333 let mut socket = match open_socket ( host, port) {
@@ -367,9 +360,9 @@ fn initialize_stream(host: &str, port: Port, ssl: &SslMode)
367360
368361fn initialize_unix ( path : & Path )
369362 -> Result < InternalStream , PostgresConnectError > {
370- match open_unix ( path) {
363+ match UnixStream :: connect ( path) {
371364 Ok ( unix) => Ok ( NormalUnix ( unix) ) ,
372- Err ( err) => Err ( err)
365+ Err ( err) => Err ( SocketError ( err) )
373366 }
374367}
375368
@@ -454,31 +447,13 @@ impl InnerPostgresConnection {
454447
455448 let stream = try!( initialize_stream ( host, port, ssl) ) ;
456449
457- let conn = InnerPostgresConnection {
458- stream : BufferedStream :: new ( stream) ,
459- next_stmt_id : 0 ,
460- notice_handler : ~DefaultNoticeHandler ,
461- notifications : RingBuf :: new ( ) ,
462- cancel_data : PostgresCancelData { process_id : 0 , secret_key : 0 } ,
463- unknown_types : HashMap :: new ( ) ,
464- desynchronized : false ,
465- finished : false ,
466- canary : CANARY ,
467- } ;
468-
469- args. push ( ( ~"client_encoding", ~"UTF8 ") ) ;
470- // Postgres uses the value of TimeZone as the time zone for TIMESTAMP
471- // WITH TIME ZONE values. Timespec converts to GMT internally.
472- args. push ( ( ~"TimeZone ", ~"GMT ") ) ;
473- // We have to clone here since we need the user again for auth
474- args. push ( ( ~"user", user. user . clone ( ) ) ) ;
475450 if !path. is_empty ( ) {
476451 // path contains the leading /
477452 let ( _, path) = path. slice_shift_char ( ) ;
478453 args. push ( ( ~"database", path. to_owned ( ) ) ) ;
479454 }
480455
481- InnerPostgresConnection :: connect_finish ( conn , args, user)
456+ InnerPostgresConnection :: connect_finish ( stream , args, user)
482457 }
483458
484459 fn connect_unix ( socket_dir : & Path , port : Port , user : UserInfo , database : ~str )
@@ -488,7 +463,16 @@ impl InnerPostgresConnection {
488463
489464 let stream = try!( initialize_unix ( & socket) ) ;
490465
491- let conn = InnerPostgresConnection {
466+ let mut args = Vec :: new ( ) ;
467+ args. push ( ( ~"database", database) ) ;
468+
469+ InnerPostgresConnection :: connect_finish ( stream, args, user)
470+ }
471+
472+ fn connect_finish ( stream : InternalStream , mut args : Vec < ( ~str , ~str ) > , user : UserInfo )
473+ -> Result < InnerPostgresConnection , PostgresConnectError > {
474+
475+ let mut conn = InnerPostgresConnection {
492476 stream : BufferedStream :: new ( stream) ,
493477 next_stmt_id : 0 ,
494478 notice_handler : ~DefaultNoticeHandler ,
@@ -500,21 +484,13 @@ impl InnerPostgresConnection {
500484 canary : CANARY ,
501485 } ;
502486
503- let mut args = Vec :: new ( ) ;
504-
505487 args. push ( ( ~"client_encoding", ~"UTF8 ") ) ;
506488 // Postgres uses the value of TimeZone as the time zone for TIMESTAMP
507489 // WITH TIME ZONE values. Timespec converts to GMT internally.
508490 args. push ( ( ~"TimeZone ", ~"GMT ") ) ;
509491 // We have to clone here since we need the user again for auth
510492 args. push ( ( ~"user", user. user . clone ( ) ) ) ;
511- args. push ( ( ~"database", database) ) ;
512493
513- InnerPostgresConnection :: connect_finish ( conn, args, user)
514- }
515-
516- fn connect_finish ( mut conn : InnerPostgresConnection , args : Vec < ( ~str , ~str ) > , user : UserInfo )
517- -> Result < InnerPostgresConnection , PostgresConnectError > {
518494 try_pg_conn ! ( conn. write_messages( [ StartupMessage {
519495 version: message:: PROTOCOL_VERSION ,
520496 parameters: args. as_slice( )
@@ -796,7 +772,9 @@ impl PostgresConnection {
796772 ///
797773 /// # Example
798774 ///
799- /// ```rust,no_run
775+ /// ```rust,ignore
776+ /// # extern crate url;
777+ /// # use url::UserInfo;
800778 /// # use postgres::PostgresConnection;
801779 /// let path = Path::new("/tmp");
802780 /// let port = 5432;
0 commit comments