Return error messages for some exposed methods, fix panic when connection is closed. Close #21.

This commit is contained in:
Ola Holmström
2017-02-10 23:12:27 +01:00
parent e39e1207dd
commit 3321ec3da7
4 changed files with 200 additions and 47 deletions
+7 -4
View File
@@ -38,8 +38,6 @@ loop:
if _, ok := h.sessions[s]; ok {
h.rwmutex.Lock()
delete(h.sessions, s)
s.conn.Close()
close(s.output)
h.rwmutex.Unlock()
}
case m := <-h.broadcast:
@@ -58,8 +56,7 @@ loop:
h.rwmutex.Lock()
for s := range h.sessions {
delete(h.sessions, s)
s.conn.Close()
close(s.output)
s.Close()
}
h.open = false
h.rwmutex.Unlock()
@@ -68,6 +65,12 @@ loop:
}
}
func (h *hub) closed() bool {
h.rwmutex.RLock()
defer h.rwmutex.RUnlock()
return !h.open
}
func (h *hub) len() int {
h.rwmutex.RLock()
defer h.rwmutex.RUnlock()