3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-26 05:49:25 +01:00

stop leaking client goroutines; closes #34

This commit is contained in:
Jeremy Latt 2014-03-27 16:49:22 -07:00
parent c2e3bbe494
commit d696f2313e
2 changed files with 17 additions and 12 deletions

View File

@ -60,10 +60,17 @@ func NewClient(server *Server, conn net.Conn) *Client {
// command goroutine
//
func (client *Client) run() {
for command := range client.commands {
command.SetClient(client)
func (client *Client) send(command Command) {
command.SetClient(client)
client.server.commands <- command
}
func (client *Client) run() {
client.send(&ProxyCommand{
hostname: AddrLookupHostname(client.socket.conn.RemoteAddr()),
})
for command := range client.commands {
checkPass, ok := command.(checkPasswordCommand)
if ok {
checkPass.LoadPassword(client.server)
@ -75,8 +82,12 @@ func (client *Client) run() {
checkPass.CheckPassword()
}
client.server.commands <- command
client.send(command)
}
client.send(&QuitCommand{
message: "connection closed",
})
}
func (client *Client) connectionTimeout() {
@ -259,8 +270,8 @@ func (client *Client) Quit(message Text) {
return
}
client.Reply(RplError("connection closed"))
client.hasQuit = true
client.Reply(RplError("quit"))
client.server.whoWas.Append(client)
friends := client.Friends()
friends.Remove(client)

View File

@ -41,10 +41,6 @@ func (socket *Socket) Close() {
}
func (socket *Socket) readLines(commands chan<- Command) {
commands <- &ProxyCommand{
hostname: AddrLookupHostname(socket.conn.RemoteAddr()),
}
for {
line, err := socket.reader.ReadString('\n')
if socket.isError(err, R) {
@ -64,9 +60,7 @@ func (socket *Socket) readLines(commands chan<- Command) {
commands <- msg
}
commands <- &QuitCommand{
message: "connection closed",
}
close(commands)
}
func (socket *Socket) Write(line string) (err error) {