diff options
author | Alex Crichton <alex@alexcrichton.com> | 2016-08-17 11:23:32 -0700 |
---|---|---|
committer | Alex Crichton <alex@alexcrichton.com> | 2016-08-17 18:41:34 -0700 |
commit | 311bfa07a362657c57037b44404a6e42cf560438 (patch) | |
tree | 3855d3fa7d1609cd445a0fa6561316d6ab4388a1 /src/bin/echo.rs | |
parent | d0b911189c9a879fd3861b7fc84d4f03723208de (diff) |
Update futures-minihttp
Diffstat (limited to 'src/bin/echo.rs')
-rw-r--r-- | src/bin/echo.rs | 28 |
1 files changed, 4 insertions, 24 deletions
diff --git a/src/bin/echo.rs b/src/bin/echo.rs index 6bc76b7c..338d44d4 100644 --- a/src/bin/echo.rs +++ b/src/bin/echo.rs @@ -5,14 +5,11 @@ extern crate futures_io; extern crate futures_mio; use std::env; -use std::io::{self, Read, Write}; use std::net::SocketAddr; -use std::sync::Arc; use futures::Future; use futures::stream::Stream; -use futures_io::copy; -use futures_mio::TcpStream; +use futures_io::{copy, TaskIo}; fn main() { let addr = env::args().nth(1).unwrap_or("127.0.0.1:8080".to_string()); @@ -36,8 +33,9 @@ fn main() { // Finally we use the `io::copy` future to copy all data from the // reading half onto the writing half. socket.incoming().for_each(|(socket, addr)| { - let socket = Arc::new(socket); - let amt = copy(SocketIo(socket.clone()), SocketIo(socket)); + let socket = futures::lazy(|| futures::finished(TaskIo::new(socket))); + let pair = socket.map(|s| s.split()); + let amt = pair.and_then(|(reader, writer)| copy(reader, writer)); // Once all that is done we print out how much we wrote, and then // critically we *forget* this future which allows it to run @@ -51,21 +49,3 @@ fn main() { }); l.run(done).unwrap(); } - -struct SocketIo(Arc<TcpStream>); - -impl Read for SocketIo { - fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> { - (&*self.0).read(buf) - } -} - -impl Write for SocketIo { - fn write(&mut self, buf: &[u8]) -> io::Result<usize> { - (&*self.0).write(buf) - } - - fn flush(&mut self) -> io::Result<()> { - (&*self.0).flush() - } -} |