From c327042c949cd614002f3f036557a60e0bae2893 Mon Sep 17 00:00:00 2001 From: Jeremy Latt Date: Thu, 13 Feb 2014 09:47:10 -0800 Subject: [PATCH] destroy clients on socket close with quit --- irc/client.go | 16 ++++++++++++---- irc/server.go | 12 ++++++------ 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/irc/client.go b/irc/client.go index f41bf27d..3b6a955b 100644 --- a/irc/client.go +++ b/irc/client.go @@ -65,14 +65,14 @@ func (client *Client) Touch() { func (client *Client) Idle() { if client.quitTimer == nil { - client.quitTimer = time.AfterFunc(QUIT_TIMEOUT, client.Quit) + client.quitTimer = time.AfterFunc(QUIT_TIMEOUT, client.ConnectionTimeout) } else { client.quitTimer.Reset(QUIT_TIMEOUT) } client.Reply(RplPing(client.server, client)) } -func (client *Client) Quit() { +func (client *Client) ConnectionTimeout() { msg := &QuitCommand{ message: "connection timeout", } @@ -80,6 +80,14 @@ func (client *Client) Quit() { client.server.commands <- msg } +func (client *Client) ConnectionClosed() { + msg := &QuitCommand{ + message: "connection closed", + } + msg.SetClient(client) + client.server.commands <- msg +} + func (c *Client) readConn() { for { line, err := c.recv.ReadString('\n') @@ -113,7 +121,7 @@ func (c *Client) readConn() { m.SetClient(c) c.server.commands <- m } - c.Destroy() + c.ConnectionClosed() } func (client *Client) maybeLogWriteError(err error) bool { @@ -150,7 +158,7 @@ func (client *Client) writeConn(replies <-chan Reply) { } } } - client.Destroy() + client.ConnectionClosed() } func (client *Client) Destroy() { diff --git a/irc/server.go b/irc/server.go index 5cb8fd37..3d347d4d 100644 --- a/irc/server.go +++ b/irc/server.go @@ -298,7 +298,7 @@ func (m *JoinCommand) HandleServer(s *Server) { } for name := range m.channels { - s.GetOrMakeChannel(name).commands <- m + s.GetOrMakeChannel(name).Command(m) } } @@ -311,7 +311,7 @@ func (m *PartCommand) HandleServer(s *Server) { continue } - channel.commands <- m + channel.Command(m) } } @@ -322,7 +322,7 @@ func (m *TopicCommand) HandleServer(s *Server) { return } - channel.commands <- m + channel.Command(m) } func (m *PrivMsgCommand) HandleServer(s *Server) { @@ -333,7 +333,7 @@ func (m *PrivMsgCommand) HandleServer(s *Server) { return } - channel.commands <- m + channel.Command(m) return } @@ -391,7 +391,7 @@ func (msg *ChannelModeCommand) HandleServer(server *Server) { client.Reply(ErrNoSuchChannel(server, msg.channel)) return } - channel.commands <- msg + channel.Command(msg) } func whoChannel(client *Client, server *Server, channel *Channel) { @@ -483,7 +483,7 @@ func (msg *NoticeCommand) HandleServer(server *Server) { return } - channel.commands <- msg + channel.Command(msg) return }