From 994526a30da53a94f714e89d74b8888a9e15b774 Mon Sep 17 00:00:00 2001 From: Sebastian Mark Date: Thu, 21 Nov 2024 20:11:09 +0100 Subject: [PATCH] drop `sendPing()` --- internal/websocket/staleClients.go | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/internal/websocket/staleClients.go b/internal/websocket/staleClients.go index 0752208..f4fce6b 100644 --- a/internal/websocket/staleClients.go +++ b/internal/websocket/staleClients.go @@ -16,7 +16,10 @@ func RemoveStaleClients() { for range ticker.C { mu.Lock() for _, client := range Clients { - if !sendPing(client) || isStale(client) { + client.Conn.SetWriteDeadline(time.Now().Add(SEND_TIMEOUT * time.Second)) + client.Conn.WriteMessage(websocket.PingMessage, nil) + + if isStale(client) { client.Conn.Close() delete(Clients, client.Conn.LocalAddr()) helper.Logger.Info("Removed stale client", "host", client.RealIP, "lastPong", client.LastPong) @@ -26,17 +29,6 @@ func RemoveStaleClients() { } } -func sendPing(client *models.WebsocketClient) bool { - client.Conn.SetWriteDeadline(time.Now().Add(SEND_TIMEOUT * time.Second)) - err := client.Conn.WriteMessage(websocket.PingMessage, nil) - - if err != nil { - return false - } - - return true -} - func isStale(client *models.WebsocketClient) bool { return time.Since(client.LastPong) > (STALE_CLIENT_TIMEOUT * time.Second) }