From ee5c8cf463643d9cb982d76aa7700406de939d98 Mon Sep 17 00:00:00 2001 From: crusader Date: Fri, 27 Oct 2017 16:14:20 +0900 Subject: [PATCH] ing --- server.go | 7 +++++++ server_handler.go | 1 + server_handlers.go | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/server.go b/server.go index d4cbf7c..dbec47a 100644 --- a/server.go +++ b/server.go @@ -119,6 +119,13 @@ func runServer(s *server) { func handleServerConnection(s *server, conn io.ReadWriteCloser, clientAddr string) { defer s.stopWg.Done() + + if err := s.serverHandler.OnHandshake(clientAddr, conn); nil != err { + logging.Logger.Error(fmt.Sprintf("Server: [%s]. handshake error: [%s]", clientAddr, err)) + conn.Close() + return + } + logging.Logger.Debug(fmt.Sprintf("Server: Client[%s] is connected.", clientAddr)) clientStopChan := make(chan struct{}) go s.serverHandler.Handle(clientAddr, conn, clientStopChan) diff --git a/server_handler.go b/server_handler.go index 59750cd..a1d1e4d 100644 --- a/server_handler.go +++ b/server_handler.go @@ -7,6 +7,7 @@ import ( type ServerHandler interface { Listen() (net.Listener, error) + OnHandshake(remoteAddr string, rwc io.ReadWriteCloser) error Handle(remoteAddr string, rwc io.ReadWriteCloser, stopChan chan struct{}) OnStopped() diff --git a/server_handlers.go b/server_handlers.go index 1d33a4a..974a945 100644 --- a/server_handlers.go +++ b/server_handlers.go @@ -27,6 +27,10 @@ func (sh *ServerHandlers) Listen() (net.Listener, error) { return nil, errors.New("Server: Handler method[Listen] of Server is not implement") } +func (sh *ServerHandlers) OnHandshake(remoteAddr string, rwc io.ReadWriteCloser) error { + return nil +} + func (sh *ServerHandlers) Handle(remoteAddr string, rwc io.ReadWriteCloser, stopChan chan struct{}) { }