1
0
Fork 0
forked from External/ergo

destroy clients on socket close with quit

This commit is contained in:
Jeremy Latt 2014-02-13 09:47:10 -08:00
parent 7a2c9db503
commit c327042c94
2 changed files with 18 additions and 10 deletions

View file

@ -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() {