reorder staleClients.go
This commit is contained in:
parent
68b5784255
commit
2c3ccc86c3
1 changed files with 15 additions and 15 deletions
|
@ -8,21 +8,6 @@ import (
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
)
|
)
|
||||||
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check and remove stale clients
|
// Check and remove stale clients
|
||||||
func RemoveStaleClients() {
|
func RemoveStaleClients() {
|
||||||
ticker := time.NewTicker(STALE_CHECK_INTERVALL * time.Second)
|
ticker := time.NewTicker(STALE_CHECK_INTERVALL * time.Second)
|
||||||
|
@ -40,3 +25,18 @@ func RemoveStaleClients() {
|
||||||
mu.Unlock()
|
mu.Unlock()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue