From 72a90d5544f972a15e420248d433f000402a6c9a Mon Sep 17 00:00:00 2001 From: Jeremy Latt Date: Fri, 14 Feb 2014 08:57:17 -0800 Subject: [PATCH] don't close channels unless necessary --- irc/channel.go | 29 ++++++++++++++++------------- irc/client.go | 16 ++++++++-------- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/irc/channel.go b/irc/channel.go index 7f2c455d..900d017a 100644 --- a/irc/channel.go +++ b/irc/channel.go @@ -55,27 +55,16 @@ func (channel *Channel) Destroy() { return } - close(channel.replies) - channel.replies = nil - close(channel.commands) - channel.commands = nil - - channel.server.channels.Remove(channel) - channel.destroyed = true + channel.members = make(ClientSet) + channel.server.channels.Remove(channel) } func (channel *Channel) Command(command ChannelCommand) { - if channel.commands == nil { - return - } channel.commands <- command } func (channel *Channel) Reply(replies ...Reply) { - if channel.replies == nil { - return - } for _, reply := range replies { channel.replies <- reply } @@ -83,6 +72,13 @@ func (channel *Channel) Reply(replies ...Reply) { func (channel *Channel) receiveCommands(commands <-chan ChannelCommand) { for command := range commands { + if channel.destroyed { + if DEBUG_CHANNEL { + log.Printf("%s → %s %s dropped", command.Source(), channel, command) + } + continue + } + if DEBUG_CHANNEL { log.Printf("%s → %s %s", command.Source(), channel, command) } @@ -92,6 +88,13 @@ func (channel *Channel) receiveCommands(commands <-chan ChannelCommand) { func (channel *Channel) receiveReplies(replies <-chan Reply) { for reply := range replies { + if channel.destroyed { + if DEBUG_CHANNEL { + log.Printf("%s ← %s %s dropped", channel, reply.Source(), reply) + } + continue + } + if DEBUG_CHANNEL { log.Printf("%s ← %s %s", channel, reply.Source(), reply) } diff --git a/irc/client.go b/irc/client.go index cf44a1f4..30cce792 100644 --- a/irc/client.go +++ b/irc/client.go @@ -126,6 +126,13 @@ func (c *Client) readCommands() { func (client *Client) writeReplies() { for reply := range client.replies { + if client.IsDestroyed() { + if DEBUG_CLIENT { + log.Printf("%s ← %s dropped", client, reply) + } + continue + } + if DEBUG_CLIENT { log.Printf("%s ← %s", client, reply) } @@ -154,11 +161,6 @@ func (client *Client) Destroy() { client.mutex.Lock() client.destroyed = true - if client.replies != nil { - close(client.replies) - client.replies = nil - } - client.socket.Close() if client.idleTimer != nil { @@ -169,9 +171,7 @@ func (client *Client) Destroy() { client.quitTimer.Stop() } - // clear channel list - client.channels = make(ChannelSet) - + client.channels = make(ChannelSet) // clear channel list client.server.clients.Remove(client) client.mutex.Unlock()