From d2dec97259e69bf14d202ff1acd83b8379e99634 Mon Sep 17 00:00:00 2001 From: "." <.@.> Date: Thu, 5 May 2016 18:56:55 +1200 Subject: [PATCH] handle terminating the libnmdc connection --HG-- branch : nmdc-ircfrontend --- server.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/server.go b/server.go index 41fae31..0ebaf4d 100644 --- a/server.go +++ b/server.go @@ -17,6 +17,7 @@ type Server struct { client *Client channel Channel // Single blessed channel upstreamLauncher libnmdc.HubConnectionOptions + upstreamCloser chan struct{} upstream *libnmdc.HubConnection motd string } @@ -33,6 +34,7 @@ func NewServer(name string, upstream libnmdc.HubAddress) *Server { Address: upstream, Self: *self, }, + upstreamCloser: make(chan struct{}, 1), channel: Channel{ clientMap: make(map[string]*Client), modeMap: make(map[string]*ClientMode), @@ -60,6 +62,9 @@ func (s *Server) RunClient(conn net.Conn) { if err != nil { if err == io.EOF { s.client.disconnect() + if s.client != nil && s.client.registered { + s.upstreamCloser <- struct{}{} + } return // FIXME cleanup } continue @@ -98,7 +103,8 @@ func (s *Server) ProtocolReadLoop_NMDC(closeChan chan struct{}) { for { select { case <-closeChan: - // Need some way of deliberately shutting down a libnmdc connection... + // Abandon the upstream connection + s.upstream.Disconnect() return case hubEvent := <-s.upstream.OnEvent: