@@ -150,7 +150,7 @@ pub use stmt::{NormalPostgresStatement,
150
150
RowIndex ,
151
151
TransactionalPostgresStatement } ;
152
152
153
- macro_rules! if_ok_pg_conn (
153
+ macro_rules! try_pg_conn (
154
154
( $e: expr) => (
155
155
match $e {
156
156
Ok ( ok) => ok,
@@ -159,7 +159,7 @@ macro_rules! if_ok_pg_conn(
159
159
)
160
160
)
161
161
162
- macro_rules! if_ok_pg (
162
+ macro_rules! try_pg (
163
163
( $e: expr) => (
164
164
match $e {
165
165
Ok ( ok) => ok,
@@ -168,7 +168,7 @@ macro_rules! if_ok_pg(
168
168
)
169
169
)
170
170
171
- macro_rules! if_ok_desync (
171
+ macro_rules! try_desync (
172
172
( $e: expr) => (
173
173
match $e {
174
174
Ok ( ok) => ok,
@@ -297,12 +297,12 @@ pub fn cancel_query(url: &str, ssl: &SslMode, data: PostgresCancelData)
297
297
Err ( err) => return Err ( err)
298
298
} ;
299
299
300
- if_ok_pg_conn ! ( socket. write_message( & CancelRequest {
300
+ try_pg_conn ! ( socket. write_message( & CancelRequest {
301
301
code: message:: CANCEL_CODE ,
302
302
process_id: data. process_id,
303
303
secret_key: data. secret_key
304
304
} ) ) ;
305
- if_ok_pg_conn ! ( socket. flush( ) ) ;
305
+ try_pg_conn ! ( socket. flush( ) ) ;
306
306
307
307
Ok ( ( ) )
308
308
}
@@ -337,10 +337,10 @@ fn initialize_stream(host: &str, port: Port, ssl: &SslMode)
337
337
& RequireSsl ( ref ctx) => ( true , ctx)
338
338
} ;
339
339
340
- if_ok_pg_conn ! ( socket. write_message( & SslRequest { code: message:: SSL_CODE } ) ) ;
341
- if_ok_pg_conn ! ( socket. flush( ) ) ;
340
+ try_pg_conn ! ( socket. write_message( & SslRequest { code: message:: SSL_CODE } ) ) ;
341
+ try_pg_conn ! ( socket. flush( ) ) ;
342
342
343
- if if_ok_pg_conn ! ( socket. read_u8( ) ) == 'N' as u8 {
343
+ if try_pg_conn ! ( socket. read_u8( ) ) == 'N' as u8 {
344
344
if ssl_required {
345
345
return Err ( NoSslSupport ) ;
346
346
} else {
@@ -432,10 +432,7 @@ impl InnerPostgresConnection {
432
432
None => DEFAULT_PORT
433
433
} ;
434
434
435
- let stream = match initialize_stream ( host, port, ssl) {
436
- Ok ( stream) => stream,
437
- Err ( err) => return Err ( err)
438
- } ;
435
+ let stream = try!( initialize_stream ( host, port, ssl) ) ;
439
436
440
437
let mut conn = InnerPostgresConnection {
441
438
stream : BufferedStream :: new ( stream) ,
@@ -459,18 +456,15 @@ impl InnerPostgresConnection {
459
456
path. shift_char ( ) ;
460
457
args. push ( ( ~"database", path) ) ;
461
458
}
462
- if_ok_pg_conn ! ( conn. write_messages( [ StartupMessage {
459
+ try_pg_conn ! ( conn. write_messages( [ StartupMessage {
463
460
version: message:: PROTOCOL_VERSION ,
464
461
parameters: args. as_slice( )
465
462
} ] ) ) ;
466
463
467
- match conn. handle_auth ( user) {
468
- Err ( err) => return Err ( err) ,
469
- Ok ( ( ) ) => { }
470
- }
464
+ try!( conn. handle_auth ( user) ) ;
471
465
472
466
loop {
473
- match if_ok_pg_conn ! ( conn. read_message( ) ) {
467
+ match try_pg_conn ! ( conn. read_message( ) ) {
474
468
BackendKeyData { process_id, secret_key } => {
475
469
conn. cancel_data . process_id = process_id;
476
470
conn. cancel_data . secret_key = secret_key;
@@ -488,15 +482,15 @@ impl InnerPostgresConnection {
488
482
fn write_messages ( & mut self , messages : & [ FrontendMessage ] ) -> IoResult < ( ) > {
489
483
assert ! ( !self . desynchronized) ;
490
484
for message in messages. iter ( ) {
491
- if_ok_desync ! ( self . stream. write_message( message) ) ;
485
+ try_desync ! ( self . stream. write_message( message) ) ;
492
486
}
493
- Ok ( if_ok_desync ! ( self . stream. flush( ) ) )
487
+ Ok ( try_desync ! ( self . stream. flush( ) ) )
494
488
}
495
489
496
490
fn read_message ( & mut self ) -> IoResult < BackendMessage > {
497
491
assert ! ( !self . desynchronized) ;
498
492
loop {
499
- match if_ok_desync ! ( self . stream. read_message( ) ) {
493
+ match try_desync ! ( self . stream. read_message( ) ) {
500
494
NoticeResponse { fields } =>
501
495
self . notice_handler . handle ( PostgresDbError :: new ( fields) ) ,
502
496
NotificationResponse { pid, channel, payload } =>
@@ -514,14 +508,14 @@ impl InnerPostgresConnection {
514
508
515
509
fn handle_auth ( & mut self , user : UserInfo ) ->
516
510
Result < ( ) , PostgresConnectError > {
517
- match if_ok_pg_conn ! ( self . read_message( ) ) {
511
+ match try_pg_conn ! ( self . read_message( ) ) {
518
512
AuthenticationOk => return Ok ( ( ) ) ,
519
513
AuthenticationCleartextPassword => {
520
514
let pass = match user. pass {
521
515
Some ( pass) => pass,
522
516
None => return Err ( MissingPassword )
523
517
} ;
524
- if_ok_pg_conn ! ( self . write_messages( [ PasswordMessage { password: pass } ] ) ) ;
518
+ try_pg_conn ! ( self . write_messages( [ PasswordMessage { password: pass } ] ) ) ;
525
519
}
526
520
AuthenticationMD5Password { salt } => {
527
521
let UserInfo { user, pass } = user;
@@ -537,7 +531,7 @@ impl InnerPostgresConnection {
537
531
hasher. update ( output. as_bytes ( ) ) ;
538
532
hasher. update ( salt) ;
539
533
let output = "md5" + hasher. final ( ) . to_hex ( ) ;
540
- if_ok_pg_conn ! ( self . write_messages( [ PasswordMessage {
534
+ try_pg_conn ! ( self . write_messages( [ PasswordMessage {
541
535
password: output. as_slice( )
542
536
} ] ) ) ;
543
537
}
@@ -550,7 +544,7 @@ impl InnerPostgresConnection {
550
544
_ => unreachable ! ( )
551
545
}
552
546
553
- match if_ok_pg_conn ! ( self . read_message( ) ) {
547
+ match try_pg_conn ! ( self . read_message( ) ) {
554
548
AuthenticationOk => Ok ( ( ) ) ,
555
549
ErrorResponse { fields } =>
556
550
Err ( PgConnectDbError ( PostgresDbError :: new ( fields) ) ) ,
@@ -569,7 +563,7 @@ impl InnerPostgresConnection {
569
563
self . next_stmt_id += 1 ;
570
564
571
565
let types = [ ] ;
572
- if_ok_pg ! ( self . write_messages( [
566
+ try_pg ! ( self . write_messages( [
573
567
Parse {
574
568
name: stmt_name,
575
569
query: query,
@@ -581,7 +575,7 @@ impl InnerPostgresConnection {
581
575
} ,
582
576
Sync ] ) ) ;
583
577
584
- match if_ok_pg ! ( self . read_message( ) ) {
578
+ match try_pg ! ( self . read_message( ) ) {
585
579
ParseComplete => { }
586
580
ErrorResponse { fields } => {
587
581
try!( self . wait_for_ready ( ) ) ;
@@ -590,13 +584,13 @@ impl InnerPostgresConnection {
590
584
_ => unreachable ! ( )
591
585
}
592
586
593
- let mut param_types: Vec < PostgresType > = match if_ok_pg ! ( self . read_message( ) ) {
587
+ let mut param_types: Vec < PostgresType > = match try_pg ! ( self . read_message( ) ) {
594
588
ParameterDescription { types } =>
595
589
types. iter ( ) . map ( |ty| PostgresType :: from_oid ( * ty) ) . collect ( ) ,
596
590
_ => unreachable ! ( )
597
591
} ;
598
592
599
- let mut result_desc: Vec < ResultDescription > = match if_ok_pg ! ( self . read_message( ) ) {
593
+ let mut result_desc: Vec < ResultDescription > = match try_pg ! ( self . read_message( ) ) {
600
594
RowDescription { descriptions } =>
601
595
descriptions. move_iter ( ) . map ( |desc| {
602
596
stmt:: make_ResultDescription ( desc)
@@ -653,7 +647,7 @@ impl InnerPostgresConnection {
653
647
}
654
648
655
649
fn wait_for_ready ( & mut self ) -> Result < ( ) , PostgresError > {
656
- match if_ok_pg ! ( self . read_message( ) ) {
650
+ match try_pg ! ( self . read_message( ) ) {
657
651
ReadyForQuery { .. } => Ok ( ( ) ) ,
658
652
_ => unreachable ! ( )
659
653
}
@@ -662,11 +656,11 @@ impl InnerPostgresConnection {
662
656
fn quick_query ( & mut self , query : & str )
663
657
-> Result < Vec < Vec < Option < ~str > > > , PostgresError > {
664
658
check_desync ! ( self ) ;
665
- if_ok_pg ! ( self . write_messages( [ Query { query: query } ] ) ) ;
659
+ try_pg ! ( self . write_messages( [ Query { query: query } ] ) ) ;
666
660
667
661
let mut result = Vec :: new ( ) ;
668
662
loop {
669
- match if_ok_pg ! ( self . read_message( ) ) {
663
+ match try_pg ! ( self . read_message( ) ) {
670
664
ReadyForQuery { .. } => break ,
671
665
DataRow { row } =>
672
666
result. push ( row. move_iter ( ) . map ( |opt|
@@ -684,7 +678,7 @@ impl InnerPostgresConnection {
684
678
685
679
fn finish_inner ( & mut self ) -> Result < ( ) , PostgresError > {
686
680
check_desync ! ( self ) ;
687
- Ok ( if_ok_pg ! ( self . write_messages( [ Terminate ] ) ) )
681
+ Ok ( try_pg ! ( self . write_messages( [ Terminate ] ) ) )
688
682
}
689
683
}
690
684
0 commit comments