This commit is contained in:
crusader 2017-10-27 16:14:20 +09:00
parent 4163705d49
commit ee5c8cf463
3 changed files with 12 additions and 0 deletions

View File

@ -119,6 +119,13 @@ func runServer(s *server) {
func handleServerConnection(s *server, conn io.ReadWriteCloser, clientAddr string) { func handleServerConnection(s *server, conn io.ReadWriteCloser, clientAddr string) {
defer s.stopWg.Done() 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)) logging.Logger.Debug(fmt.Sprintf("Server: Client[%s] is connected.", clientAddr))
clientStopChan := make(chan struct{}) clientStopChan := make(chan struct{})
go s.serverHandler.Handle(clientAddr, conn, clientStopChan) go s.serverHandler.Handle(clientAddr, conn, clientStopChan)

View File

@ -7,6 +7,7 @@ import (
type ServerHandler interface { type ServerHandler interface {
Listen() (net.Listener, error) Listen() (net.Listener, error)
OnHandshake(remoteAddr string, rwc io.ReadWriteCloser) error
Handle(remoteAddr string, rwc io.ReadWriteCloser, stopChan chan struct{}) Handle(remoteAddr string, rwc io.ReadWriteCloser, stopChan chan struct{})
OnStopped() OnStopped()

View File

@ -27,6 +27,10 @@ func (sh *ServerHandlers) Listen() (net.Listener, error) {
return nil, errors.New("Server: Handler method[Listen] of Server is not implement") 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{}) { func (sh *ServerHandlers) Handle(remoteAddr string, rwc io.ReadWriteCloser, stopChan chan struct{}) {
} }