Client cleanup
This commit is contained in:
+12
-7
@@ -49,7 +49,7 @@ impl Server {
|
||||
|
||||
let mut clients_meta = s.clients.lock().await;
|
||||
|
||||
let client_meta =
|
||||
let clients =
|
||||
clients_meta
|
||||
.entry(public_key)
|
||||
.or_insert_with(|| UserConnections {
|
||||
@@ -59,18 +59,23 @@ impl Server {
|
||||
connections: HashMap::new(),
|
||||
});
|
||||
|
||||
client_meta.connections.insert(
|
||||
client_meta
|
||||
.counter
|
||||
.fetch_add(1, std::sync::atomic::Ordering::Relaxed),
|
||||
client.clone(),
|
||||
);
|
||||
let conid = clients
|
||||
.counter
|
||||
.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
|
||||
|
||||
clients.connections.insert(conid, client.clone());
|
||||
|
||||
if let Err(e) = read_loop(&client).await {
|
||||
eprintln!("Failed to handle client: {e}");
|
||||
} else {
|
||||
println!("Client connection closed")
|
||||
}
|
||||
|
||||
clients.connections.remove(&conid);
|
||||
|
||||
if clients.connections.len() == 0 {
|
||||
clients_meta.remove(&public_key);
|
||||
}
|
||||
}
|
||||
|
||||
Err(e) => {
|
||||
|
||||
Reference in New Issue
Block a user