Skip to content

Commit e680f85

Browse files
author
Lapp
committed
hub: added buffer size for the broadcasting channel, added closing of connection with the client in case of sending channel buffer overflow
1 parent 3106f23 commit e680f85

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Чат на вебсокетах
2-
[![Release](https://img.shields.io/badge/release-v1.0.0-blue)](https://github.com/Lapp-coder/go-pocket-sdk/releases)
2+
[![Release](https://img.shields.io/badge/release-v1.0.1-blue)](https://github.com/Lapp-coder/go-pocket-sdk/releases)
33

44
### Для запуска сервера используйте следующую команду
55
```make docker-build && docker run --name=chat -e CHAT_HOST=<host> -e CHAT_PORT=<port> -p <port>>:<port> --rm websocket-chat```

hub.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ type hub struct {
1111
func newHub() *hub {
1212
return &hub{
1313
connections: make(map[*connection]struct{}),
14-
broadcast: make(chan []byte),
14+
broadcast: make(chan []byte, 10000),
1515
register: make(chan *connection),
1616
unregister: make(chan *connection),
1717
}
@@ -30,7 +30,12 @@ func (h *hub) listen() {
3030
}
3131
case message := <-h.broadcast:
3232
for conn := range h.connections {
33-
conn.send <- message
33+
select {
34+
case conn.send <- message:
35+
default:
36+
delete(h.connections, conn)
37+
close(conn.send)
38+
}
3439
}
3540
}
3641
}

0 commit comments

Comments
 (0)