ㅑㅜㅎ

This commit is contained in:
crusader 2017-11-28 00:42:27 +09:00
parent 4522a80579
commit f653cbf551
2 changed files with 5 additions and 5 deletions

View File

@ -155,6 +155,10 @@ func (s *server) handleRequest(ctx *fasthttp.RequestCtx) {
socketCTX := socketHandler.SocketContext(s.ctx) socketCTX := socketHandler.SocketContext(s.ctx)
soc := newSocket(socketHandler, socketCTX, conn, socketID) soc := newSocket(socketHandler, socketCTX, conn, socketID)
logging.Logger().Debug(fmt.Sprintf("Server: Client[%s] is connected.", soc.RemoteAddr()))
socketHandler.addSocket(soc)
socketHandler.OnConnect(soc)
s.stopWg.Add(1) s.stopWg.Add(1)
handleConnection(s, soc, socketHandler) handleConnection(s, soc, socketHandler)
@ -171,10 +175,6 @@ func (s *server) handleError(ctx *fasthttp.RequestCtx, status int, reason error)
func handleConnection(s *server, soc Socket, socketHandler SocketHandler) { func handleConnection(s *server, soc Socket, socketHandler SocketHandler) {
defer s.stopWg.Done() defer s.stopWg.Done()
logging.Logger().Debug(fmt.Sprintf("Server: Client[%s] is connected.", soc.RemoteAddr()))
soc = socketHandler.OnConnect(soc)
socketHandler.addSocket(soc)
clientStopChan := make(chan struct{}) clientStopChan := make(chan struct{})
handleDoneChan := make(chan struct{}) handleDoneChan := make(chan struct{})

View File

@ -31,7 +31,7 @@ type SocketHandler interface {
// newSoc := ... // newSoc := ...
// return newSoc // return newSoc
// } // }
OnConnect(soc Socket) Socket OnConnect(soc Socket)
Handle(soc Socket, stopChan <-chan struct{}, doneChan chan<- struct{}) Handle(soc Socket, stopChan <-chan struct{}, doneChan chan<- struct{})
// OnDisconnect invoked when client is disconnected // OnDisconnect invoked when client is disconnected
// If you override ths method, must call // If you override ths method, must call