mirror of https://github.com/fluffle/goirc
Don't hold conn.mu during REGISTER. Fixes #94.
This commit is contained in:
parent
64ad58533d
commit
329a62d7d9
|
@ -295,6 +295,18 @@ func (conn *Conn) ConnectTo(host string, pass ...string) error {
|
||||||
// handler for the CONNECTED event is used to perform any initial client work
|
// handler for the CONNECTED event is used to perform any initial client work
|
||||||
// like joining channels and sending messages.
|
// like joining channels and sending messages.
|
||||||
func (conn *Conn) Connect() error {
|
func (conn *Conn) Connect() error {
|
||||||
|
// We don't want to hold conn.mu while firing the REGISTER event,
|
||||||
|
// and it's much easier and less error prone to defer the unlock,
|
||||||
|
// so the connect mechanics have been delegated to internalConnect.
|
||||||
|
err := conn.internalConnect()
|
||||||
|
if err == nil {
|
||||||
|
conn.dispatch(&Line{Cmd: REGISTER, Time: time.Now()})
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// internalConnect handles the work of actually connecting to the server.
|
||||||
|
func (conn *Conn) internalConnect() error {
|
||||||
conn.mu.Lock()
|
conn.mu.Lock()
|
||||||
defer conn.mu.Unlock()
|
defer conn.mu.Unlock()
|
||||||
conn.initialise()
|
conn.initialise()
|
||||||
|
@ -350,7 +362,6 @@ func (conn *Conn) Connect() error {
|
||||||
|
|
||||||
conn.postConnect(true)
|
conn.postConnect(true)
|
||||||
conn.connected = true
|
conn.connected = true
|
||||||
conn.dispatch(&Line{Cmd: REGISTER, Time: time.Now()})
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue