This commit is contained in:
fiatjaf
2024-07-30 09:43:04 -03:00
parent 096890804f
commit a63dc829df
12 changed files with 353 additions and 115 deletions

View File

@@ -49,11 +49,12 @@ func (rl *Relay) Start(host string, port int, started ...chan bool) error {
// Shutdown sends a websocket close control message to all connected clients.
func (rl *Relay) Shutdown(ctx context.Context) {
rl.httpServer.Shutdown(ctx)
rl.clients.Range(func(conn *websocket.Conn, _ struct{}) bool {
conn.WriteControl(websocket.CloseMessage, nil, time.Now().Add(time.Second))
conn.Close()
rl.clients.Delete(conn)
return true
})
rl.clientsMutex.Lock()
defer rl.clientsMutex.Unlock()
for ws := range rl.clients {
ws.conn.WriteControl(websocket.CloseMessage, nil, time.Now().Add(time.Second))
ws.conn.Close()
}
clear(rl.clients)
rl.listeners = rl.listeners[:0]
}