3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-22 20:09:41 +01:00

do idle in the server goroutine instead of the timeout goroutine

This commit is contained in:
Jeremy Latt 2014-02-18 11:22:56 -08:00
parent 4f106e7d3e
commit 2bc1b952a0
2 changed files with 11 additions and 13 deletions

View File

@ -79,26 +79,24 @@ func (client *Client) Touch() {
}
if client.idleTimer == nil {
client.idleTimer = time.AfterFunc(IDLE_TIMEOUT, client.Idle)
client.idleTimer = time.AfterFunc(IDLE_TIMEOUT, client.connectionIdle)
} else {
client.idleTimer.Reset(IDLE_TIMEOUT)
}
}
type ClientIdle struct {
BaseCommand
}
func (client *Client) Idle() {
client.Reply(RplPing(client.server, client))
if client.quitTimer == nil {
client.quitTimer = time.AfterFunc(QUIT_TIMEOUT, client.connectionTimeout)
} else {
client.quitTimer.Reset(QUIT_TIMEOUT)
}
}
cmd := &ClientIdle{}
cmd.SetClient(client)
client.server.commands <- cmd
func (client *Client) connectionIdle() {
client.server.idle <- client
}
func (client *Client) connectionTimeout() {

View File

@ -19,6 +19,7 @@ type Server struct {
commands chan Command
conns chan net.Conn
ctime time.Time
idle chan *Client
motdFile string
name string
operators map[string]string
@ -33,6 +34,7 @@ func NewServer(config *Config) *Server {
commands: make(chan Command),
conns: make(chan net.Conn),
ctime: time.Now(),
idle: make(chan *Client),
motdFile: config.MOTD,
name: config.Name,
operators: make(map[string]string),
@ -60,6 +62,9 @@ func (server *Server) ReceiveCommands() {
case client := <-server.toDestroy:
client.Destroy()
case client := <-server.idle:
client.Idle()
case cmd := <-server.commands:
client := cmd.Client()
if DEBUG_SERVER {
@ -650,11 +655,6 @@ func (msg *ListCommand) HandleServer(server *Server) {
client.Reply(RplListEnd(server))
}
func (msg *ClientIdle) HandleServer(server *Server) {
client := msg.Client()
client.Reply(RplPing(server, client))
}
func (msg *NamesCommand) HandleServer(server *Server) {
client := msg.Client()
if len(server.channels) == 0 {