mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-29 00:00:11 +02:00
+9
-4
@@ -198,24 +198,29 @@ mod udp {
|
|||||||
|
|
||||||
// All bytes from `stdin` will go to the `addr` specified in our
|
// All bytes from `stdin` will go to the `addr` specified in our
|
||||||
// argument list. Like with TCP this is spawned concurrently
|
// argument list. Like with TCP this is spawned concurrently
|
||||||
tokio::spawn(stdin.map(move |chunk| {
|
let forward_stdin = stdin.map(move |chunk| {
|
||||||
(chunk, addr)
|
(chunk, addr)
|
||||||
}).forward(sink).then(|result| {
|
}).forward(sink).then(|result| {
|
||||||
if let Err(e) = result {
|
if let Err(e) = result {
|
||||||
panic!("failed to write to socket: {}", e)
|
panic!("failed to write to socket: {}", e)
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}));
|
});
|
||||||
|
|
||||||
// With UDP we could receive data from any source, so filter out
|
// With UDP we could receive data from any source, so filter out
|
||||||
// anything coming from a different address
|
// anything coming from a different address
|
||||||
Box::new(stream.filter_map(move |(chunk, src)| {
|
let receive = stream.filter_map(move |(chunk, src)| {
|
||||||
if src == addr {
|
if src == addr {
|
||||||
Some(chunk.into())
|
Some(chunk.into())
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}))
|
});
|
||||||
|
|
||||||
|
Box::new(future::lazy(|| {
|
||||||
|
tokio::spawn(forward_stdin);
|
||||||
|
future::ok(receive)
|
||||||
|
}).flatten_stream())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user