protocol/rtcp: made Client error channel unexported

Renamed Client ErrChan field to err, i.e. made unexported. Wrote Err() accessor that allows user to only read from error channel.
This commit is contained in:
Saxon 2019-04-23 13:26:56 +09:30
parent a43ef56618
commit 6b994d0dba
2 changed files with 11 additions and 6 deletions

View File

@ -54,7 +54,7 @@ type log func(lvl int8, msg string, args ...interface{})
// Client is an RTCP Client that will handle receiving SenderReports from a server
// and sending out ReceiverReports.
type Client struct {
ErrChan chan error // Client will send any errors through this chan.
err chan error // Client will send any errors through this chan. Can be accessed by Err().
cAddr *net.UDPAddr // Address of client.
sAddr *net.UDPAddr // Address of RTSP server.
@ -81,7 +81,7 @@ func NewClient(clientAddress, serverAddress, name string, sendInterval time.Dura
c := &Client{
name: name,
ErrChan: make(chan error, 2),
err: make(chan error),
quitSend: make(chan struct{}),
quitRecv: make(chan struct{}),
interval: sendInterval,
@ -127,6 +127,11 @@ func (c *Client) Stop() {
c.wg.Wait()
}
// Err provides read access to the Client err channel.
func (c *Client) Err() <-chan error {
return c.err
}
// recv reads from the UDP connection and parses SenderReports.
func (c *Client) recv() {
defer c.wg.Done()
@ -139,7 +144,7 @@ func (c *Client) recv() {
default:
n, _, err := c.conn.ReadFromUDP(buf)
if err != nil {
c.ErrChan <- err
c.err <- err
continue
}
c.log(logger.Debug, pkg+"sender report received", "report", buf[:n])
@ -204,7 +209,7 @@ func (c *Client) send() {
c.log(logger.Debug, pkg+"sending receiver report")
_, err := c.conn.Write(c.formPayload(&report, &description))
if err != nil {
c.ErrChan <- err
c.err <- err
}
}
}
@ -228,7 +233,7 @@ func (c *Client) parse(buf []byte) {
c.markReceivedTime()
t, err := Timestamp(buf)
if err != nil {
c.ErrChan <- errors.New(fmt.Sprintf("could not get timestamp from sender report, failed with error: %v", err))
c.err <- errors.New(fmt.Sprintf("could not get timestamp from sender report, failed with error: %v", err))
}
c.setSenderTs(t)
}

View File

@ -163,7 +163,7 @@ func TestReceiveAndSend(t *testing.T) {
go func() {
for {
select {
case err := <-c.ErrChan:
case err := <-c.Err():
const errConnClosed = "use of closed network connection"
if !strings.Contains(err.Error(), errConnClosed) {
t.Fatalf("error received from client error chan: %v\n", err)