This commit is contained in:
crusader 2017-11-08 14:30:56 +09:00
parent 072d6f11a8
commit 760e6b8ae1
4 changed files with 6 additions and 6 deletions

View File

@ -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()
} }
} }

View File

@ -1,2 +0,0 @@
package websocket_fasthttp

View File

@ -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{})
} }

View File

@ -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
} }