Skip to content

Commit 1c1a939

Browse files
authored
Merge branch 'master' into master
2 parents 2c43519 + 983a71c commit 1c1a939

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+4227
-6316
lines changed

.circleci/config.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,20 @@ version: 2
2222
jobs:
2323
build:
2424
docker:
25-
- image: rust:1.35.0
25+
- image: rustlang/rust:nightly
2626
environment:
2727
RUSTFLAGS: -D warnings
2828
- image: sfackler/rust-postgres-test:5
2929
steps:
3030
- checkout
31-
- run: rustup component add rustfmt clippy
31+
# - run: rustup component add rustfmt clippy
3232
- *RESTORE_REGISTRY
3333
- run: cargo generate-lockfile
3434
- *SAVE_REGISTRY
3535
- run: rustc --version > ~/rust-version
3636
- *RESTORE_DEPS
37-
- run: cargo fmt --all -- --check
38-
- run: cargo clippy --all --all-targets --all-features
37+
# - run: cargo fmt --all -- --check
38+
# - run: cargo clippy --all --all-targets --all-features
3939
- run: cargo test --all
4040
- run: cargo test --manifest-path tokio-postgres/Cargo.toml --no-default-features
4141
- run: cargo test --manifest-path tokio-postgres/Cargo.toml --all-features

postgres-native-tls/Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ default = ["runtime"]
1616
runtime = ["tokio-postgres/runtime"]
1717

1818
[dependencies]
19-
futures = "0.1"
19+
futures-preview = "=0.3.0-alpha.18"
2020
native-tls = "0.2"
21-
tokio-io = "0.1"
22-
tokio-tls = "0.2.1"
21+
tokio-io = "=0.2.0-alpha.5"
22+
tokio-tls = "=0.3.0-alpha.5"
2323
tokio-postgres = { version = "0.4.0-rc.1", path = "../tokio-postgres", default-features = false }
2424

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

postgres-native-tls/src/lib.rs

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,13 @@
4848
#![doc(html_root_url = "https://docs.rs/postgres-native-tls/0.2.0-rc.1")]
4949
#![warn(rust_2018_idioms, clippy::all, missing_docs)]
5050

51-
use futures::{try_ready, Async, Future, Poll};
51+
use std::future::Future;
52+
use std::pin::Pin;
5253
use tokio_io::{AsyncRead, AsyncWrite};
5354
#[cfg(feature = "runtime")]
5455
use tokio_postgres::tls::MakeTlsConnect;
5556
use tokio_postgres::tls::{ChannelBinding, TlsConnect};
56-
use tokio_tls::{Connect, TlsStream};
57+
use tokio_tls::TlsStream;
5758

5859
#[cfg(test)]
5960
mod test;
@@ -76,7 +77,7 @@ impl MakeTlsConnector {
7677
#[cfg(feature = "runtime")]
7778
impl<S> MakeTlsConnect<S> for MakeTlsConnector
7879
where
79-
S: AsyncRead + AsyncWrite,
80+
S: AsyncRead + AsyncWrite + Unpin + 'static + Send,
8081
{
8182
type Stream = TlsStream<S>;
8283
type TlsConnect = TlsConnector;
@@ -105,35 +106,24 @@ impl TlsConnector {
105106

106107
impl<S> TlsConnect<S> for TlsConnector
107108
where
108-
S: AsyncRead + AsyncWrite,
109+
S: AsyncRead + AsyncWrite + Unpin + 'static + Send,
109110
{
110111
type Stream = TlsStream<S>;
111112
type Error = native_tls::Error;
112-
type Future = TlsConnectFuture<S>;
113+
type Future = Pin<
114+
Box<dyn Future<Output = Result<(TlsStream<S>, ChannelBinding), native_tls::Error>> + Send>,
115+
>;
113116

114-
fn connect(self, stream: S) -> TlsConnectFuture<S> {
115-
TlsConnectFuture(self.connector.connect(&self.domain, stream))
116-
}
117-
}
118-
119-
/// The future returned by `TlsConnector`.
120-
pub struct TlsConnectFuture<S>(Connect<S>);
121-
122-
impl<S> Future for TlsConnectFuture<S>
123-
where
124-
S: AsyncRead + AsyncWrite,
125-
{
126-
type Item = (TlsStream<S>, ChannelBinding);
127-
type Error = native_tls::Error;
117+
fn connect(self, stream: S) -> Self::Future {
118+
let future = async move {
119+
let stream = self.connector.connect(&self.domain, stream).await?;
128120

129-
fn poll(&mut self) -> Poll<(TlsStream<S>, ChannelBinding), native_tls::Error> {
130-
let stream = try_ready!(self.0.poll());
121+
// FIXME https://github.com/tokio-rs/tokio/issues/1383
122+
let channel_binding = ChannelBinding::none();
131123

132-
let channel_binding = match stream.get_ref().tls_server_end_point().unwrap_or(None) {
133-
Some(buf) => ChannelBinding::tls_server_end_point(buf),
134-
None => ChannelBinding::none(),
124+
Ok((stream, channel_binding))
135125
};
136126

137-
Ok(Async::Ready((stream, channel_binding)))
127+
Box::pin(future)
138128
}
139129
}

postgres-native-tls/src/test.rs

Lines changed: 44 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,38 @@
1-
use futures::{Future, Stream};
1+
use futures::{FutureExt, TryStreamExt};
22
use native_tls::{self, Certificate};
33
use tokio::net::TcpStream;
4-
use tokio::runtime::current_thread::Runtime;
54
use tokio_postgres::tls::TlsConnect;
65

76
#[cfg(feature = "runtime")]
87
use crate::MakeTlsConnector;
98
use crate::TlsConnector;
109

11-
fn smoke_test<T>(s: &str, tls: T)
10+
async fn smoke_test<T>(s: &str, tls: T)
1211
where
1312
T: TlsConnect<TcpStream>,
14-
T::Stream: 'static,
13+
T::Stream: 'static + Send,
1514
{
16-
let mut runtime = Runtime::new().unwrap();
15+
let stream = TcpStream::connect("127.0.0.1:5433").await.unwrap();
1716

1817
let builder = s.parse::<tokio_postgres::Config>().unwrap();
18+
let (mut client, connection) = builder.connect_raw(stream, tls).await.unwrap();
1919

20-
let handshake = TcpStream::connect(&"127.0.0.1:5433".parse().unwrap())
21-
.map_err(|e| panic!("{}", e))
22-
.and_then(|s| builder.connect_raw(s, tls));
23-
let (mut client, connection) = runtime.block_on(handshake).unwrap();
24-
let connection = connection.map_err(|e| panic!("{}", e));
25-
runtime.spawn(connection);
20+
let connection = connection.map(|r| r.unwrap());
21+
tokio::spawn(connection);
2622

27-
let prepare = client.prepare("SELECT 1::INT4");
28-
let statement = runtime.block_on(prepare).unwrap();
29-
let select = client.query(&statement, &[]).collect().map(|rows| {
30-
assert_eq!(rows.len(), 1);
31-
assert_eq!(rows[0].get::<_, i32>(0), 1);
32-
});
33-
runtime.block_on(select).unwrap();
23+
let stmt = client.prepare("SELECT $1::INT4").await.unwrap();
24+
let rows = client
25+
.query(&stmt, &[&1i32])
26+
.try_collect::<Vec<_>>()
27+
.await
28+
.unwrap();
3429

35-
drop(statement);
36-
drop(client);
37-
runtime.run().unwrap();
30+
assert_eq!(rows.len(), 1);
31+
assert_eq!(rows[0].get::<_, i32>(0), 1);
3832
}
3933

40-
#[test]
41-
fn require() {
34+
#[tokio::test]
35+
async fn require() {
4236
let connector = native_tls::TlsConnector::builder()
4337
.add_root_certificate(
4438
Certificate::from_pem(include_bytes!("../../test/server.crt")).unwrap(),
@@ -48,11 +42,12 @@ fn require() {
4842
smoke_test(
4943
"user=ssl_user dbname=postgres sslmode=require",
5044
TlsConnector::new(connector, "localhost"),
51-
);
45+
)
46+
.await;
5247
}
5348

54-
#[test]
55-
fn prefer() {
49+
#[tokio::test]
50+
async fn prefer() {
5651
let connector = native_tls::TlsConnector::builder()
5752
.add_root_certificate(
5853
Certificate::from_pem(include_bytes!("../../test/server.crt")).unwrap(),
@@ -62,11 +57,12 @@ fn prefer() {
6257
smoke_test(
6358
"user=ssl_user dbname=postgres",
6459
TlsConnector::new(connector, "localhost"),
65-
);
60+
)
61+
.await;
6662
}
6763

68-
#[test]
69-
fn scram_user() {
64+
#[tokio::test]
65+
async fn scram_user() {
7066
let connector = native_tls::TlsConnector::builder()
7167
.add_root_certificate(
7268
Certificate::from_pem(include_bytes!("../../test/server.crt")).unwrap(),
@@ -76,14 +72,13 @@ fn scram_user() {
7672
smoke_test(
7773
"user=scram_user password=password dbname=postgres sslmode=require",
7874
TlsConnector::new(connector, "localhost"),
79-
);
75+
)
76+
.await;
8077
}
8178

82-
#[test]
79+
#[tokio::test]
8380
#[cfg(feature = "runtime")]
84-
fn runtime() {
85-
let mut runtime = Runtime::new().unwrap();
86-
81+
async fn runtime() {
8782
let connector = native_tls::TlsConnector::builder()
8883
.add_root_certificate(
8984
Certificate::from_pem(include_bytes!("../../test/server.crt")).unwrap(),
@@ -92,14 +87,22 @@ fn runtime() {
9287
.unwrap();
9388
let connector = MakeTlsConnector::new(connector);
9489

95-
let connect = tokio_postgres::connect(
90+
let (mut client, connection) = tokio_postgres::connect(
9691
"host=localhost port=5433 user=postgres sslmode=require",
9792
connector,
98-
);
99-
let (mut client, connection) = runtime.block_on(connect).unwrap();
100-
let connection = connection.map_err(|e| panic!("{}", e));
101-
runtime.spawn(connection);
93+
)
94+
.await
95+
.unwrap();
96+
let connection = connection.map(|r| r.unwrap());
97+
tokio::spawn(connection);
98+
99+
let stmt = client.prepare("SELECT $1::INT4").await.unwrap();
100+
let rows = client
101+
.query(&stmt, &[&1i32])
102+
.try_collect::<Vec<_>>()
103+
.await
104+
.unwrap();
102105

103-
let execute = client.simple_query("SELECT 1").for_each(|_| Ok(()));
104-
runtime.block_on(execute).unwrap();
106+
assert_eq!(rows.len(), 1);
107+
assert_eq!(rows[0].get::<_, i32>(0), 1);
105108
}

postgres-openssl/Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ default = ["runtime"]
1616
runtime = ["tokio-postgres/runtime"]
1717

1818
[dependencies]
19-
futures = "0.1"
19+
futures-preview = "=0.3.0-alpha.18"
2020
openssl = "0.10"
21-
tokio-io = "0.1"
22-
tokio-openssl = "0.3"
21+
tokio-io = "=0.2.0-alpha.5"
22+
tokio-openssl = "=0.4.0-alpha.5"
2323
tokio-postgres = { version = "0.4.0-rc.1", path = "../tokio-postgres", default-features = false }
2424

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

postgres-openssl/src/lib.rs

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,20 @@
4242
#![doc(html_root_url = "https://docs.rs/postgres-openssl/0.2.0-rc.1")]
4343
#![warn(rust_2018_idioms, clippy::all, missing_docs)]
4444

45-
use futures::{try_ready, Async, Future, Poll};
4645
#[cfg(feature = "runtime")]
4746
use openssl::error::ErrorStack;
4847
use openssl::hash::MessageDigest;
4948
use openssl::nid::Nid;
5049
#[cfg(feature = "runtime")]
5150
use openssl::ssl::SslConnector;
52-
use openssl::ssl::{ConnectConfiguration, HandshakeError, SslRef};
51+
use openssl::ssl::{ConnectConfiguration, SslRef};
5352
use std::fmt::Debug;
53+
use std::future::Future;
54+
use std::pin::Pin;
5455
#[cfg(feature = "runtime")]
5556
use std::sync::Arc;
5657
use tokio_io::{AsyncRead, AsyncWrite};
57-
use tokio_openssl::{ConnectAsync, ConnectConfigurationExt, SslStream};
58+
use tokio_openssl::{HandshakeError, SslStream};
5859
#[cfg(feature = "runtime")]
5960
use tokio_postgres::tls::MakeTlsConnect;
6061
use tokio_postgres::tls::{ChannelBinding, TlsConnect};
@@ -96,7 +97,7 @@ impl MakeTlsConnector {
9697
#[cfg(feature = "runtime")]
9798
impl<S> MakeTlsConnect<S> for MakeTlsConnector
9899
where
99-
S: AsyncRead + AsyncWrite + Debug + 'static + Sync + Send,
100+
S: AsyncRead + AsyncWrite + Unpin + Debug + 'static + Sync + Send,
100101
{
101102
type Stream = SslStream<S>;
102103
type TlsConnect = TlsConnector;
@@ -127,36 +128,27 @@ impl TlsConnector {
127128

128129
impl<S> TlsConnect<S> for TlsConnector
129130
where
130-
S: AsyncRead + AsyncWrite + Debug + 'static + Sync + Send,
131+
S: AsyncRead + AsyncWrite + Unpin + Debug + 'static + Sync + Send,
131132
{
132133
type Stream = SslStream<S>;
133134
type Error = HandshakeError<S>;
134-
type Future = TlsConnectFuture<S>;
135+
type Future = Pin<
136+
Box<dyn Future<Output = Result<(SslStream<S>, ChannelBinding), HandshakeError<S>>> + Send>,
137+
>;
135138

136-
fn connect(self, stream: S) -> TlsConnectFuture<S> {
137-
TlsConnectFuture(self.ssl.connect_async(&self.domain, stream))
138-
}
139-
}
140-
141-
/// The future returned by `TlsConnector`.
142-
pub struct TlsConnectFuture<S>(ConnectAsync<S>);
143-
144-
impl<S> Future for TlsConnectFuture<S>
145-
where
146-
S: AsyncRead + AsyncWrite + Debug + 'static + Sync + Send,
147-
{
148-
type Item = (SslStream<S>, ChannelBinding);
149-
type Error = HandshakeError<S>;
139+
fn connect(self, stream: S) -> Self::Future {
140+
let future = async move {
141+
let stream = tokio_openssl::connect(self.ssl, &self.domain, stream).await?;
150142

151-
fn poll(&mut self) -> Poll<(SslStream<S>, ChannelBinding), HandshakeError<S>> {
152-
let stream = try_ready!(self.0.poll());
143+
let channel_binding = match tls_server_end_point(stream.ssl()) {
144+
Some(buf) => ChannelBinding::tls_server_end_point(buf),
145+
None => ChannelBinding::none(),
146+
};
153147

154-
let channel_binding = match tls_server_end_point(stream.get_ref().ssl()) {
155-
Some(buf) => ChannelBinding::tls_server_end_point(buf),
156-
None => ChannelBinding::none(),
148+
Ok((stream, channel_binding))
157149
};
158150

159-
Ok(Async::Ready((stream, channel_binding)))
151+
Box::pin(future)
160152
}
161153
}
162154

0 commit comments

Comments
 (0)