feat: 增加Ping任务管理功能

This commit is contained in:
Akizon77
2025-06-21 16:47:39 +08:00
parent 785f448baf
commit d6b58f6eed
10 changed files with 400 additions and 21 deletions

View File

@@ -8,23 +8,23 @@ import (
)
var (
connectedClients = make(map[string]*websocket.Conn)
connectedClients = make(map[string]*SafeConn)
ConnectedUsers = []*websocket.Conn{}
latestReport = make(map[string]*common.Report)
mu = sync.RWMutex{}
)
func GetConnectedClients() map[string]*websocket.Conn {
func GetConnectedClients() map[string]*SafeConn {
mu.RLock()
defer mu.RUnlock()
clientsCopy := make(map[string]*websocket.Conn)
clientsCopy := make(map[string]*SafeConn)
for k, v := range connectedClients {
clientsCopy[k] = v
}
return clientsCopy
}
func SetConnectedClients(uuid string, conn *websocket.Conn) {
func SetConnectedClients(uuid string, conn *SafeConn) {
mu.Lock()
defer mu.Unlock()
connectedClients[uuid] = conn
@@ -32,6 +32,9 @@ func SetConnectedClients(uuid string, conn *websocket.Conn) {
func DeleteConnectedClients(uuid string) {
mu.Lock()
defer mu.Unlock()
if conn, exists := connectedClients[uuid]; exists {
conn.Close()
}
delete(connectedClients, uuid)
}
func GetLatestReport() map[string]*common.Report {