ing
This commit is contained in:
parent
072d6f11a8
commit
760e6b8ae1
|
@ -131,8 +131,9 @@ func (s *server) handleRequest(ctx *fasthttp.RequestCtx) {
|
||||||
s.handleError(ctx, fasthttp.StatusInternalServerError, err)
|
s.handleError(ctx, fasthttp.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
s.stopWg.Add(1)
|
s.stopWg.Add(1)
|
||||||
go handleConnection(s, ctx, conn, socketHandler)
|
go handleConnection(s, conn, socketHandler)
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -144,7 +145,7 @@ func (s *server) handleError(ctx *fasthttp.RequestCtx, status int, reason error)
|
||||||
s.sh.OnError(ctx, status, reason)
|
s.sh.OnError(ctx, status, reason)
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleConnection(s *server, ctx *fasthttp.RequestCtx, conn *websocket.Conn, handler SocketHandler) {
|
func handleConnection(s *server, conn *websocket.Conn, handler SocketHandler) {
|
||||||
defer s.stopWg.Done()
|
defer s.stopWg.Done()
|
||||||
|
|
||||||
logging.Logger.Debug(fmt.Sprintf("Server: Client[%s] is connected.", conn.RemoteAddr()))
|
logging.Logger.Debug(fmt.Sprintf("Server: Client[%s] is connected.", conn.RemoteAddr()))
|
||||||
|
@ -160,8 +161,8 @@ func handleConnection(s *server, ctx *fasthttp.RequestCtx, conn *websocket.Conn,
|
||||||
<-handleDoneChan
|
<-handleDoneChan
|
||||||
case <-handleDoneChan:
|
case <-handleDoneChan:
|
||||||
close(clientStopChan)
|
close(clientStopChan)
|
||||||
conn.Close()
|
|
||||||
logging.Logger.Debug(fmt.Sprintf("Server: Client[%s] is disconnected.", conn.RemoteAddr()))
|
logging.Logger.Debug(fmt.Sprintf("Server: Client[%s] is disconnected.", conn.RemoteAddr()))
|
||||||
|
conn.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,6 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type SocketHandler interface {
|
type SocketHandler interface {
|
||||||
Handshake(ctx *fasthttp.RequestCtx) (bool, *fasthttp.ResponseHeader)
|
Handshake(ctx *fasthttp.RequestCtx) (connectable bool, extensionsHeader *fasthttp.ResponseHeader)
|
||||||
Handle(conn *websocket.Conn, stopChan <-chan struct{}, doneChan chan<- struct{})
|
Handle(conn *websocket.Conn, stopChan <-chan struct{}, doneChan chan<- struct{})
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ type SocketHandlers struct {
|
||||||
func (sh *SocketHandlers) Handshake(ctx *fasthttp.RequestCtx) (bool, *fasthttp.ResponseHeader) {
|
func (sh *SocketHandlers) Handshake(ctx *fasthttp.RequestCtx) (bool, *fasthttp.ResponseHeader) {
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sh *SocketHandlers) Handle(conn *websocket.Conn, stopChan <-chan struct{}, doneChan chan<- struct{}) {
|
func (sh *SocketHandlers) Handle(conn *websocket.Conn, stopChan <-chan struct{}, doneChan chan<- struct{}) {
|
||||||
// no op
|
// no op
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user