From cc460e2fe9735f32f7a5195cfb544ed59cc56bff Mon Sep 17 00:00:00 2001 From: "." <.@.> Date: Sat, 7 May 2016 12:59:28 +1200 Subject: [PATCH] correctly disconnect from upstream on client disconnect --HG-- branch : nmdc-ircfrontend --- server.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/server.go b/server.go index 9019b6b..6b538f1 100644 --- a/server.go +++ b/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) } }