mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-10 22:19:31 +01:00
don't close channels unless necessary
This commit is contained in:
parent
9600be82a3
commit
72a90d5544
@ -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)
|
||||
}
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user