summaryrefslogtreecommitdiffstats
path: root/examples/udp-codec.rs
diff options
context:
space:
mode:
authorCarl Lerche <me@carllerche.com>2018-03-06 09:59:04 -0800
committerGitHub <noreply@github.com>2018-03-06 09:59:04 -0800
commitf1cb12e14fb047f3f86c852c253962c60ce471e8 (patch)
tree59aab45a28961b00f7c71c5eb083c6242b51ff01 /examples/udp-codec.rs
parent56c579787260abcb9786aa22cfca1ee4b7c3b5ba (diff)
Update examples to track latest Tokio changes (#180)
The exampes included in the repository have lagged behind the changes made. Specifically, they do not use the new runtime construct. This patch updates examples to use the latest features of Tokio.
Diffstat (limited to 'examples/udp-codec.rs')
-rw-r--r--examples/udp-codec.rs23
1 files changed, 11 insertions, 12 deletions
diff --git a/examples/udp-codec.rs b/examples/udp-codec.rs
index be686d63..c9b53f17 100644
--- a/examples/udp-codec.rs
+++ b/examples/udp-codec.rs
@@ -1,29 +1,25 @@
-//! This is a basic example of leveraging `BytesCodec` to create a simple UDP
-//! client and server which speak a custom protocol.
+//! This example leverages `BytesCodec` to create a UDP client and server which
+//! speak a custom protocol.
//!
//! Here we're using the codec from tokio-io to convert a UDP socket to a stream of
//! client messages. These messages are then processed and returned back as a
//! new message with a new destination. Overall, we then use this to construct a
//! "ping pong" pair where two sockets are sending messages back and forth.
+#![deny(warnings)]
+
extern crate tokio;
extern crate tokio_io;
extern crate env_logger;
-extern crate futures;
-extern crate futures_cpupool;
use std::net::SocketAddr;
-use futures::{Future, Stream, Sink};
-use futures::future::Executor;
-use futures_cpupool::CpuPool;
+use tokio::prelude::*;
use tokio::net::{UdpSocket, UdpFramed};
use tokio_io::codec::BytesCodec;
fn main() {
- drop(env_logger::init());
-
- let pool = CpuPool::new(1);
+ let _ = env_logger::init();
let addr: SocketAddr = "127.0.0.1:0".parse().unwrap();
@@ -59,6 +55,9 @@ fn main() {
let b = b_sink.send_all(b_stream);
// Spawn the sender of pongs and then wait for our pinger to finish.
- pool.execute(b.then(|_| Ok(()))).unwrap();
- drop(a.wait());
+ tokio::run({
+ b.join(a)
+ .map(|_| ())
+ .map_err(|e| println!("error = {:?}", e))
+ });
}