Change net::Incoming signature to match std. (#89)

std's `Incoming` iterator yields `TcpStream` instances. This patch
updates the `Incoming` future to match this signature.

This changes the yielded value from `(TcpStream, SocketAddr)` ->
`TcpStream`.
This commit is contained in:
Carl Lerche
2018-01-30 15:01:34 -06:00
committed by Alex Crichton
parent f4ec9a6360
commit ae627db266
18 changed files with 31 additions and 28 deletions
+3 -1
View File
@@ -49,7 +49,9 @@ fn main() {
// Once the same thread executor lands, transition to single threaded.
let connections = Arc::new(Mutex::new(HashMap::new()));
let srv = socket.incoming().for_each(move |(stream, addr)| {
let srv = socket.incoming().for_each(move |stream| {
let addr = stream.peer_addr().unwrap();
println!("New Connection: {}", addr);
let (reader, writer) = stream.split();
+2 -1
View File
@@ -50,7 +50,8 @@ fn main() {
// The compress logic will happen in the function below, but everything's
// still a future! Each client is spawned to concurrently get processed.
let server = socket.incoming().for_each(move |(socket, addr)| {
let server = socket.incoming().for_each(move |socket| {
let addr = socket.peer_addr().unwrap();
pool.execute(compress(socket, &pool).then(move |result| {
match result {
Ok((r, w)) => println!("{}: compressed {} bytes to {}", addr, r, w),
+1 -1
View File
@@ -56,7 +56,7 @@ fn main() {
// shipped round-robin to a particular thread which will associate the
// socket with the corresponding event loop and process the connection.
let mut next = 0;
let srv = listener.incoming().for_each(|(socket, _)| {
let srv = listener.incoming().for_each(|socket| {
channels[next].unbounded_send(socket).expect("worker thread died");
next = (next + 1) % channels.len();
Ok(())
+5 -6
View File
@@ -60,12 +60,11 @@ fn main() {
// connections made to the server). The return value of the `for_each`
// method is itself a future representing processing the entire stream of
// connections, and ends up being our server.
let done = socket.incoming().for_each(move |(socket, addr)| {
let done = socket.incoming().for_each(move |socket| {
// Once we're inside this closure this represents an accepted client
// from our server. The `socket` is the client connection and `addr` is
// the remote address of the client (similar to how the standard library
// operates).
// from our server. The `socket` is the client connection (similar to
// how the standard library operates).
//
// We just want to copy all data read from the socket back onto the
// socket itself (e.g. "echo"). We can use the standard `io::copy`
@@ -88,8 +87,8 @@ fn main() {
// information.
let msg = amt.then(move |result| {
match result {
Ok((amt, _, _)) => println!("wrote {} bytes to {}", amt, addr),
Err(e) => println!("error on {}: {}", addr, e),
Ok((amt, _, _)) => println!("wrote {} bytes", amt),
Err(e) => println!("error: {}", e),
}
Ok(())
+1 -1
View File
@@ -33,7 +33,7 @@ fn main() {
println!("Listening for connections on {}", addr);
let clients = listener.incoming();
let welcomes = clients.and_then(|(socket, _peer_addr)| {
let welcomes = clients.and_then(|socket| {
tokio_io::io::write_all(socket, b"Hello!\n")
});
let server = welcomes.for_each(|(_socket, _welcome)| {
+3 -3
View File
@@ -48,7 +48,7 @@ fn main() {
println!("Listening on: {}", listen_addr);
println!("Proxying to: {}", server_addr);
let done = socket.incoming().for_each(move |(client, client_addr)| {
let done = socket.incoming().for_each(move |client| {
let server = TcpStream::connect(&server_addr);
let amounts = server.and_then(move |server| {
// Create separate read/write handles for the TCP clients that we're
@@ -82,8 +82,8 @@ fn main() {
});
let msg = amounts.map(move |(from_client, from_server)| {
println!("client at {} wrote {} bytes and received {} bytes",
client_addr, from_client, from_server);
println!("client wrote {} bytes and received {} bytes",
from_client, from_server);
}).map_err(|e| {
// Don't panic. Maybe the client just disconnected too soon.
println!("error: {}", e);
+2 -2
View File
@@ -41,8 +41,8 @@ fn main() {
let socket = TcpListener::bind(&addr).unwrap();
println!("Listening on: {}", addr);
let server = socket.incoming().for_each(|(socket, addr)| {
println!("got a socket: {}", addr);
let server = socket.incoming().for_each(|socket| {
println!("got a socket: {}", socket.peer_addr().unwrap());
pool.execute(write(socket).or_else(|_| Ok(()))).unwrap();
Ok(())
});
+1 -1
View File
@@ -100,7 +100,7 @@ fn main() {
map: Mutex::new(initial_db),
});
let done = listener.incoming().for_each(move |(socket, _addr)| {
let done = listener.incoming().for_each(move |socket| {
// As with many other small examples, the first thing we'll do is
// *split* this TCP stream into two separately owned halves. This'll
// allow us to work with the read and write halves independently.