Skip to content

Commit 6908038

Browse files
authored
context changes (#5)
1 parent a58d250 commit 6908038

File tree

6 files changed

+28
-21
lines changed

6 files changed

+28
-21
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
language: rust
33
rust:
4-
- nightly-2019-04-07
4+
- nightly
55
sudo: false
66
cache:
77
- apt

Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ edition = "2018"
77
# - Update CHANGELOG.md.
88
# - Update doc URL.
99
# - Create "v0.1.x" git tag.
10-
version = "0.3.0-alpha.3"
10+
version = "0.3.0-alpha.4"
1111
license = "MIT"
1212
readme = "README.md"
1313
description = """
1414
TLS support for AsyncRead/AsyncWrite using native-tls
1515
"""
1616
authors = ["Danny Browning <[email protected]>", "Carl Lerche <[email protected]>"]
1717
categories = ["asynchronous", "network-programming"]
18-
documentation = "https://docs.rs/tls-async/0.3.0-alpha.3/tls_async/"
18+
documentation = "https://docs.rs/tls-async/0.3.0-alpha.4/tls_async/"
1919
repository = "https://github.com/dbcfd/tls-async"
2020

2121
[dependencies]
@@ -25,13 +25,13 @@ log = "0.4.1"
2525
native-tls = "0.2"
2626

2727
[dependencies.futures]
28-
version = "0.3.0-alpha.13"
28+
version = "0.3.0-alpha.14"
2929
package = "futures-preview"
3030
features = ["compat", "io-compat", "std"]
3131

3232
[dev-dependencies]
3333
cfg-if = "0.1"
34-
romio = "0.3.0-alpha.3"
34+
romio = "0.3.0-alpha.5"
3535
tokio = "0.1"
3636

3737
[dev-dependencies.env_logger]

src/acceptor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ impl TlsAcceptor {
118118
/// `TcpListener`. That socket is then passed to this function to perform
119119
/// the server half of accepting a client connection.
120120
pub fn accept<S>(&self, stream: S) -> PendingTlsStream<S>
121-
where S: AsyncRead + AsyncWrite,
121+
where S: AsyncRead + AsyncWrite + Unpin,
122122
{
123123
PendingTlsStream::new(self.inner.accept(stream.compat()))
124124
}

src/connector.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ impl TlsConnector {
156156
/// provided here to perform the client half of a connection to a
157157
/// TLS-powered server.
158158
pub fn connect<'a, S>(&'a self, domain: &'a str, stream: S) -> PendingTlsStream<S>
159-
where S: AsyncRead + AsyncWrite,
159+
where S: AsyncRead + AsyncWrite + Unpin,
160160
{
161161
PendingTlsStream::new(self.inner.connect(domain, stream.compat()))
162162
}

src/lib.rs

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ pub use connector::TlsConnector as TlsConnector;
2525
pub use errors::Error as Error;
2626

2727
use std::io::{self, Read, Write};
28-
use std::task::Waker;
28+
use std::pin::Pin;
29+
use std::task::Context;
2930

3031
use futures::compat::Compat;
3132
use futures::io::{AsyncRead, AsyncWrite};
@@ -56,12 +57,18 @@ impl<S> TlsStream<S> {
5657
pub fn get_mut(&mut self) -> &mut native_tls::TlsStream<Compat<S>> {
5758
&mut self.inner
5859
}
60+
61+
fn inner<'a>(self: Pin<&'a mut Self>) -> &'a mut native_tls::TlsStream<Compat<S>> {
62+
unsafe {
63+
&mut Pin::get_unchecked_mut(self).inner
64+
}
65+
}
5966
}
6067

61-
impl<S: AsyncRead + AsyncWrite> AsyncRead for TlsStream<S> {
62-
fn poll_read(&mut self, _lw: &Waker, buf: &mut [u8])
68+
impl<S: AsyncRead + AsyncWrite + Unpin> AsyncRead for TlsStream<S> {
69+
fn poll_read(mut self: Pin<&mut Self>, _cx: &mut Context<'_>, buf: &mut [u8])
6370
-> Poll<Result<usize, io::Error>> {
64-
match self.inner.read(buf) {
71+
match self.as_mut().inner().read(buf) {
6572
Ok(sz) => Poll::Ready(Ok(sz)),
6673
Err(ref e) if e.kind() == io::ErrorKind::WouldBlock => {
6774
Poll::Pending
@@ -71,10 +78,10 @@ impl<S: AsyncRead + AsyncWrite> AsyncRead for TlsStream<S> {
7178
}
7279
}
7380

74-
impl<S: AsyncRead + AsyncWrite> AsyncWrite for TlsStream<S> {
75-
fn poll_write(&mut self, _lw: &Waker, buf: &[u8])
81+
impl<S: AsyncRead + AsyncWrite + Unpin> AsyncWrite for TlsStream<S> {
82+
fn poll_write(mut self: Pin<&mut Self>, _cx: &mut Context<'_>, buf: &[u8])
7683
-> Poll<Result<usize, io::Error>> {
77-
match self.inner.write(buf) {
84+
match self.as_mut().inner().write(buf) {
7885
Ok(sz) => Poll::Ready(Ok(sz)),
7986
Err(ref e) if e.kind() == io::ErrorKind::WouldBlock => {
8087
Poll::Pending
@@ -83,8 +90,8 @@ impl<S: AsyncRead + AsyncWrite> AsyncWrite for TlsStream<S> {
8390
}
8491
}
8592

86-
fn poll_flush(&mut self, _lw: &Waker) -> Poll<Result<(), io::Error>> {
87-
match self.inner.flush() {
93+
fn poll_flush(mut self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Result<(), io::Error>> {
94+
match self.as_mut().inner().flush() {
8895
Ok(sz) => Poll::Ready(Ok(sz)),
8996
Err(ref e) if e.kind() == io::ErrorKind::WouldBlock => {
9097
Poll::Pending
@@ -93,8 +100,8 @@ impl<S: AsyncRead + AsyncWrite> AsyncWrite for TlsStream<S> {
93100
}
94101
}
95102

96-
fn poll_close(&mut self, _lw: &Waker) -> Poll<Result<(), io::Error>> {
97-
match self.inner.shutdown() {
103+
fn poll_close(mut self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Result<(), io::Error>> {
104+
match self.as_mut().inner().shutdown() {
98105
Ok(sz) => Poll::Ready(Ok(sz)),
99106
Err(ref e) if e.kind() == io::ErrorKind::WouldBlock => {
100107
Poll::Pending

src/pending.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::errors::Error;
22
use crate::TlsStream;
33

44
use std::pin::Pin;
5-
use std::task::Waker;
5+
use std::task::Context;
66

77
use futures::Future;
88
use futures::compat::Compat;
@@ -57,10 +57,10 @@ impl<S> PendingTlsStream<S> {
5757
}
5858
}
5959

60-
impl<S: AsyncRead + AsyncWrite + std::fmt::Debug> Future for PendingTlsStream<S> {
60+
impl<S: AsyncRead + AsyncWrite + std::fmt::Debug + Unpin> Future for PendingTlsStream<S> {
6161
type Output = Result<TlsStream<S>, Error>;
6262

63-
fn poll(mut self: Pin<&mut Self>, _lw: &Waker) -> Poll<Self::Output> {
63+
fn poll(mut self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Self::Output> {
6464
loop {
6565
let handshake = std::mem::replace(self.as_mut().inner(), Handshake::Error(Error::RepeatedHandshake));
6666
match handshake {

0 commit comments

Comments
 (0)