handle terminating the libnmdc connection

--HG--
branch : nmdc-ircfrontend
This commit is contained in:
. 2016-05-05 18:56:55 +12:00
parent 07f01a1d92
commit d2dec97259

View File

@ -17,6 +17,7 @@ type Server struct {
client *Client client *Client
channel Channel // Single blessed channel channel Channel // Single blessed channel
upstreamLauncher libnmdc.HubConnectionOptions upstreamLauncher libnmdc.HubConnectionOptions
upstreamCloser chan struct{}
upstream *libnmdc.HubConnection upstream *libnmdc.HubConnection
motd string motd string
} }
@ -33,6 +34,7 @@ func NewServer(name string, upstream libnmdc.HubAddress) *Server {
Address: upstream, Address: upstream,
Self: *self, Self: *self,
}, },
upstreamCloser: make(chan struct{}, 1),
channel: Channel{ channel: Channel{
clientMap: make(map[string]*Client), clientMap: make(map[string]*Client),
modeMap: make(map[string]*ClientMode), modeMap: make(map[string]*ClientMode),
@ -60,6 +62,9 @@ func (s *Server) RunClient(conn net.Conn) {
if err != nil { if err != nil {
if err == io.EOF { if err == io.EOF {
s.client.disconnect() s.client.disconnect()
if s.client != nil && s.client.registered {
s.upstreamCloser <- struct{}{}
}
return // FIXME cleanup return // FIXME cleanup
} }
continue continue
@ -98,7 +103,8 @@ func (s *Server) ProtocolReadLoop_NMDC(closeChan chan struct{}) {
for { for {
select { select {
case <-closeChan: case <-closeChan:
// Need some way of deliberately shutting down a libnmdc connection... // Abandon the upstream connection
s.upstream.Disconnect()
return return
case hubEvent := <-s.upstream.OnEvent: case hubEvent := <-s.upstream.OnEvent: