sendhub sends the msg received from the send channel to the remote client
()
| 570 | |
| 571 | // sendhub sends the msg received from the send channel to the remote client |
| 572 | func (c *Client) sendHub() { |
| 573 | defer c.wg.Done() |
| 574 | |
| 575 | for { |
| 576 | select { |
| 577 | case msg := <-c.send: |
| 578 | c.LocalKite.Log.Debug("sending: %s", msg) |
| 579 | session := c.getSession() |
| 580 | if session == nil { |
| 581 | c.LocalKite.Log.Error("not connected") |
| 582 | continue |
| 583 | } |
| 584 | |
| 585 | err := session.Send(string(msg.p)) |
| 586 | if err != nil { |
| 587 | if msg.errC != nil { |
| 588 | msg.errC <- err |
| 589 | } |
| 590 | |
| 591 | if sockjsclient.IsSessionClosed(err) { |
| 592 | // The readloop may already be interrupted, thus the non-blocking send. |
| 593 | select { |
| 594 | case c.interrupt <- err: |
| 595 | default: |
| 596 | } |
| 597 | |
| 598 | c.LocalKite.Log.Error("error sending to %s: %s", session.ID(), err) |
| 599 | return |
| 600 | } |
| 601 | } |
| 602 | case <-c.closeChan: |
| 603 | c.LocalKite.Log.Debug("Send hub is closed") |
| 604 | return |
| 605 | } |
| 606 | } |
| 607 | } |
| 608 | |
| 609 | // OnConnect adds a callback which is called when client connects |
| 610 | // to a remote kite. |
no test coverage detected