ing
This commit is contained in:
parent
d13384841b
commit
52c900f0a2
13
server.go
13
server.go
|
@ -3,7 +3,6 @@ package server
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
|
||||||
"net"
|
"net"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
@ -120,18 +119,18 @@ func runServer(s *server) {
|
||||||
|
|
||||||
func handleConnection(s *server, conn io.ReadWriteCloser, clientAddr string) {
|
func handleConnection(s *server, conn io.ReadWriteCloser, clientAddr string) {
|
||||||
defer s.stopWg.Done()
|
defer s.stopWg.Done()
|
||||||
log.Printf("Connected: %s", clientAddr)
|
logging.Logger.Debug(fmt.Sprintf("Server: Client[%s] is connected.", clientAddr))
|
||||||
stopChan := make(chan struct{})
|
clientStopChan := make(chan struct{})
|
||||||
go s.serverHandler.Handle(clientAddr, conn, stopChan)
|
go s.serverHandler.Handle(clientAddr, conn, clientStopChan)
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case <-s.stopChan:
|
case <-s.stopChan:
|
||||||
close(stopChan)
|
close(clientStopChan)
|
||||||
conn.Close()
|
conn.Close()
|
||||||
return
|
return
|
||||||
case <-stopChan:
|
case <-clientStopChan:
|
||||||
conn.Close()
|
conn.Close()
|
||||||
log.Printf("Disconnected: %s", clientAddr)
|
logging.Logger.Debug(fmt.Sprintf("Server: Client[%s] is disconnected.", clientAddr))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user