Some random cleanup

This commit is contained in:
Steven Fackler 2014-05-27 21:07:58 -07:00
parent b926745f50
commit adc81a9809
2 changed files with 24 additions and 23 deletions

View File

@ -87,7 +87,6 @@ use std::from_str::FromStr;
use std::io::{BufferedStream, IoResult}; use std::io::{BufferedStream, IoResult};
use std::io::net::ip::Port; use std::io::net::ip::Port;
use std::mem; use std::mem;
use std::owned::Box;
use std::task; use std::task;
use std::fmt; use std::fmt;
@ -107,8 +106,7 @@ use error::{InvalidUrl,
UnsupportedAuthentication, UnsupportedAuthentication,
PgWrongConnection, PgWrongConnection,
PgWrongTransaction}; PgWrongTransaction};
use io::{MaybeSslStream, use io::{MaybeSslStream, InternalStream};
InternalStream};
use message::{AuthenticationCleartextPassword, use message::{AuthenticationCleartextPassword,
AuthenticationGSS, AuthenticationGSS,
AuthenticationKerberosV5, AuthenticationKerberosV5,
@ -435,19 +433,6 @@ impl InnerPostgresConnection {
let params = try!(params.into_connect_params()); let params = try!(params.into_connect_params());
let stream = try!(io::initialize_stream(&params, ssl)); let stream = try!(io::initialize_stream(&params, ssl));
let mut conn = InnerPostgresConnection {
stream: BufferedStream::new(stream),
next_stmt_id: 0,
notice_handler: box DefaultNoticeHandler,
notifications: RingBuf::new(),
cancel_data: PostgresCancelData { process_id: 0, secret_key: 0 },
unknown_types: HashMap::new(),
desynchronized: false,
finished: false,
trans_depth: 0,
canary: CANARY,
};
let PostgresConnectParams { let PostgresConnectParams {
user, user,
password, password,
@ -461,6 +446,19 @@ impl InnerPostgresConnection {
None => return Err(MissingUser), None => return Err(MissingUser),
}; };
let mut conn = InnerPostgresConnection {
stream: BufferedStream::new(stream),
next_stmt_id: 0,
notice_handler: box DefaultNoticeHandler,
notifications: RingBuf::new(),
cancel_data: PostgresCancelData { process_id: 0, secret_key: 0 },
unknown_types: HashMap::new(),
desynchronized: false,
finished: false,
trans_depth: 0,
canary: CANARY,
};
options.push(("client_encoding".to_owned(), "UTF8".to_owned())); options.push(("client_encoding".to_owned(), "UTF8".to_owned()));
// Postgres uses the value of TimeZone as the time zone for TIMESTAMP // Postgres uses the value of TimeZone as the time zone for TIMESTAMP
// WITH TIME ZONE values. Timespec converts to GMT internally. // WITH TIME ZONE values. Timespec converts to GMT internally.

View File

@ -79,13 +79,16 @@ impl PostgresConnectionPool {
pub fn get_connection(&self) -> PooledPostgresConnection { pub fn get_connection(&self) -> PooledPostgresConnection {
let mut pool = self.pool.lock(); let mut pool = self.pool.lock();
while pool.pool.is_empty() { loop {
pool.cond.wait(); match pool.pool.pop() {
} Some(conn) => {
return PooledPostgresConnection {
PooledPostgresConnection {
pool: self.clone(), pool: self.clone(),
conn: Some(pool.pool.pop().unwrap()) conn: Some(conn),
};
}
None => pool.cond.wait()
}
} }
} }
} }