Skip to content

Commit

Permalink
tlsserver: handle running out of slab, or event on closed connection
Browse files Browse the repository at this point in the history
  • Loading branch information
ctz committed Jan 25, 2017
1 parent b6a62a4 commit f6442a9
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions examples/tlsserver.rs
Expand Up @@ -79,11 +79,16 @@ impl mio::Handler for TlsServer {

let tls_session = rustls::ServerSession::new(&self.tls_config);
let mode = self.mode.clone();
let token = self.connections
.insert_with(|token| Connection::new(socket, token, mode, tls_session))
.unwrap();

self.connections[token].register(event_loop);
match self.connections
.insert_with(|token| Connection::new(socket, token, mode, tls_session)) {
Some(token) => {
self.connections[token].register(event_loop);
}
None => {
error!("Too many connections: rejecting new connection");
}
}
}
Ok(None) => {}
Err(e) => {
Expand All @@ -95,10 +100,12 @@ impl mio::Handler for TlsServer {

// A connection socket.
_ => {
self.connections[token].ready(event_loop, events);
if self.connections.contains(token) {
self.connections[token].ready(event_loop, events);

if self.connections[token].is_closed() {
self.connections.remove(token);
if self.connections[token].is_closed() {
self.connections.remove(token);
}
}
}
}
Expand Down

0 comments on commit f6442a9

Please sign in to comment.