diff options
author | Alex Crichton <alex@alexcrichton.com> | 2017-09-11 08:43:11 -0700 |
---|---|---|
committer | Alex Crichton <alex@alexcrichton.com> | 2017-09-11 08:43:11 -0700 |
commit | 85257e19af1a1fa0714a4c58297755f374cef949 (patch) | |
tree | e644d463794634ac2e8ceb99c7da93db3b48c3d2 /examples/connect.rs | |
parent | a611f6ec3043e63be340341cd97d17892ec6513c (diff) |
Touch up a few examples
Diffstat (limited to 'examples/connect.rs')
-rw-r--r-- | examples/connect.rs | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/examples/connect.rs b/examples/connect.rs index 315d2caf..4d8e0c7f 100644 --- a/examples/connect.rs +++ b/examples/connect.rs @@ -113,7 +113,12 @@ mod tcp { // with us reading data from the stream. Box::new(tcp.map(move |stream| { let (sink, stream) = stream.framed(Bytes).split(); - handle.spawn(stdin.forward(sink).then(|_| Ok(()))); + handle.spawn(stdin.forward(sink).then(|result| { + if let Err(e) = result { + panic!("failed to write to socket: {}", e) + } + Ok(()) + })); stream }).flatten_stream()) } @@ -172,7 +177,12 @@ mod udp { { // We'll bind our UDP socket to a local IP/port, but for now we // basically let the OS pick both of those. - let udp = UdpSocket::bind(&"0.0.0.0:0".parse().unwrap(), handle) + let addr_to_bind = if addr.ip().is_ipv4() { + "0.0.0.0:0".parse().unwrap() + } else { + "[::]:0".parse().unwrap() + }; + let udp = UdpSocket::bind(&addr_to_bind, handle) .expect("failed to bind socket"); // Like above with TCP we use an instance of `UdpCodec` to transform @@ -185,7 +195,12 @@ mod udp { // argument list. Like with TCP this is spawned concurrently handle.spawn(stdin.map(move |chunk| { (addr, chunk) - }).forward(sink).then(|_| Ok(()))); + }).forward(sink).then(|result| { + if let Err(e) = result { + panic!("failed to write to socket: {}", e) + } + Ok(()) + })); // With UDP we could receive data from any source, so filter out // anything coming from a different address @@ -227,6 +242,9 @@ fn read_stdin(mut tx: mpsc::Sender<Vec<u8>>) { Ok(n) => n, }; buf.truncate(n); - tx = tx.send(buf).wait().unwrap(); + tx = match tx.send(buf).wait() { + Ok(tx) => tx, + Err(_) => break, + }; } } |