Skip to content

Commit 96eb483

Browse files
committed
Update example: Restart server instead of abort
You don't want to restart aborted sample server everytime it meets errors. :)
1 parent 5dec3f9 commit 96eb483

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

examples/server.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//! otherwise HTTP/1.1 will be used.
77
use core::task::{Context, Poll};
88
use futures_util::{
9-
future::TryFutureExt,
9+
future::{ready, TryFutureExt},
1010
stream::{Stream, StreamExt, TryStreamExt},
1111
};
1212
use hyper::service::{make_service_fn, service_fn};
@@ -65,12 +65,14 @@ async fn run_server() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
6565
.map_err(|e| error(format!("Incoming failed: {:?}", e)))
6666
.and_then(move |s| {
6767
tls_acceptor.accept(s).map_err(|e| {
68-
println!("[!] Voluntary server halt due to client-connection error...");
69-
// Errors could be handled here, instead of server aborting.
70-
// Ok(None)
68+
eprintln!("TLS Error: {:?}", e);
7169
error(format!("TLS Error: {:?}", e))
7270
})
7371
})
72+
.filter(|res| {
73+
// Ignore failed accepts
74+
ready(res.is_ok())
75+
})
7476
.boxed();
7577

7678
let service = make_service_fn(|_| async { Ok::<_, io::Error>(service_fn(echo)) });

0 commit comments

Comments
 (0)