Skip to content

Commit 7f318f2

Browse files
committed
Update for upstream changes
1 parent d1c412b commit 7f318f2

3 files changed

Lines changed: 4 additions & 34 deletions

File tree

src/error.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ macro_rules! make_errors(
1717
#[allow(missing_doc)]
1818
pub enum PostgresSqlState {
1919
$($error,)+
20-
UnknownSqlState(~str)
20+
UnknownSqlState(StrBuf)
2121
}
2222

2323
static STATE_MAP: PhfMap<PostgresSqlState> = phf_map!(
@@ -29,7 +29,7 @@ macro_rules! make_errors(
2929
pub fn from_code(s: &str) -> PostgresSqlState {
3030
match STATE_MAP.find(&s) {
3131
Some(state) => state.clone(),
32-
None => UnknownSqlState(s.to_owned())
32+
None => UnknownSqlState(s.to_strbuf())
3333
}
3434
}
3535
}
@@ -362,8 +362,6 @@ pub enum PostgresConnectError {
362362
InvalidUrl(~str),
363363
/// The URL was missing a user
364364
MissingUser,
365-
/// DNS lookup failed
366-
DnsError(IoError),
367365
/// There was an error opening a socket to the server
368366
SocketError(IoError),
369367
/// An error from the Postgres server itself
@@ -386,7 +384,6 @@ impl fmt::Show for PostgresConnectError {
386384
match *self {
387385
InvalidUrl(ref err) => write!(fmt.buf, "Invalid URL: {}", err),
388386
MissingUser => fmt.buf.write_str("User missing in URL"),
389-
DnsError(ref err) => write!(fmt.buf, "DNS lookup failed: {}", err),
390387
SocketError(ref err) =>
391388
write!(fmt.buf, "Unable to open connection to server: {}", err),
392389
PgConnectDbError(ref err) => err.fmt(fmt),

src/io.rs

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use openssl::ssl::SslStream;
2-
use std::io::net;
3-
use std::io::net::ip::{Port, SocketAddr};
2+
use std::io::net::ip::Port;
43
use std::io::net::tcp::TcpStream;
54
use std::io::net::unix::UnixStream;
65
use std::io::{Stream, IoResult};
@@ -14,7 +13,6 @@ use {PostgresConnectParams,
1413
TargetUnix};
1514
use error::{PostgresConnectError,
1615
PgConnectStreamError,
17-
DnsError,
1816
NoSslSupport,
1917
SslError,
2018
SocketError};
@@ -25,20 +23,7 @@ static DEFAULT_PORT: Port = 5432;
2523

2624
fn open_tcp_socket(host: &str, port: Port) -> Result<TcpStream,
2725
PostgresConnectError> {
28-
let addrs = match net::get_host_addresses(host) {
29-
Ok(addrs) => addrs,
30-
Err(err) => return Err(DnsError(err))
31-
};
32-
33-
let mut err = None;
34-
for &addr in addrs.iter() {
35-
match TcpStream::connect(SocketAddr { ip: addr, port: port }) {
36-
Ok(socket) => return Ok(socket),
37-
Err(e) => err = Some(e)
38-
}
39-
}
40-
41-
Err(SocketError(err.unwrap()))
26+
TcpStream::connect(host, port).map_err(|e| SocketError(e))
4227
}
4328

4429
fn open_unix_socket(path: &Path, port: Port) -> Result<UnixStream,
@@ -150,4 +135,3 @@ pub fn initialize_stream(params: &PostgresConnectParams, ssl: &SslMode)
150135
Err(err) => Err(SslError(err))
151136
}
152137
}
153-

src/test.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ use error::{PgConnectDbError,
2525
PgWrongType,
2626
PgInvalidColumn,
2727
PgWasNull,
28-
DnsError,
2928
MissingPassword,
3029
Position,
3130
PostgresDbError,
@@ -972,16 +971,6 @@ fn test_md5_pass_wrong_pass() {
972971
}
973972
}
974973

975-
#[test]
976-
fn test_dns_failure() {
977-
let ret = PostgresConnection::connect("postgres://postgres@asdfasdfasdf", &NoSsl);
978-
match ret {
979-
Err(DnsError(_)) => (),
980-
Err(err) => fail!("Unexpected error {}", err),
981-
_ => fail!("Expected error")
982-
}
983-
}
984-
985974
#[test]
986975
fn test_jsonarray_params() {
987976
test_array_params!("JSON",

0 commit comments

Comments
 (0)