split ping sending and pong check

This commit is contained in:
Sebastian Mark 2024-11-21 07:37:55 +01:00
parent 1e9b7fbb79
commit bb141bffb8

View file

@ -31,8 +31,14 @@ func RemoveStaleClients() {
for range ticker.C { for range ticker.C {
mu.Lock() mu.Lock()
for _, client := range Clients { for _, client := range Clients {
// send ping and check for last pong // send ping
if !sendPing(client) || isStale(client) { if !sendPing(client) {
client.Conn.Close()
delete(Clients, client.Conn.LocalAddr())
}
// check for last pong
if isStale(client) {
client.Conn.Close() client.Conn.Close()
delete(Clients, client.Conn.LocalAddr()) delete(Clients, client.Conn.LocalAddr())
} }