3
3
//! package.
4
4
//!
5
5
//! ```rust,no_run
6
- //! # #![allow(unstable)]
7
6
//! extern crate postgres;
8
7
//!
9
8
//! use postgres::{Connection, SslMode};
42
41
//! }
43
42
//! }
44
43
//! ```
45
- #![ doc( html_root_url="https://sfackler.github.io/rust-postgres/doc/v0.9.0 " ) ]
44
+ #![ doc( html_root_url="https://sfackler.github.io/rust-postgres/doc/v0.9.2 " ) ]
46
45
#![ warn( missing_docs) ]
47
46
48
47
extern crate bufstream;
49
48
extern crate byteorder;
50
- extern crate crypto;
51
49
#[ macro_use]
52
50
extern crate log;
53
51
extern crate phf;
@@ -57,8 +55,7 @@ extern crate unix_socket;
57
55
extern crate debug_builders;
58
56
59
57
use bufstream:: BufStream ;
60
- use crypto:: digest:: Digest ;
61
- use crypto:: md5:: Md5 ;
58
+ use md5:: Md5 ;
62
59
use debug_builders:: DebugStruct ;
63
60
use std:: ascii:: AsciiExt ;
64
61
use std:: borrow:: ToOwned ;
@@ -95,6 +92,7 @@ mod url;
95
92
mod util;
96
93
pub mod types;
97
94
pub mod rows;
95
+ mod md5;
98
96
99
97
const TYPEINFO_QUERY : & ' static str = "t" ;
100
98
@@ -174,7 +172,7 @@ impl IntoConnectParams for Url {
174
172
175
173
#[ cfg( feature = "unix_socket" ) ]
176
174
fn make_unix ( maybe_path : String ) -> result:: Result < ConnectTarget , ConnectError > {
177
- Ok ( ConnectTarget :: Unix ( PathBuf :: from ( & maybe_path) ) )
175
+ Ok ( ConnectTarget :: Unix ( PathBuf :: from ( maybe_path) ) )
178
176
}
179
177
#[ cfg( not( feature = "unix_socket" ) ) ]
180
178
fn make_unix ( _: String ) -> result:: Result < ConnectTarget , ConnectError > {
@@ -289,62 +287,6 @@ impl<'conn> Notifications<'conn> {
289
287
_ => unreachable ! ( )
290
288
}
291
289
}
292
-
293
- /*
294
- /// Returns the oldest pending notification
295
- ///
296
- /// If no notifications are pending, blocks for up to `timeout` time, after
297
- /// which `None` is returned.
298
- ///
299
- /// ## Example
300
- ///
301
- /// ```rust,no_run
302
- /// # #![allow(unstable)]
303
- /// use std::old_io::{IoError, IoErrorKind};
304
- /// use std::time::Duration;
305
- ///
306
- /// use postgres::Error;
307
- ///
308
- /// # let conn = postgres::Connection::connect("", &postgres::SslMode::None).unwrap();
309
- /// match conn.notifications().next_block_for(Duration::seconds(2)) {
310
- /// Some(Ok(notification)) => println!("notification: {}", notification.payload),
311
- /// Some(Err(e)) => println!("Error: {:?}", e),
312
- /// None => println!("Wait for notification timed out"),
313
- /// }
314
- /// ```
315
- pub fn next_block_for(&mut self, timeout: Duration) -> Option<Result<Notification>> {
316
- if let Some(notification) = self.next() {
317
- return Some(Ok(notification));
318
- }
319
-
320
- let mut conn = self.conn.conn.borrow_mut();
321
- if conn.desynchronized {
322
- return Some(Err(Error::StreamDesynchronized));
323
- }
324
-
325
- let end = SteadyTime::now() + timeout;
326
- loop {
327
- let timeout = max(Duration::zero(), end - SteadyTime::now()).num_milliseconds() as u64;
328
- conn.stream.set_read_timeout(Some(timeout));
329
- match conn.read_one_message() {
330
- Ok(Some(NotificationResponse { pid, channel, payload })) => {
331
- return Some(Ok(Notification {
332
- pid: pid,
333
- channel: channel,
334
- payload: payload
335
- }))
336
- }
337
- Ok(Some(_)) => unreachable!(),
338
- Ok(None) => {}
339
- Err(IoError { kind: IoErrorKind::TimedOut, .. }) => {
340
- conn.desynchronized = false;
341
- return None;
342
- }
343
- Err(e) => return Some(Err(Error::IoError(e))),
344
- }
345
- }
346
- }
347
- */
348
290
}
349
291
350
292
/// Contains information necessary to cancel queries for a session.
@@ -467,9 +409,19 @@ pub enum SslMode {
467
409
/// The connection will not use SSL.
468
410
None ,
469
411
/// The connection will use SSL if the backend supports it.
470
- Prefer ( Box < NegotiateSsl > ) ,
412
+ Prefer ( Box < NegotiateSsl +std :: marker :: Sync + Send > ) ,
471
413
/// The connection must use SSL.
472
- Require ( Box < NegotiateSsl > ) ,
414
+ Require ( Box < NegotiateSsl +std:: marker:: Sync +Send > ) ,
415
+ }
416
+
417
+ impl fmt:: Debug for SslMode {
418
+ fn fmt ( & self , fmt : & mut fmt:: Formatter ) -> fmt:: Result {
419
+ match * self {
420
+ SslMode :: None => fmt. write_str ( "None" ) ,
421
+ SslMode :: Prefer ( ..) => fmt. write_str ( "Prefer" ) ,
422
+ SslMode :: Require ( ..) => fmt. write_str ( "Require" ) ,
423
+ }
424
+ }
473
425
}
474
426
475
427
#[ derive( Clone ) ]
@@ -479,10 +431,6 @@ struct CachedStatement {
479
431
columns : Vec < Column > ,
480
432
}
481
433
482
- trait SessionInfoNew < ' a > {
483
- fn new ( conn : & ' a InnerConnection ) -> SessionInfo < ' a > ;
484
- }
485
-
486
434
struct InnerConnection {
487
435
stream : BufStream < Box < StreamWrapper > > ,
488
436
notice_handler : Box < HandleNotice > ,
@@ -597,27 +545,19 @@ impl InnerConnection {
597
545
Ok ( try_desync ! ( self , self . stream. flush( ) ) )
598
546
}
599
547
600
- fn read_one_message ( & mut self ) -> std_io:: Result < Option < BackendMessage > > {
601
- debug_assert ! ( !self . desynchronized) ;
602
- match try_desync ! ( self , self . stream. read_message( ) ) {
603
- NoticeResponse { fields } => {
604
- if let Ok ( err) = DbError :: new_raw ( fields) {
605
- self . notice_handler . handle_notice ( err) ;
606
- }
607
- Ok ( None )
608
- }
609
- ParameterStatus { parameter, value } => {
610
- self . parameters . insert ( parameter, value) ;
611
- Ok ( None )
612
- }
613
- val => Ok ( Some ( val) )
614
- }
615
- }
616
-
617
548
fn read_message_with_notification ( & mut self ) -> std_io:: Result < BackendMessage > {
549
+ debug_assert ! ( !self . desynchronized) ;
618
550
loop {
619
- if let Some ( msg) = try!( self . read_one_message ( ) ) {
620
- return Ok ( msg) ;
551
+ match try_desync ! ( self , self . stream. read_message( ) ) {
552
+ NoticeResponse { fields } => {
553
+ if let Ok ( err) = DbError :: new_raw ( fields) {
554
+ self . notice_handler . handle_notice ( err) ;
555
+ }
556
+ }
557
+ ParameterStatus { parameter, value } => {
558
+ self . parameters . insert ( parameter, value) ;
559
+ }
560
+ val => return Ok ( val)
621
561
}
622
562
}
623
563
}
@@ -982,7 +922,6 @@ impl Connection {
982
922
/// ```
983
923
///
984
924
/// ```rust,no_run
985
- /// # #![allow(unstable)]
986
925
/// # use postgres::{Connection, UserInfo, ConnectParams, SslMode, ConnectTarget};
987
926
/// # #[cfg(feature = "unix_socket")]
988
927
/// # fn f() -> Result<(), ::postgres::error::ConnectError> {
@@ -1630,22 +1569,31 @@ impl<'conn> Statement<'conn> {
1630
1569
1631
1570
let mut buf = vec ! [ ] ;
1632
1571
loop {
1633
- match std :: io :: copy ( & mut r. take ( 16 * 1024 ) , & mut buf) {
1572
+ match r. take ( 16 * 1024 ) . read_to_end ( & mut buf) {
1634
1573
Ok ( 0 ) => break ,
1635
- Ok ( len ) => {
1574
+ Ok ( _ ) => {
1636
1575
try_desync ! ( conn, conn. stream. write_message(
1637
- & CopyData {
1638
- data: & buf[ ..len as usize ] ,
1639
- } ) ) ;
1576
+ & CopyData {
1577
+ data: & buf,
1578
+ } ) ) ;
1640
1579
buf. clear ( ) ;
1641
1580
}
1642
1581
Err ( err) => {
1643
- // FIXME better to return the error directly
1644
- try_desync ! ( conn, conn. stream. write_message(
1645
- & CopyFail {
1646
- message: & err. to_string( ) ,
1647
- } ) ) ;
1648
- break ;
1582
+ try!( conn. write_messages ( & [
1583
+ CopyFail {
1584
+ message : "" ,
1585
+ } ,
1586
+ CopyDone ,
1587
+ Sync ] ) ) ;
1588
+ match try!( conn. read_message ( ) ) {
1589
+ ErrorResponse { .. } => { /* expected from the CopyFail */ }
1590
+ _ => {
1591
+ conn. desynchronized = true ;
1592
+ return Err ( Error :: IoError ( bad_response ( ) ) ) ;
1593
+ }
1594
+ }
1595
+ try!( conn. wait_for_ready ( ) ) ;
1596
+ return Err ( Error :: IoError ( err) ) ;
1649
1597
}
1650
1598
}
1651
1599
}
@@ -1833,3 +1781,7 @@ trait LazyRowsNew<'trans, 'stmt> {
1833
1781
finished : bool ,
1834
1782
trans : & ' trans Transaction < ' trans > ) -> LazyRows < ' trans , ' stmt > ;
1835
1783
}
1784
+
1785
+ trait SessionInfoNew < ' a > {
1786
+ fn new ( conn : & ' a InnerConnection ) -> SessionInfo < ' a > ;
1787
+ }
0 commit comments