mirror of
https://github.com/strukturag/nextcloud-spreed-signaling
synced 2024-05-04 14:53:10 +02:00
Support closing clients from message processor.
This commit is contained in:
parent
618e7b085e
commit
fe95626f3b
25
client.go
25
client.go
|
@ -100,9 +100,10 @@ type Client struct {
|
||||||
|
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
|
|
||||||
closeChan chan bool
|
closeChan chan bool
|
||||||
messagesDone sync.WaitGroup
|
messagesDone sync.WaitGroup
|
||||||
messageChan chan *bytes.Buffer
|
messageChan chan *bytes.Buffer
|
||||||
|
messageProcessing uint32
|
||||||
|
|
||||||
OnLookupCountry func(*Client) string
|
OnLookupCountry func(*Client) string
|
||||||
OnClosed func(*Client)
|
OnClosed func(*Client)
|
||||||
|
@ -183,6 +184,16 @@ func (c *Client) Close() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if atomic.LoadUint32(&c.messageProcessing) == 1 {
|
||||||
|
// Defer closing
|
||||||
|
atomic.StoreUint32(&c.closed, 2)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
c.doClose()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Client) doClose() {
|
||||||
c.closeChan <- true
|
c.closeChan <- true
|
||||||
c.messagesDone.Wait()
|
c.messagesDone.Wait()
|
||||||
|
|
||||||
|
@ -304,7 +315,7 @@ func (c *Client) ReadPump() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stop processing if the client was closed.
|
// Stop processing if the client was closed.
|
||||||
if atomic.LoadUint32(&c.closed) == 1 {
|
if atomic.LoadUint32(&c.closed) != 0 {
|
||||||
bufferPool.Put(decodeBuffer)
|
bufferPool.Put(decodeBuffer)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -321,10 +332,16 @@ func (c *Client) processMessages() {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
atomic.StoreUint32(&c.messageProcessing, 1)
|
||||||
c.OnMessageReceived(c, buffer.Bytes())
|
c.OnMessageReceived(c, buffer.Bytes())
|
||||||
|
atomic.StoreUint32(&c.messageProcessing, 0)
|
||||||
c.messagesDone.Done()
|
c.messagesDone.Done()
|
||||||
bufferPool.Put(buffer)
|
bufferPool.Put(buffer)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if atomic.LoadUint32(&c.closed) == 2 {
|
||||||
|
c.doClose()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) writeInternal(message json.Marshaler) bool {
|
func (c *Client) writeInternal(message json.Marshaler) bool {
|
||||||
|
|
Loading…
Reference in a new issue