maybe fix networking hangs

This commit is contained in:
Jeremy Latt 2014-02-12 21:04:50 -08:00
parent 01fa48c73e
commit 415ccc7607
3 changed files with 23 additions and 24 deletions

View File

@ -7,6 +7,7 @@ import (
type Channel struct {
banList []UserMask
commands chan<- ChannelCommand
destroyed bool
key string
members ClientSet
name string
@ -46,23 +47,23 @@ func NewChannel(s *Server, name string) *Channel {
return channel
}
func (channel *Channel) Destroy() error {
if channel.replies == nil {
return ErrAlreadyDestroyed
}
close(channel.replies)
channel.replies = nil
return nil
func (channel *Channel) Destroy() {
if channel.destroyed {
return
}
func (channel *Channel) Reply(replies ...Reply) error {
if channel.replies == nil {
return ErrAlreadyDestroyed
close(channel.replies)
close(channel.commands)
channel.server.channels.Remove(channel)
channel.destroyed = true
}
func (channel *Channel) Reply(replies ...Reply) {
for _, reply := range replies {
channel.replies <- reply
}
return nil
}
func (channel *Channel) receiveCommands(commands <-chan ChannelCommand) {
@ -183,7 +184,7 @@ func (m *PartCommand) HandleChannel(channel *Channel) {
// TODO persistent channels
if channel.IsEmpty() {
channel.server.channels.Remove(channel)
channel.Destroy()
}
}

View File

@ -15,6 +15,7 @@ type Client struct {
awayMessage string
channels ChannelSet
conn net.Conn
destroyed bool
hostname string
idleTimer *time.Timer
invisible bool
@ -106,6 +107,7 @@ func (c *Client) readConn() {
m.SetClient(c)
c.server.commands <- m
}
c.Destroy()
}
func (client *Client) maybeLogWriteError(err error) bool {
@ -138,18 +140,18 @@ func (client *Client) writeConn(replies <-chan Reply) {
}
}
}
client.Destroy()
}
func (client *Client) Destroy() error {
if client.replies == nil {
return ErrAlreadyDestroyed
func (client *Client) Destroy() {
if client.destroyed {
return
}
close(client.replies)
client.replies = nil
client.conn.Close()
close(client.replies)
if client.idleTimer != nil {
client.idleTimer.Stop()
}
@ -161,17 +163,13 @@ func (client *Client) Destroy() error {
// clear channel list
client.channels = make(ChannelSet)
return nil
client.destroyed = true
}
func (client *Client) Reply(replies ...Reply) error {
if client.replies == nil {
return ErrAlreadyDestroyed
}
func (client *Client) Reply(replies ...Reply) {
for _, reply := range replies {
client.replies <- reply
}
return nil
}
func (client *Client) HasNick() bool {

View File

@ -108,7 +108,7 @@ type Identifier interface {
}
type Replier interface {
Reply(...Reply) error
Reply(...Reply)
}
type Reply interface {