From d1e892d449e5ba98790beb6a6a0f91294af32cfc Mon Sep 17 00:00:00 2001 From: mountain Date: Tue, 26 Dec 2023 00:18:15 +0900 Subject: [PATCH] =?UTF-8?q?=EC=83=9D=EC=84=B1=20=EC=82=AD=EC=A0=9C=20?= =?UTF-8?q?=EC=B1=84=EB=84=90=EC=9D=84=20=EB=B0=96=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EB=BA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- wshandler/wshandler_peer.go | 43 ------------------------------------- 1 file changed, 43 deletions(-) diff --git a/wshandler/wshandler_peer.go b/wshandler/wshandler_peer.go index 7d90c03..1cecf45 100644 --- a/wshandler/wshandler_peer.go +++ b/wshandler/wshandler_peer.go @@ -22,22 +22,10 @@ type WebsocketPeerHandler interface { RegisterHandlers(serveMux *http.ServeMux, prefix string) error } -type connEstChannelValue struct { - accid primitive.ObjectID - conn *websocket.Conn -} - -type connDisChannelValue struct { - accid primitive.ObjectID - closed bool -} - type websocketPeerHandler[T PeerInterface] struct { methods map[string]peerApiFuncType[T] createPeer func(primitive.ObjectID) T sessionConsumer session.Consumer - connEstChannel chan connEstChannelValue - connDisChannel chan connDisChannelValue } type PeerInterface interface { @@ -156,24 +144,12 @@ func NewWebsocketPeerHandler[T PeerInterface](consumer session.Consumer, creator sessionConsumer: consumer, methods: methods, createPeer: creator, - connEstChannel: make(chan connEstChannelValue), - connDisChannel: make(chan connDisChannelValue), } - consumer.RegisterOnSessionInvalidated(wsh.onSessionInvalidated) return wsh } -func (ws *websocketPeerHandler[T]) onSessionInvalidated(accid primitive.ObjectID) { - ws.connDisChannel <- connDisChannelValue{ - accid: accid, - closed: false, - } -} - func (ws *websocketPeerHandler[T]) RegisterHandlers(serveMux *http.ServeMux, prefix string) error { - go ws.sessionMonitoring() - if *noAuthFlag { serveMux.HandleFunc(prefix, ws.upgrade_noauth) } else { @@ -183,33 +159,14 @@ func (ws *websocketPeerHandler[T]) RegisterHandlers(serveMux *http.ServeMux, pre return nil } -func (ws *websocketPeerHandler[T]) sessionMonitoring() { - all := make(map[primitive.ObjectID]*websocket.Conn) - for { - select { - case estVal := <-ws.connEstChannel: - all[estVal.accid] = estVal.conn - case disVal := <-ws.connDisChannel: - if disVal.closed { - delete(all, disVal.accid) - } else if c := all[disVal.accid]; c != nil { - c.Close() - delete(all, disVal.accid) - } - } - } -} - func (ws *websocketPeerHandler[T]) upgrade_core(conn *websocket.Conn, accid primitive.ObjectID, nonce uint32) { go func(c *websocket.Conn, accid primitive.ObjectID) { peer := ws.createPeer(accid) var closeReason string peer.ClientConnected(conn) - ws.connEstChannel <- connEstChannelValue{accid: accid, conn: conn} defer func() { - ws.connDisChannel <- connDisChannelValue{accid: accid, closed: true} peer.ClientDisconnected(closeReason) }()