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
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
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
blocking I/O. Until this is fixed, do something this on Windows:
```sh
echo | cargo run --example client hsts.badssl.com
cd examples/client
echo | cargo run -- hsts.badssl.com
```
### 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
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

View File

@ -52,20 +52,18 @@ fn main() {
let done = socket.incoming()
.for_each(move |stream| if flag_echo {
let addr = stream.peer_addr().ok();
let addr2 = addr.clone();
let done = arc_config.accept_async(stream)
.and_then(|stream| {
let (reader, writer) = stream.split();
io::copy(reader, writer)
})
.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);
Ok(())
} else {
let addr = stream.peer_addr().ok();
let addr2 = addr.clone();
let done = arc_config.accept_async(stream)
.and_then(|stream| io::write_all(
stream,
@ -77,7 +75,7 @@ fn main() {
))
.and_then(|(stream, _)| io::flush(stream))
.map(move |_| println!("Accept: {:?}", addr))
.map_err(move |err| println!("Error: {:?} - {:?}", err, addr2));
.map_err(move |err| println!("Error: {:?} - {:?}", err, addr));
tokio::spawn(done);
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> {
let (io, session) = self.get_mut();
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> {
@ -157,7 +161,7 @@ impl<S, C> AsyncWrite for TlsStream<S, C>
{
let (io, session) = self.get_mut();
let mut taskio = TaskStream { io, task: ctx };
session.complete_io(&mut taskio)?;
async!(from session.complete_io(&mut taskio))?;
}
self.io.poll_close(ctx)