mirror of https://bitbucket.org/ausocean/av.git
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:
parent
a43ef56618
commit
6b994d0dba
|
@ -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
|
// Client is an RTCP Client that will handle receiving SenderReports from a server
|
||||||
// and sending out ReceiverReports.
|
// and sending out ReceiverReports.
|
||||||
type Client struct {
|
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.
|
cAddr *net.UDPAddr // Address of client.
|
||||||
sAddr *net.UDPAddr // Address of RTSP server.
|
sAddr *net.UDPAddr // Address of RTSP server.
|
||||||
|
@ -81,7 +81,7 @@ func NewClient(clientAddress, serverAddress, name string, sendInterval time.Dura
|
||||||
|
|
||||||
c := &Client{
|
c := &Client{
|
||||||
name: name,
|
name: name,
|
||||||
ErrChan: make(chan error, 2),
|
err: make(chan error),
|
||||||
quitSend: make(chan struct{}),
|
quitSend: make(chan struct{}),
|
||||||
quitRecv: make(chan struct{}),
|
quitRecv: make(chan struct{}),
|
||||||
interval: sendInterval,
|
interval: sendInterval,
|
||||||
|
@ -127,6 +127,11 @@ func (c *Client) Stop() {
|
||||||
c.wg.Wait()
|
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.
|
// recv reads from the UDP connection and parses SenderReports.
|
||||||
func (c *Client) recv() {
|
func (c *Client) recv() {
|
||||||
defer c.wg.Done()
|
defer c.wg.Done()
|
||||||
|
@ -139,7 +144,7 @@ func (c *Client) recv() {
|
||||||
default:
|
default:
|
||||||
n, _, err := c.conn.ReadFromUDP(buf)
|
n, _, err := c.conn.ReadFromUDP(buf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.ErrChan <- err
|
c.err <- err
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
c.log(logger.Debug, pkg+"sender report received", "report", buf[:n])
|
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")
|
c.log(logger.Debug, pkg+"sending receiver report")
|
||||||
_, err := c.conn.Write(c.formPayload(&report, &description))
|
_, err := c.conn.Write(c.formPayload(&report, &description))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.ErrChan <- err
|
c.err <- err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -228,7 +233,7 @@ func (c *Client) parse(buf []byte) {
|
||||||
c.markReceivedTime()
|
c.markReceivedTime()
|
||||||
t, err := Timestamp(buf)
|
t, err := Timestamp(buf)
|
||||||
if err != nil {
|
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)
|
c.setSenderTs(t)
|
||||||
}
|
}
|
||||||
|
|
|
@ -163,7 +163,7 @@ func TestReceiveAndSend(t *testing.T) {
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case err := <-c.ErrChan:
|
case err := <-c.Err():
|
||||||
const errConnClosed = "use of closed network connection"
|
const errConnClosed = "use of closed network connection"
|
||||||
if !strings.Contains(err.Error(), errConnClosed) {
|
if !strings.Contains(err.Error(), errConnClosed) {
|
||||||
t.Fatalf("error received from client error chan: %v\n", err)
|
t.Fatalf("error received from client error chan: %v\n", err)
|
||||||
|
|
Loading…
Reference in New Issue