mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-09-07 00:00:08 +02:00
Re-work I/O
* Auto-register interest whenever we see WouldBlock
* Remove implementations of `Stream<Item=Ready>`, no longer needed
* Add explicit `poll_{read,write}` methods, if needed
* Remove all I/O streams, libstd ones suffice
* Update all I/O futures
This commit is contained in:
+4
-15
@@ -9,7 +9,6 @@ extern crate futures_io;
|
||||
extern crate futures_mio;
|
||||
|
||||
use std::env;
|
||||
use std::io::{self, Write};
|
||||
use std::net::SocketAddr;
|
||||
|
||||
use futures::Future;
|
||||
@@ -24,7 +23,7 @@ fn main() {
|
||||
let server = l.handle().tcp_listen(&addr).and_then(|socket| {
|
||||
socket.incoming().and_then(|(socket, addr)| {
|
||||
println!("got a socket: {}", addr);
|
||||
write(socket)
|
||||
write(socket).or_else(|_| Ok(()))
|
||||
}).for_each(|()| {
|
||||
println!("lost the socket");
|
||||
Ok(())
|
||||
@@ -34,20 +33,10 @@ fn main() {
|
||||
l.run(server).unwrap();
|
||||
}
|
||||
|
||||
// TODO: this blows the stack...
|
||||
fn write(socket: futures_mio::TcpStream) -> IoFuture<()> {
|
||||
static BUF: &'static [u8] = &[0; 64 * 1024];
|
||||
socket.into_future().map_err(|e| e.0).and_then(move |(ready, mut socket)| {
|
||||
let ready = match ready {
|
||||
Some(ready) => ready,
|
||||
None => return futures::finished(()).boxed(),
|
||||
};
|
||||
while ready.is_write() {
|
||||
match socket.write(&BUF) {
|
||||
Ok(_) => {}
|
||||
Err(ref e) if e.kind() == io::ErrorKind::WouldBlock => break,
|
||||
Err(e) => return futures::failed(e).boxed(),
|
||||
}
|
||||
}
|
||||
static BUF: &'static [u8] = &[0; 1 * 1024 * 1024];
|
||||
futures_io::write_all(socket, BUF).and_then(|(socket, _)| {
|
||||
write(socket)
|
||||
}).boxed()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user