Put read lock in Connected() (10->9).

This commit is contained in:
Alex Bramley 2013-09-30 13:55:55 +01:00
parent 648864c1d4
commit 637cdb573f
2 changed files with 4 additions and 2 deletions

View File

@ -16,7 +16,7 @@ import (
// An IRC connection is represented by this struct. // An IRC connection is represented by this struct.
type Conn struct { type Conn struct {
// For preventing races on (dis)connect. // For preventing races on (dis)connect.
mu sync.Mutex mu sync.RWMutex
// Contains parameters that people can tweak to change client behaviour. // Contains parameters that people can tweak to change client behaviour.
cfg *Config cfg *Config
@ -134,6 +134,8 @@ func Client(cfg *Config) *Conn {
} }
func (conn *Conn) Connected() bool { func (conn *Conn) Connected() bool {
conn.mu.RLock()
defer conn.mu.RUnlock()
return conn.connected return conn.connected
} }

View File

@ -65,7 +65,7 @@ func TestEOF(t *testing.T) {
<-time.After(time.Millisecond) <-time.After(time.Millisecond)
// Verify that the connection no longer thinks it's connected // Verify that the connection no longer thinks it's connected
if c.connected { if c.Connected() {
t.Errorf("Conn still thinks it's connected to the server.") t.Errorf("Conn still thinks it's connected to the server.")
} }