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: