mirror of https://bitbucket.org/ausocean/av.git
protocol/rtp: Client.ErrChan => Client.err and wrote accessor function Client.Err() to access this chan as only receive
This commit is contained in:
parent
a0c324a813
commit
49a401681d
|
@ -61,7 +61,7 @@ type Client struct {
|
|||
done chan struct{} // Used to terminate the recv routine.
|
||||
ring *ring.Buffer // Processed data from RTP packets will be stored here.
|
||||
op func([]byte) ([]byte, error) // The operation to perform on received RTP packets before storing.
|
||||
ErrChan chan error // Errors encountered during recv will be sent to this chan.
|
||||
err chan error // Errors encountered during recv will be sent to this chan.
|
||||
rt time.Duration // Read timeout used when reading from the ringbuffer.
|
||||
log
|
||||
}
|
||||
|
@ -81,7 +81,7 @@ func NewClient(addr string, op func([]byte) ([]byte, error), l log, rt time.Dura
|
|||
ring: ring.NewBuffer(ringBufferSize, ringBufferElementSize, 0),
|
||||
op: op,
|
||||
log: l,
|
||||
ErrChan: make(chan error),
|
||||
err: make(chan error),
|
||||
rt: rt,
|
||||
}
|
||||
|
||||
|
@ -114,6 +114,10 @@ func (c *Client) Stop() {
|
|||
c.wg.Wait()
|
||||
}
|
||||
|
||||
func (c *Client) Err() <-chan error {
|
||||
return c.err
|
||||
}
|
||||
|
||||
// recv will read RTP packets from the UDP connection, perform the operation
|
||||
// on them given at creation of the Client and then store the result in the
|
||||
// ringBuffer for Reading.
|
||||
|
@ -129,7 +133,7 @@ func (c *Client) recv() {
|
|||
c.log(logger.Debug, pkg+"waiting for packet")
|
||||
n, _, err := c.conn.ReadFromUDP(buf)
|
||||
if err != nil {
|
||||
c.ErrChan <- err
|
||||
c.err <- err
|
||||
continue
|
||||
}
|
||||
c.log(logger.Debug, pkg+"packet received", "packet", buf[:n])
|
||||
|
@ -141,7 +145,7 @@ func (c *Client) recv() {
|
|||
default:
|
||||
_buf, err = c.op(buf[:n])
|
||||
if err != nil {
|
||||
c.ErrChan <- err
|
||||
c.err <- err
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
@ -149,7 +153,7 @@ func (c *Client) recv() {
|
|||
_, err = c.ring.Write(_buf)
|
||||
c.ring.Flush()
|
||||
if err != nil {
|
||||
c.ErrChan <- err
|
||||
c.err <- err
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
|
|
@ -86,7 +86,7 @@ func TestReceive(t *testing.T) {
|
|||
// Log any errors from client.
|
||||
go func() {
|
||||
for {
|
||||
err := <-c.ErrChan
|
||||
err := <-c.Err()
|
||||
t.Logf("unexpected error from client: %v", err)
|
||||
}
|
||||
}()
|
||||
|
|
Loading…
Reference in New Issue