Skip to content

Commit adc81a9

Browse files
committed
Some random cleanup
1 parent b926745 commit adc81a9

2 files changed

Lines changed: 24 additions & 23 deletions

File tree

src/lib.rs

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ use std::from_str::FromStr;
8787
use std::io::{BufferedStream, IoResult};
8888
use std::io::net::ip::Port;
8989
use std::mem;
90-
use std::owned::Box;
9190
use std::task;
9291
use std::fmt;
9392

@@ -107,8 +106,7 @@ use error::{InvalidUrl,
107106
UnsupportedAuthentication,
108107
PgWrongConnection,
109108
PgWrongTransaction};
110-
use io::{MaybeSslStream,
111-
InternalStream};
109+
use io::{MaybeSslStream, InternalStream};
112110
use message::{AuthenticationCleartextPassword,
113111
AuthenticationGSS,
114112
AuthenticationKerberosV5,
@@ -435,19 +433,6 @@ impl InnerPostgresConnection {
435433
let params = try!(params.into_connect_params());
436434
let stream = try!(io::initialize_stream(&params, ssl));
437435

438-
let mut conn = InnerPostgresConnection {
439-
stream: BufferedStream::new(stream),
440-
next_stmt_id: 0,
441-
notice_handler: box DefaultNoticeHandler,
442-
notifications: RingBuf::new(),
443-
cancel_data: PostgresCancelData { process_id: 0, secret_key: 0 },
444-
unknown_types: HashMap::new(),
445-
desynchronized: false,
446-
finished: false,
447-
trans_depth: 0,
448-
canary: CANARY,
449-
};
450-
451436
let PostgresConnectParams {
452437
user,
453438
password,
@@ -461,6 +446,19 @@ impl InnerPostgresConnection {
461446
None => return Err(MissingUser),
462447
};
463448

449+
let mut conn = InnerPostgresConnection {
450+
stream: BufferedStream::new(stream),
451+
next_stmt_id: 0,
452+
notice_handler: box DefaultNoticeHandler,
453+
notifications: RingBuf::new(),
454+
cancel_data: PostgresCancelData { process_id: 0, secret_key: 0 },
455+
unknown_types: HashMap::new(),
456+
desynchronized: false,
457+
finished: false,
458+
trans_depth: 0,
459+
canary: CANARY,
460+
};
461+
464462
options.push(("client_encoding".to_owned(), "UTF8".to_owned()));
465463
// Postgres uses the value of TimeZone as the time zone for TIMESTAMP
466464
// WITH TIME ZONE values. Timespec converts to GMT internally.

src/pool.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,16 @@ impl PostgresConnectionPool {
7979
pub fn get_connection(&self) -> PooledPostgresConnection {
8080
let mut pool = self.pool.lock();
8181

82-
while pool.pool.is_empty() {
83-
pool.cond.wait();
84-
}
85-
86-
PooledPostgresConnection {
87-
pool: self.clone(),
88-
conn: Some(pool.pool.pop().unwrap())
82+
loop {
83+
match pool.pool.pop() {
84+
Some(conn) => {
85+
return PooledPostgresConnection {
86+
pool: self.clone(),
87+
conn: Some(conn),
88+
};
89+
}
90+
None => pool.cond.wait()
91+
}
8992
}
9093
}
9194
}

0 commit comments

Comments
 (0)