diff options
author | Wim <wim@42.be> | 2017-03-25 20:45:10 +0100 |
---|---|---|
committer | Wim <wim@42.be> | 2017-03-25 20:45:10 +0100 |
commit | 07fd825349e8b7e86f8afb3843cb8e2c2afc7c74 (patch) | |
tree | ea4b33872a5b925fa0ecd2b421f8f073ba22b2cc /vendor/github.com/gorilla/websocket/examples/chat/hub.go | |
parent | be15cc8a36ed3c207251f9b92815781f2fa8618d (diff) | |
download | matterbridge-msglm-07fd825349e8b7e86f8afb3843cb8e2c2afc7c74.tar.gz matterbridge-msglm-07fd825349e8b7e86f8afb3843cb8e2c2afc7c74.tar.bz2 matterbridge-msglm-07fd825349e8b7e86f8afb3843cb8e2c2afc7c74.zip |
Update vendor
Diffstat (limited to 'vendor/github.com/gorilla/websocket/examples/chat/hub.go')
-rw-r--r-- | vendor/github.com/gorilla/websocket/examples/chat/hub.go | 56 |
1 files changed, 29 insertions, 27 deletions
diff --git a/vendor/github.com/gorilla/websocket/examples/chat/hub.go b/vendor/github.com/gorilla/websocket/examples/chat/hub.go index 449ba753..7f07ea07 100644 --- a/vendor/github.com/gorilla/websocket/examples/chat/hub.go +++ b/vendor/github.com/gorilla/websocket/examples/chat/hub.go @@ -4,46 +4,48 @@ package main -// hub maintains the set of active connections and broadcasts messages to the -// connections. -type hub struct { - // Registered connections. - connections map[*connection]bool +// hub maintains the set of active clients and broadcasts messages to the +// clients. +type Hub struct { + // Registered clients. + clients map[*Client]bool - // Inbound messages from the connections. + // Inbound messages from the clients. broadcast chan []byte - // Register requests from the connections. - register chan *connection + // Register requests from the clients. + register chan *Client - // Unregister requests from connections. - unregister chan *connection + // Unregister requests from clients. + unregister chan *Client } -var h = hub{ - broadcast: make(chan []byte), - register: make(chan *connection), - unregister: make(chan *connection), - connections: make(map[*connection]bool), +func newHub() *Hub { + return &Hub{ + broadcast: make(chan []byte), + register: make(chan *Client), + unregister: make(chan *Client), + clients: make(map[*Client]bool), + } } -func (h *hub) run() { +func (h *Hub) run() { for { select { - case c := <-h.register: - h.connections[c] = true - case c := <-h.unregister: - if _, ok := h.connections[c]; ok { - delete(h.connections, c) - close(c.send) + case client := <-h.register: + h.clients[client] = true + case client := <-h.unregister: + if _, ok := h.clients[client]; ok { + delete(h.clients, client) + close(client.send) } - case m := <-h.broadcast: - for c := range h.connections { + case message := <-h.broadcast: + for client := range h.clients { select { - case c.send <- m: + case client.send <- message: default: - close(c.send) - delete(h.connections, c) + close(client.send) + delete(h.clients, client) } } } |