3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-14 16:09:32 +01:00

don't close channels unless necessary

This commit is contained in:
Jeremy Latt 2014-02-14 08:57:17 -08:00
parent 9600be82a3
commit 72a90d5544
2 changed files with 24 additions and 21 deletions

View File

@ -55,27 +55,16 @@ func (channel *Channel) Destroy() {
return return
} }
close(channel.replies)
channel.replies = nil
close(channel.commands)
channel.commands = nil
channel.server.channels.Remove(channel)
channel.destroyed = true channel.destroyed = true
channel.members = make(ClientSet)
channel.server.channels.Remove(channel)
} }
func (channel *Channel) Command(command ChannelCommand) { func (channel *Channel) Command(command ChannelCommand) {
if channel.commands == nil {
return
}
channel.commands <- command channel.commands <- command
} }
func (channel *Channel) Reply(replies ...Reply) { func (channel *Channel) Reply(replies ...Reply) {
if channel.replies == nil {
return
}
for _, reply := range replies { for _, reply := range replies {
channel.replies <- reply channel.replies <- reply
} }
@ -83,6 +72,13 @@ func (channel *Channel) Reply(replies ...Reply) {
func (channel *Channel) receiveCommands(commands <-chan ChannelCommand) { func (channel *Channel) receiveCommands(commands <-chan ChannelCommand) {
for command := range commands { for command := range commands {
if channel.destroyed {
if DEBUG_CHANNEL {
log.Printf("%s → %s %s dropped", command.Source(), channel, command)
}
continue
}
if DEBUG_CHANNEL { if DEBUG_CHANNEL {
log.Printf("%s → %s %s", command.Source(), channel, command) 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) { func (channel *Channel) receiveReplies(replies <-chan Reply) {
for reply := range replies { for reply := range replies {
if channel.destroyed {
if DEBUG_CHANNEL {
log.Printf("%s ← %s %s dropped", channel, reply.Source(), reply)
}
continue
}
if DEBUG_CHANNEL { if DEBUG_CHANNEL {
log.Printf("%s ← %s %s", channel, reply.Source(), reply) log.Printf("%s ← %s %s", channel, reply.Source(), reply)
} }

View File

@ -126,6 +126,13 @@ func (c *Client) readCommands() {
func (client *Client) writeReplies() { func (client *Client) writeReplies() {
for reply := range client.replies { for reply := range client.replies {
if client.IsDestroyed() {
if DEBUG_CLIENT {
log.Printf("%s ← %s dropped", client, reply)
}
continue
}
if DEBUG_CLIENT { if DEBUG_CLIENT {
log.Printf("%s ← %s", client, reply) log.Printf("%s ← %s", client, reply)
} }
@ -154,11 +161,6 @@ func (client *Client) Destroy() {
client.mutex.Lock() client.mutex.Lock()
client.destroyed = true client.destroyed = true
if client.replies != nil {
close(client.replies)
client.replies = nil
}
client.socket.Close() client.socket.Close()
if client.idleTimer != nil { if client.idleTimer != nil {
@ -169,9 +171,7 @@ func (client *Client) Destroy() {
client.quitTimer.Stop() client.quitTimer.Stop()
} }
// clear channel list client.channels = make(ChannelSet) // clear channel list
client.channels = make(ChannelSet)
client.server.clients.Remove(client) client.server.clients.Remove(client)
client.mutex.Unlock() client.mutex.Unlock()