1
0
mirror of https://gitlab.crans.org/nounous/ghostream.git synced 2025-06-30 02:01:08 +02:00

Make client count independant of outputs

This commit is contained in:
Alexandre Iooss
2020-10-17 16:17:19 +02:00
parent 70798ce1df
commit f0990a630d
3 changed files with 24 additions and 16 deletions

View File

@ -62,18 +62,15 @@ func (s *Stream) Close() {
// Register a new output on a stream.
// If hidden in true, then do not count this client.
func (s *Stream) Register(output chan []byte, hidden bool) {
func (s *Stream) Register(output chan []byte) {
s.lock.Lock()
defer s.lock.Unlock()
s.outputs[output] = struct{}{}
if !hidden {
s.nbClients++
}
}
// Unregister removes an output.
// If hidden in true, then do not count this client.
func (s *Stream) Unregister(output chan []byte, hidden bool) {
func (s *Stream) Unregister(output chan []byte) {
s.lock.Lock()
defer s.lock.Unlock()
@ -82,13 +79,20 @@ func (s *Stream) Unregister(output chan []byte, hidden bool) {
if ok {
delete(s.outputs, output)
close(output)
if !hidden {
s.nbClients--
}
}
}
// Count number of clients
func (s *Stream) Count() int {
// ClientCount returns the number of clients
func (s *Stream) ClientCount() int {
return s.nbClients
}
// IncrementClientCount increments the number of clients
func (s *Stream) IncrementClientCount() {
s.nbClients++
}
// DecrementClientCount decrements the number of clients
func (s *Stream) DecrementClientCount() {
s.nbClients--
}