fix futures_impl flush/close and README

This commit is contained in:
quininer 2018-03-24 00:46:21 +08:00
parent fddb77759f
commit 062c10e31e
3 changed files with 17 additions and 12 deletions

View File

@ -31,25 +31,28 @@ TcpStream::connect(&addr)
### Client Example Program ### Client Example Program
See [examples/client.rs](examples/client.rs). You can run it with: See [examples/client](examples/client/src/main.rs). You can run it with:
```sh ```sh
cargo run --example client hsts.badssl.com cd examples/client
cargo run -- hsts.badssl.com
``` ```
Currently on Windows the example client reads from stdin and writes to stdout using Currently on Windows the example client reads from stdin and writes to stdout using
blocking I/O. Until this is fixed, do something this on Windows: blocking I/O. Until this is fixed, do something this on Windows:
```sh ```sh
echo | cargo run --example client hsts.badssl.com cd examples/client
echo | cargo run -- hsts.badssl.com
``` ```
### Server Example Program ### Server Example Program
See [examples/server.rs](examples/server.rs). You can run it with: See [examples/server](examples/server/src/main.rs). You can run it with:
```sh ```sh
cargo run --example server -- 127.0.0.1 --cert mycert.der --key mykey.der cd examples/server
cargo run -- 127.0.0.1 --cert mycert.der --key mykey.der
``` ```
### License & Origin ### License & Origin

View File

@ -52,20 +52,18 @@ fn main() {
let done = socket.incoming() let done = socket.incoming()
.for_each(move |stream| if flag_echo { .for_each(move |stream| if flag_echo {
let addr = stream.peer_addr().ok(); let addr = stream.peer_addr().ok();
let addr2 = addr.clone();
let done = arc_config.accept_async(stream) let done = arc_config.accept_async(stream)
.and_then(|stream| { .and_then(|stream| {
let (reader, writer) = stream.split(); let (reader, writer) = stream.split();
io::copy(reader, writer) io::copy(reader, writer)
}) })
.map(move |(n, ..)| println!("Echo: {} - {:?}", n, addr)) .map(move |(n, ..)| println!("Echo: {} - {:?}", n, addr))
.map_err(move |err| println!("Error: {:?} - {:?}", err, addr2)); .map_err(move |err| println!("Error: {:?} - {:?}", err, addr));
tokio::spawn(done); tokio::spawn(done);
Ok(()) Ok(())
} else { } else {
let addr = stream.peer_addr().ok(); let addr = stream.peer_addr().ok();
let addr2 = addr.clone();
let done = arc_config.accept_async(stream) let done = arc_config.accept_async(stream)
.and_then(|stream| io::write_all( .and_then(|stream| io::write_all(
stream, stream,
@ -77,7 +75,7 @@ fn main() {
)) ))
.and_then(|(stream, _)| io::flush(stream)) .and_then(|(stream, _)| io::flush(stream))
.map(move |_| println!("Accept: {:?}", addr)) .map(move |_| println!("Accept: {:?}", addr))
.map_err(move |err| println!("Error: {:?} - {:?}", err, addr2)); .map_err(move |err| println!("Error: {:?} - {:?}", err, addr));
tokio::spawn(done); tokio::spawn(done);
Ok(()) Ok(())

View File

@ -143,9 +143,13 @@ impl<S, C> AsyncWrite for TlsStream<S, C>
fn poll_flush(&mut self, ctx: &mut Context) -> Poll<(), Error> { fn poll_flush(&mut self, ctx: &mut Context) -> Poll<(), Error> {
let (io, session) = self.get_mut(); let (io, session) = self.get_mut();
let mut taskio = TaskStream { io, task: ctx }; let mut taskio = TaskStream { io, task: ctx };
let mut stream = Stream::new(session, &mut taskio);
async!(from io::Write::flush(&mut stream)) {
let mut stream = Stream::new(session, &mut taskio);
async!(from io::Write::flush(&mut stream))?;
}
async!(from io::Write::flush(&mut taskio))
} }
fn poll_close(&mut self, ctx: &mut Context) -> Poll<(), Error> { fn poll_close(&mut self, ctx: &mut Context) -> Poll<(), Error> {
@ -157,7 +161,7 @@ impl<S, C> AsyncWrite for TlsStream<S, C>
{ {
let (io, session) = self.get_mut(); let (io, session) = self.get_mut();
let mut taskio = TaskStream { io, task: ctx }; let mut taskio = TaskStream { io, task: ctx };
session.complete_io(&mut taskio)?; async!(from session.complete_io(&mut taskio))?;
} }
self.io.poll_close(ctx) self.io.poll_close(ctx)