mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-04-01 18:25:30 +00:00
aquatic_ws: in listener, remove previous connection if it exists
This commit is contained in:
parent
0ec73d6cea
commit
e4bb851c10
1 changed files with 31 additions and 0 deletions
|
|
@ -131,6 +131,35 @@ pub fn run_socket_worker(
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fn remove_connection_if_exists(
|
||||||
|
poll: &mut Poll,
|
||||||
|
connections: &mut ConnectionMap,
|
||||||
|
token: Token,
|
||||||
|
){
|
||||||
|
if let Some(connection) = connections.remove(&token){
|
||||||
|
match connection.stage {
|
||||||
|
ConnectionStage::Stream(mut stream) => {
|
||||||
|
poll.registry()
|
||||||
|
.deregister(&mut stream)
|
||||||
|
.unwrap();
|
||||||
|
},
|
||||||
|
ConnectionStage::MidHandshake(mut handshake) => {
|
||||||
|
poll.registry()
|
||||||
|
.deregister(handshake.get_mut().get_mut())
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
ConnectionStage::Established(mut peer_connection) => {
|
||||||
|
poll.registry()
|
||||||
|
.deregister(peer_connection.ws.get_mut())
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
connections.remove(&token);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
fn accept_new_streams(
|
fn accept_new_streams(
|
||||||
listener: &mut TcpListener,
|
listener: &mut TcpListener,
|
||||||
poll: &mut Poll,
|
poll: &mut Poll,
|
||||||
|
|
@ -149,6 +178,8 @@ fn accept_new_streams(
|
||||||
|
|
||||||
let token = *poll_token_counter;
|
let token = *poll_token_counter;
|
||||||
|
|
||||||
|
remove_connection_if_exists(poll, connections, token);
|
||||||
|
|
||||||
poll.registry()
|
poll.registry()
|
||||||
.register(&mut stream, token, Interest::READABLE)
|
.register(&mut stream, token, Interest::READABLE)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue