This commit is contained in:
crusader 2017-10-27 14:33:35 +09:00
parent d13384841b
commit 52c900f0a2

View File

@ -3,7 +3,6 @@ package server
import (
"fmt"
"io"
"log"
"net"
"sync"
"sync/atomic"
@ -120,18 +119,18 @@ func runServer(s *server) {
func handleConnection(s *server, conn io.ReadWriteCloser, clientAddr string) {
defer s.stopWg.Done()
log.Printf("Connected: %s", clientAddr)
stopChan := make(chan struct{})
go s.serverHandler.Handle(clientAddr, conn, stopChan)
logging.Logger.Debug(fmt.Sprintf("Server: Client[%s] is connected.", clientAddr))
clientStopChan := make(chan struct{})
go s.serverHandler.Handle(clientAddr, conn, clientStopChan)
select {
case <-s.stopChan:
close(stopChan)
close(clientStopChan)
conn.Close()
return
case <-stopChan:
case <-clientStopChan:
conn.Close()
log.Printf("Disconnected: %s", clientAddr)
logging.Logger.Debug(fmt.Sprintf("Server: Client[%s] is disconnected.", clientAddr))
return
}
}