mirror of
https://github.com/ergochat/ergo.git
synced 2024-12-26 20:52:38 +01:00
stop leaking client goroutines; closes #34
This commit is contained in:
parent
c2e3bbe494
commit
d696f2313e
@ -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)
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user