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