Skip to content

Commit 2a2b76d

Browse files
committed
Upgrade to tokio alpha.4
1 parent c026644 commit 2a2b76d

File tree

9 files changed

+29
-83
lines changed

9 files changed

+29
-83
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
members = [
33
"codegen",
44
"postgres",
5-
"postgres-native-tls",
5+
# "postgres-native-tls",
66
"postgres-openssl",
77
"postgres-protocol",
88
"tokio-postgres",

postgres-native-tls/Cargo.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ runtime = ["tokio-postgres/runtime"]
1818
[dependencies]
1919
futures-preview = "=0.3.0-alpha.18"
2020
native-tls = "0.2"
21-
tokio-io = "=0.2.0-alpha.2"
22-
tokio-tls = "=0.3.0-alpha.2"
21+
tokio-io = "=0.2.0-alpha.4"
22+
tokio-tls = "=0.3.0-alpha.4"
2323
tokio-postgres = { version = "0.4.0-rc.1", path = "../tokio-postgres", default-features = false }
2424

2525
[dev-dependencies]
26-
tokio = "=0.2.0-alpha.2"
26+
tokio = "=0.2.0-alpha.4"
2727
postgres = { version = "0.16.0-rc.1", path = "../postgres" }

postgres-openssl/Cargo.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ runtime = ["tokio-postgres/runtime"]
1818
[dependencies]
1919
futures-preview = "=0.3.0-alpha.18"
2020
openssl = "0.10"
21-
tokio-io = "=0.2.0-alpha.2"
22-
tokio-openssl = "=0.4.0-alpha.2"
21+
tokio-io = "=0.2.0-alpha.4"
22+
tokio-openssl = "=0.4.0-alpha.4"
2323
tokio-postgres = { version = "0.4.0-rc.1", path = "../tokio-postgres", default-features = false }
2424

2525
[dev-dependencies]
26-
tokio = "=0.2.0-alpha.2"
26+
tokio = "=0.2.0-alpha.4"
2727
postgres = { version = "0.16.0-rc.1", path = "../postgres" }

postgres-openssl/src/test.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ where
1010
T: TlsConnect<TcpStream>,
1111
T::Stream: 'static + Send,
1212
{
13-
let stream = TcpStream::connect(&"127.0.0.1:5433".parse().unwrap())
14-
.await
15-
.unwrap();
13+
let stream = TcpStream::connect("127.0.0.1:5433").await.unwrap();
1614

1715
let builder = s.parse::<tokio_postgres::Config>().unwrap();
1816
let (mut client, connection) = builder.connect_raw(stream, tls).await.unwrap();

postgres/Cargo.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ fallible-iterator = "0.2"
3333
futures-preview = "=0.3.0-alpha.18"
3434
pin-utils = "=0.1.0-alpha.4"
3535
tokio-postgres = { version = "0.4.0-rc.2", path = "../tokio-postgres", default-features = false }
36-
tokio-executor = "=0.2.0-alpha.2"
36+
tokio-executor = "=0.2.0-alpha.4"
3737

38-
tokio = { version = "=0.2.0-alpha.2", optional = true }
38+
tokio = { version = "=0.2.0-alpha.4", optional = true }
3939
lazy_static = { version = "1.0", optional = true }
4040
log = { version = "0.4", optional = true }
4141

4242
[dev-dependencies]
43-
tokio = "=0.2.0-alpha.2"
43+
tokio = "=0.2.0-alpha.4"

tokio-postgres/Cargo.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ percent-encoding = "1.0"
4040
pin-utils = "=0.1.0-alpha.4"
4141
phf = "0.7.23"
4242
postgres-protocol = { version = "0.4.1", path = "../postgres-protocol" }
43-
tokio = { version = "=0.2.0-alpha.2", default-features = false, features = ["io", "codec"] }
43+
tokio = { version = "=0.2.0-alpha.4", default-features = false, features = ["io", "codec"] }
4444

45-
tokio-executor = { version = "=0.2.0-alpha.2", optional = true }
45+
tokio-executor = { version = "=0.2.0-alpha.4", optional = true }
4646
lazy_static = { version = "1.0", optional = true }
4747

4848
bit-vec-05 = { version = "0.5", package = "bit-vec", optional = true }
@@ -54,5 +54,5 @@ serde_json-1 = { version = "1.0", package = "serde_json", optional = true }
5454
uuid-07 = { version = "0.7", package = "uuid", optional = true }
5555

5656
[dev-dependencies]
57-
tokio = "=0.2.0-alpha.2"
57+
tokio = "=0.2.0-alpha.4"
5858
env_logger = "0.5"

tokio-postgres/src/connect_socket.rs

+9-57
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
use crate::config::Host;
22
use crate::{Error, Socket};
3-
use futures::channel::oneshot;
4-
use futures::future;
53
use std::future::Future;
6-
use std::net::{IpAddr, SocketAddr, ToSocketAddrs};
4+
use std::io;
75
use std::time::Duration;
8-
use std::vec;
9-
use std::{io, thread};
106
use tokio::net::TcpStream;
117
#[cfg(unix)]
128
use tokio::net::UnixStream;
139
use tokio::timer::Timeout;
14-
use tokio_executor::threadpool;
1510

1611
pub(crate) async fn connect_socket(
1712
host: &Host,
@@ -22,40 +17,16 @@ pub(crate) async fn connect_socket(
2217
) -> Result<Socket, Error> {
2318
match host {
2419
Host::Tcp(host) => {
25-
let addrs = match host.parse::<IpAddr>() {
26-
Ok(ip) => {
27-
// avoid dealing with blocking DNS entirely if possible
28-
vec![SocketAddr::new(ip, port)].into_iter()
29-
}
30-
Err(_) => dns(host, port).await.map_err(Error::connect)?,
31-
};
32-
33-
let mut error = None;
34-
for addr in addrs {
35-
let new_error =
36-
match connect_with_timeout(TcpStream::connect(&addr), connect_timeout).await {
37-
Ok(socket) => {
38-
socket.set_nodelay(true).map_err(Error::connect)?;
39-
if keepalives {
40-
socket
41-
.set_keepalive(Some(keepalives_idle))
42-
.map_err(Error::connect)?;
43-
}
44-
45-
return Ok(Socket::new_tcp(socket));
46-
}
47-
Err(e) => e,
48-
};
49-
error = Some(new_error);
20+
let socket =
21+
connect_with_timeout(TcpStream::connect((&**host, port)), connect_timeout).await?;
22+
socket.set_nodelay(true).map_err(Error::connect)?;
23+
if keepalives {
24+
socket
25+
.set_keepalive(Some(keepalives_idle))
26+
.map_err(Error::connect)?;
5027
}
5128

52-
let error = error.unwrap_or_else(|| {
53-
Error::connect(io::Error::new(
54-
io::ErrorKind::InvalidData,
55-
"resolved 0 addresses",
56-
))
57-
});
58-
Err(error)
29+
Ok(Socket::new_tcp(socket))
5930
}
6031
#[cfg(unix)]
6132
Host::Unix(path) => {
@@ -65,25 +36,6 @@ pub(crate) async fn connect_socket(
6536
}
6637
}
6738

68-
async fn dns(host: &str, port: u16) -> io::Result<vec::IntoIter<SocketAddr>> {
69-
// if we're running on a threadpool, use its blocking support
70-
if let Ok(r) =
71-
future::poll_fn(|_| threadpool::blocking(|| (host, port).to_socket_addrs())).await
72-
{
73-
return r;
74-
}
75-
76-
// FIXME what should we do here?
77-
let (tx, rx) = oneshot::channel();
78-
let host = host.to_string();
79-
thread::spawn(move || {
80-
let addrs = (&*host, port).to_socket_addrs();
81-
let _ = tx.send(addrs);
82-
});
83-
84-
rx.await.unwrap()
85-
}
86-
8739
async fn connect_with_timeout<F, T>(connect: F, timeout: Option<Duration>) -> Result<T, Error>
8840
where
8941
F: Future<Output = io::Result<T>>,

tokio-postgres/tests/test/main.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use futures::{join, try_join, FutureExt, TryStreamExt};
66
use std::fmt::Write;
77
use std::time::{Duration, Instant};
88
use tokio::net::TcpStream;
9-
use tokio::timer::Delay;
9+
use tokio::timer;
1010
use tokio_postgres::error::SqlState;
1111
use tokio_postgres::tls::{NoTls, NoTlsStream};
1212
use tokio_postgres::types::{Kind, Type};
@@ -18,9 +18,7 @@ mod runtime;
1818
mod types;
1919

2020
async fn connect_raw(s: &str) -> Result<(Client, Connection<TcpStream, NoTlsStream>), Error> {
21-
let socket = TcpStream::connect(&"127.0.0.1:5433".parse().unwrap())
22-
.await
23-
.unwrap();
21+
let socket = TcpStream::connect("127.0.0.1:5433").await.unwrap();
2422
let config = s.parse::<Config>().unwrap();
2523
config.connect_raw(socket, NoTls).await
2624
}
@@ -303,11 +301,9 @@ async fn simple_query() {
303301
async fn cancel_query_raw() {
304302
let mut client = connect("user=postgres").await;
305303

306-
let socket = TcpStream::connect(&"127.0.0.1:5433".parse().unwrap())
307-
.await
308-
.unwrap();
304+
let socket = TcpStream::connect("127.0.0.1:5433").await.unwrap();
309305
let cancel = client.cancel_query_raw(socket, NoTls);
310-
let cancel = Delay::new(Instant::now() + Duration::from_millis(100)).then(|()| cancel);
306+
let cancel = timer::delay(Instant::now() + Duration::from_millis(100)).then(|()| cancel);
311307

312308
let sleep = client.batch_execute("SELECT pg_sleep(100)");
313309

tokio-postgres/tests/test/runtime.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use futures::{join, FutureExt, TryStreamExt};
22
use std::time::{Duration, Instant};
3-
use tokio::timer::Delay;
3+
use tokio::timer;
44
use tokio_postgres::error::SqlState;
55
use tokio_postgres::{Client, NoTls};
66

@@ -75,7 +75,7 @@ async fn cancel_query() {
7575
let mut client = connect("host=localhost port=5433 user=postgres").await;
7676

7777
let cancel = client.cancel_query(NoTls);
78-
let cancel = Delay::new(Instant::now() + Duration::from_millis(100)).then(|()| cancel);
78+
let cancel = timer::delay(Instant::now() + Duration::from_millis(100)).then(|()| cancel);
7979

8080
let sleep = client.batch_execute("SELECT pg_sleep(100)");
8181

0 commit comments

Comments
 (0)