forked from External/ergo
destroy clients on socket close with quit
This commit is contained in:
parent
7a2c9db503
commit
c327042c94
2 changed files with 18 additions and 10 deletions
|
|
@ -65,14 +65,14 @@ func (client *Client) Touch() {
|
||||||
|
|
||||||
func (client *Client) Idle() {
|
func (client *Client) Idle() {
|
||||||
if client.quitTimer == nil {
|
if client.quitTimer == nil {
|
||||||
client.quitTimer = time.AfterFunc(QUIT_TIMEOUT, client.Quit)
|
client.quitTimer = time.AfterFunc(QUIT_TIMEOUT, client.ConnectionTimeout)
|
||||||
} else {
|
} else {
|
||||||
client.quitTimer.Reset(QUIT_TIMEOUT)
|
client.quitTimer.Reset(QUIT_TIMEOUT)
|
||||||
}
|
}
|
||||||
client.Reply(RplPing(client.server, client))
|
client.Reply(RplPing(client.server, client))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (client *Client) Quit() {
|
func (client *Client) ConnectionTimeout() {
|
||||||
msg := &QuitCommand{
|
msg := &QuitCommand{
|
||||||
message: "connection timeout",
|
message: "connection timeout",
|
||||||
}
|
}
|
||||||
|
|
@ -80,6 +80,14 @@ func (client *Client) Quit() {
|
||||||
client.server.commands <- msg
|
client.server.commands <- msg
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (client *Client) ConnectionClosed() {
|
||||||
|
msg := &QuitCommand{
|
||||||
|
message: "connection closed",
|
||||||
|
}
|
||||||
|
msg.SetClient(client)
|
||||||
|
client.server.commands <- msg
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Client) readConn() {
|
func (c *Client) readConn() {
|
||||||
for {
|
for {
|
||||||
line, err := c.recv.ReadString('\n')
|
line, err := c.recv.ReadString('\n')
|
||||||
|
|
@ -113,7 +121,7 @@ func (c *Client) readConn() {
|
||||||
m.SetClient(c)
|
m.SetClient(c)
|
||||||
c.server.commands <- m
|
c.server.commands <- m
|
||||||
}
|
}
|
||||||
c.Destroy()
|
c.ConnectionClosed()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (client *Client) maybeLogWriteError(err error) bool {
|
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() {
|
func (client *Client) Destroy() {
|
||||||
|
|
|
||||||
|
|
@ -298,7 +298,7 @@ func (m *JoinCommand) HandleServer(s *Server) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for name := range m.channels {
|
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
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
channel.commands <- m
|
channel.Command(m)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -322,7 +322,7 @@ func (m *TopicCommand) HandleServer(s *Server) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
channel.commands <- m
|
channel.Command(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *PrivMsgCommand) HandleServer(s *Server) {
|
func (m *PrivMsgCommand) HandleServer(s *Server) {
|
||||||
|
|
@ -333,7 +333,7 @@ func (m *PrivMsgCommand) HandleServer(s *Server) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
channel.commands <- m
|
channel.Command(m)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -391,7 +391,7 @@ func (msg *ChannelModeCommand) HandleServer(server *Server) {
|
||||||
client.Reply(ErrNoSuchChannel(server, msg.channel))
|
client.Reply(ErrNoSuchChannel(server, msg.channel))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
channel.commands <- msg
|
channel.Command(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
func whoChannel(client *Client, server *Server, channel *Channel) {
|
func whoChannel(client *Client, server *Server, channel *Channel) {
|
||||||
|
|
@ -483,7 +483,7 @@ func (msg *NoticeCommand) HandleServer(server *Server) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
channel.commands <- msg
|
channel.Command(msg)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue