correctly disconnect from upstream on client disconnect
--HG-- branch : nmdc-ircfrontend
This commit is contained in:
parent
cc04626518
commit
cc460e2fe9
17
server.go
17
server.go
@ -23,6 +23,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"libnmdc"
|
||||
"log"
|
||||
"net"
|
||||
"strings"
|
||||
"time"
|
||||
@ -70,11 +71,14 @@ func (s *Server) RunWorker() {
|
||||
}
|
||||
|
||||
buf := make([]byte, CLIENT_READ_BUFFSIZE)
|
||||
|
||||
//s.clientConn.SetReadDeadline(time.Now().Add(5 * time.Second))
|
||||
ln, err := s.clientConn.Read(buf)
|
||||
if err != nil {
|
||||
if err == io.EOF {
|
||||
break // abandon thread
|
||||
}
|
||||
//log.Println(err.Error())
|
||||
continue
|
||||
}
|
||||
|
||||
@ -100,17 +104,16 @@ func (s *Server) RunWorker() {
|
||||
}
|
||||
}
|
||||
|
||||
// Cleanup
|
||||
s.DisconnectClient() // if not already done
|
||||
log.Println("Broken loop.")
|
||||
|
||||
// Cleanup upstream
|
||||
if s.clientConn != nil && s.clientRegistered {
|
||||
s.upstreamCloser <- struct{}{}
|
||||
if s.clientRegistered {
|
||||
s.upstreamCloser <- struct{}{} // always safe to do this /once/
|
||||
}
|
||||
|
||||
// Clean up ourselves
|
||||
s.DisconnectClient() // if not already done
|
||||
s.clientRegistered = false
|
||||
|
||||
}
|
||||
|
||||
func (s *Server) upstreamWorker() {
|
||||
@ -120,6 +123,7 @@ func (s *Server) upstreamWorker() {
|
||||
select {
|
||||
case <-s.upstreamCloser:
|
||||
// Abandon the upstream connection
|
||||
log.Println("Abandoning upstream connection...")
|
||||
s.upstream.Disconnect()
|
||||
return
|
||||
|
||||
@ -151,7 +155,8 @@ func (s *Server) upstreamWorker() {
|
||||
}
|
||||
|
||||
case libnmdc.EVENT_SYSTEM_MESSAGE_FROM_CONN, libnmdc.EVENT_SYSTEM_MESSAGE_FROM_HUB:
|
||||
s.sendClientGlobalMessage(hubEvent.Message)
|
||||
s.reply(rplMsg, BLESSED_CHANNEL, BLESSED_CHANNEL, hubEvent.Message) // experimental
|
||||
// s.sendClientGlobalMessage(hubEvent.Message)
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user