Commit 3b505a89 authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Factor out handling actions.

parent fa625c69
......@@ -827,6 +827,30 @@ func clientLoop(c *webClient, ws *websocket.Conn) error {
return m
}
case a := <-c.actionCh:
err := handleAction(c, a)
if err != nil {
return err
}
case <-ticker.C:
if time.Since(readTime) > 75*time.Second {
return errors.New("client is dead")
}
// Some reverse proxies timeout connexions at 60
// seconds, make sure we generate some activity
// after 55s at most.
if time.Since(readTime) > 45*time.Second {
err := c.write(clientMessage{
Type: "ping",
})
if err != nil {
return err
}
}
}
}
}
func handleAction(c *webClient, a interface{}) error {
switch a := a.(type) {
case pushConnAction:
g := c.group
......@@ -854,7 +878,7 @@ func clientLoop(c *webClient, ws *websocket.Conn) error {
c, a.replace, "",
)
}
continue
return nil
}
down, _, err := addDownConn(c, a.conn)
......@@ -880,7 +904,6 @@ func clientLoop(c *webClient, ws *websocket.Conn) error {
err)
closeDownConn(c, down.id,
"negotiation failed")
continue
}
case pushConnsAction:
g := c.group
......@@ -975,23 +998,7 @@ func clientLoop(c *webClient, ws *websocket.Conn) error {
log.Printf("unexpected action %T", a)
return errors.New("unexpected action")
}
case <-ticker.C:
if time.Since(readTime) > 75*time.Second {
return errors.New("client is dead")
}
// Some reverse proxies timeout connexions at 60
// seconds, make sure we generate some activity
// after 55s at most.
if time.Since(readTime) > 45*time.Second {
err := c.write(clientMessage{
Type: "ping",
})
if err != nil {
return err
}
}
}
}
return nil
}
func failUpConnection(c *webClient, id string, message string) error {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment