diff --git a/server.go b/server.go index 9dd3349..e57eea3 100644 --- a/server.go +++ b/server.go @@ -131,8 +131,9 @@ func (s *server) handleRequest(ctx *fasthttp.RequestCtx) { s.handleError(ctx, fasthttp.StatusInternalServerError, err) return } + 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) } -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() 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 case <-handleDoneChan: close(clientStopChan) - conn.Close() logging.Logger.Debug(fmt.Sprintf("Server: Client[%s] is disconnected.", conn.RemoteAddr())) + conn.Close() } } diff --git a/socket.go b/socket.go deleted file mode 100644 index eb2c21d..0000000 --- a/socket.go +++ /dev/null @@ -1,2 +0,0 @@ -package websocket_fasthttp - diff --git a/socket_handler.go b/socket_handler.go index 9875a26..db5e731 100644 --- a/socket_handler.go +++ b/socket_handler.go @@ -6,6 +6,6 @@ import ( ) 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{}) } diff --git a/socket_handlers.go b/socket_handlers.go index b914305..a0fb338 100644 --- a/socket_handlers.go +++ b/socket_handlers.go @@ -11,6 +11,7 @@ type SocketHandlers struct { func (sh *SocketHandlers) Handshake(ctx *fasthttp.RequestCtx) (bool, *fasthttp.ResponseHeader) { return true, nil } + func (sh *SocketHandlers) Handle(conn *websocket.Conn, stopChan <-chan struct{}, doneChan chan<- struct{}) { // no op }