3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-10 22:19:31 +01:00

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

View File

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

View File

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