4
0
mirror of https://github.com/cwinfo/matterbridge.git synced 2025-07-11 18:56:28 +00:00

Update vendor

This commit is contained in:
Wim
2017-03-25 20:45:10 +01:00
parent be15cc8a36
commit 07fd825349
250 changed files with 125316 additions and 703 deletions

View File

@ -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)
}
}
}