mirror of
https://github.com/jech/galene.git
synced 2024-11-22 16:45:58 +01:00
Ensure actions happen in order.
This commit is contained in:
parent
9ba1037208
commit
260597d595
1 changed files with 13 additions and 16 deletions
|
@ -62,7 +62,7 @@ type webClient struct {
|
||||||
done chan struct{}
|
done chan struct{}
|
||||||
writeCh chan interface{}
|
writeCh chan interface{}
|
||||||
writerDone chan struct{}
|
writerDone chan struct{}
|
||||||
actionCh chan interface{}
|
actionCh chan struct{}
|
||||||
|
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
down map[string]*rtpDownConnection
|
down map[string]*rtpDownConnection
|
||||||
|
@ -739,7 +739,7 @@ func StartClient(conn *websocket.Conn) (err error) {
|
||||||
|
|
||||||
c := &webClient{
|
c := &webClient{
|
||||||
id: m.Id,
|
id: m.Id,
|
||||||
actionCh: make(chan interface{}, 10),
|
actionCh: make(chan struct{}, 1),
|
||||||
done: make(chan struct{}),
|
done: make(chan struct{}),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -810,13 +810,6 @@ func clientLoop(c *webClient, ws *websocket.Conn) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
for {
|
for {
|
||||||
c.mu.Lock()
|
|
||||||
actions := c.actions
|
|
||||||
c.actions = nil
|
|
||||||
c.mu.Unlock()
|
|
||||||
for _, a := range actions {
|
|
||||||
handleAction(c, a)
|
|
||||||
}
|
|
||||||
select {
|
select {
|
||||||
case m, ok := <-read:
|
case m, ok := <-read:
|
||||||
if !ok {
|
if !ok {
|
||||||
|
@ -832,10 +825,13 @@ func clientLoop(c *webClient, ws *websocket.Conn) error {
|
||||||
case error:
|
case error:
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
case a := <-c.actionCh:
|
case <-c.actionCh:
|
||||||
err := handleAction(c, a)
|
c.mu.Lock()
|
||||||
if err != nil {
|
actions := c.actions
|
||||||
return err
|
c.actions = nil
|
||||||
|
c.mu.Unlock()
|
||||||
|
for _, a := range actions {
|
||||||
|
handleAction(c, a)
|
||||||
}
|
}
|
||||||
case <-ticker.C:
|
case <-ticker.C:
|
||||||
if time.Since(readTime) > 75*time.Second {
|
if time.Since(readTime) > 75*time.Second {
|
||||||
|
@ -1551,16 +1547,17 @@ var ErrClientDead = errors.New("client is dead")
|
||||||
func (c *webClient) action(a interface{}) error {
|
func (c *webClient) action(a interface{}) error {
|
||||||
c.mu.Lock()
|
c.mu.Lock()
|
||||||
defer c.mu.Unlock()
|
defer c.mu.Unlock()
|
||||||
if len(c.actions) == 0 {
|
empty := len(c.actions) == 0
|
||||||
|
c.actions = append(c.actions, a)
|
||||||
|
if empty {
|
||||||
select {
|
select {
|
||||||
case c.actionCh <- a:
|
case c.actionCh <- struct{}{}:
|
||||||
return nil
|
return nil
|
||||||
case <-c.done:
|
case <-c.done:
|
||||||
return ErrClientDead
|
return ErrClientDead
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
c.actions = append(c.actions, a)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue