From 637cdb573f40cd817cf1cd6102a35dc0491e90d1 Mon Sep 17 00:00:00 2001 From: Alex Bramley Date: Mon, 30 Sep 2013 13:55:55 +0100 Subject: [PATCH] Put read lock in Connected() (10->9). --- client/connection.go | 4 +++- client/connection_test.go | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/client/connection.go b/client/connection.go index 3943324..596aeae 100644 --- a/client/connection.go +++ b/client/connection.go @@ -16,7 +16,7 @@ import ( // An IRC connection is represented by this struct. type Conn struct { // For preventing races on (dis)connect. - mu sync.Mutex + mu sync.RWMutex // Contains parameters that people can tweak to change client behaviour. cfg *Config @@ -134,6 +134,8 @@ func Client(cfg *Config) *Conn { } func (conn *Conn) Connected() bool { + conn.mu.RLock() + defer conn.mu.RUnlock() return conn.connected } diff --git a/client/connection_test.go b/client/connection_test.go index 32bfac5..bdb0cde 100644 --- a/client/connection_test.go +++ b/client/connection_test.go @@ -65,7 +65,7 @@ func TestEOF(t *testing.T) { <-time.After(time.Millisecond) // 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.") }