mirror of https://github.com/fluffle/goirc
Use connected bool properly to ensure shutdown() can't be called twice.
This commit is contained in:
parent
291132cab5
commit
6634869fe6
|
@ -139,6 +139,7 @@ func (conn *Conn) Connect(host string, pass ...string) os.Error {
|
|||
bufio.NewReader(conn.sock),
|
||||
bufio.NewWriter(conn.sock))
|
||||
conn.sock.SetTimeout(conn.Timeout * 1e9)
|
||||
conn.connected = true
|
||||
go conn.send()
|
||||
go conn.recv()
|
||||
|
||||
|
@ -247,6 +248,9 @@ func (conn *Conn) rateLimit(chars int64) {
|
|||
}
|
||||
|
||||
func (conn *Conn) shutdown() {
|
||||
// Guard against double-call of shutdown() if we get an error in send()
|
||||
// as calling sock.Close() will cause recv() to recieve EOF in readstring()
|
||||
if conn.connected {
|
||||
conn.connected = false
|
||||
conn.sock.Close()
|
||||
conn.cSend <- true
|
||||
|
@ -256,6 +260,7 @@ func (conn *Conn) shutdown() {
|
|||
// do this here rather than after runLoop()'s for due to race
|
||||
conn.initialise()
|
||||
}
|
||||
}
|
||||
|
||||
// Dumps a load of information about the current state of the connection to a
|
||||
// string for debugging state tracking and other such things.
|
||||
|
|
|
@ -76,7 +76,6 @@ func (conn *Conn) h_PING(line *Line) {
|
|||
// Handler to trigger a "CONNECTED" event on receipt of numeric 001
|
||||
func (conn *Conn) h_001(line *Line) {
|
||||
// we're connected!
|
||||
conn.connected = true
|
||||
conn.dispatchEvent(&Line{Cmd: "CONNECTED"})
|
||||
// and we're being given our hostname (from the server's perspective)
|
||||
t := line.Args[len(line.Args)-1]
|
||||
|
@ -103,7 +102,7 @@ func (conn *Conn) h_433(line *Line) {
|
|||
// if this is happening before we're properly connected (i.e. the nick
|
||||
// we sent in the initial NICK command is in use) we will not receive
|
||||
// a NICK message to confirm our change of nick, so ReNick here...
|
||||
if !conn.connected && line.Args[1] == conn.Me.Nick {
|
||||
if line.Args[1] == conn.Me.Nick {
|
||||
conn.Me.ReNick(line.Args[1] + "_")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue