mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-10 22:19:31 +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
|
// command goroutine
|
||||||
//
|
//
|
||||||
|
|
||||||
func (client *Client) run() {
|
func (client *Client) send(command Command) {
|
||||||
for command := range client.commands {
|
command.SetClient(client)
|
||||||
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)
|
checkPass, ok := command.(checkPasswordCommand)
|
||||||
if ok {
|
if ok {
|
||||||
checkPass.LoadPassword(client.server)
|
checkPass.LoadPassword(client.server)
|
||||||
@ -75,8 +82,12 @@ func (client *Client) run() {
|
|||||||
checkPass.CheckPassword()
|
checkPass.CheckPassword()
|
||||||
}
|
}
|
||||||
|
|
||||||
client.server.commands <- command
|
client.send(command)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
client.send(&QuitCommand{
|
||||||
|
message: "connection closed",
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (client *Client) connectionTimeout() {
|
func (client *Client) connectionTimeout() {
|
||||||
@ -259,8 +270,8 @@ func (client *Client) Quit(message Text) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
client.Reply(RplError("connection closed"))
|
|
||||||
client.hasQuit = true
|
client.hasQuit = true
|
||||||
|
client.Reply(RplError("quit"))
|
||||||
client.server.whoWas.Append(client)
|
client.server.whoWas.Append(client)
|
||||||
friends := client.Friends()
|
friends := client.Friends()
|
||||||
friends.Remove(client)
|
friends.Remove(client)
|
||||||
|
@ -41,10 +41,6 @@ func (socket *Socket) Close() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (socket *Socket) readLines(commands chan<- Command) {
|
func (socket *Socket) readLines(commands chan<- Command) {
|
||||||
commands <- &ProxyCommand{
|
|
||||||
hostname: AddrLookupHostname(socket.conn.RemoteAddr()),
|
|
||||||
}
|
|
||||||
|
|
||||||
for {
|
for {
|
||||||
line, err := socket.reader.ReadString('\n')
|
line, err := socket.reader.ReadString('\n')
|
||||||
if socket.isError(err, R) {
|
if socket.isError(err, R) {
|
||||||
@ -64,9 +60,7 @@ func (socket *Socket) readLines(commands chan<- Command) {
|
|||||||
commands <- msg
|
commands <- msg
|
||||||
}
|
}
|
||||||
|
|
||||||
commands <- &QuitCommand{
|
close(commands)
|
||||||
message: "connection closed",
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (socket *Socket) Write(line string) (err error) {
|
func (socket *Socket) Write(line string) (err error) {
|
||||||
|
Loading…
Reference in New Issue
Block a user