mirror of
https://github.com/nonoo/kappanhang.git
synced 2025-12-06 08:02:00 +01:00
Close the TCP serial server client connection when there's an error
This commit is contained in:
parent
f64d9018f6
commit
3a1b74ce2d
|
|
@ -90,7 +90,17 @@ func (s *serialTCPSrvStruct) clientLoop() {
|
|||
writeErrChan := make(chan error)
|
||||
go s.writeLoop(writeLoopDeinitNeededChan, writeLoopDeinitFinishedChan, writeErrChan)
|
||||
|
||||
connected:
|
||||
defer func() {
|
||||
s.client.Close()
|
||||
log.Print("client ", s.client.RemoteAddr().String(), " disconnected")
|
||||
|
||||
writeLoopDeinitNeededChan <- true
|
||||
<-writeLoopDeinitFinishedChan
|
||||
|
||||
<-s.clientLoopDeinitNeededChan
|
||||
s.clientLoopDeinitFinishedChan <- true
|
||||
}()
|
||||
|
||||
for {
|
||||
b := make([]byte, maxSerialFrameLength)
|
||||
n, err := s.client.Read(b)
|
||||
|
|
@ -101,7 +111,7 @@ connected:
|
|||
select {
|
||||
case s.fromClient <- b[:n]:
|
||||
case <-writeErrChan:
|
||||
break connected
|
||||
return
|
||||
case <-s.clientLoopDeinitNeededChan:
|
||||
writeLoopDeinitNeededChan <- true
|
||||
<-writeLoopDeinitFinishedChan
|
||||
|
|
@ -110,14 +120,6 @@ connected:
|
|||
return
|
||||
}
|
||||
}
|
||||
|
||||
log.Print("client ", s.client.RemoteAddr().String(), " disconnected")
|
||||
|
||||
writeLoopDeinitNeededChan <- true
|
||||
<-writeLoopDeinitFinishedChan
|
||||
|
||||
<-s.clientLoopDeinitNeededChan
|
||||
s.clientLoopDeinitFinishedChan <- true
|
||||
}
|
||||
|
||||
func (s *serialTCPSrvStruct) loop() {
|
||||
|
|
|
|||
Loading…
Reference in a new issue