mirror of https://bitbucket.org/ausocean/av.git
protocol/rtcp/client.go: only using one quit chan for both send and recv routines.
This commit is contained in:
parent
76612ea8df
commit
ea309b295e
|
@ -66,8 +66,7 @@ type Client struct {
|
||||||
buf [receiverBufSize]byte // Buf used to store the receiver report and source descriptions.
|
buf [receiverBufSize]byte // Buf used to store the receiver report and source descriptions.
|
||||||
conn *net.UDPConn // The UDP connection used for receiving and sending RTSP packets.
|
conn *net.UDPConn // The UDP connection used for receiving and sending RTSP packets.
|
||||||
wg sync.WaitGroup // This is used to wait for send and recv routines to stop when Client is stopped.
|
wg sync.WaitGroup // This is used to wait for send and recv routines to stop when Client is stopped.
|
||||||
quitSend chan struct{} // Channel used to communicate quit signal to send routine.
|
quit chan struct{} // Channel used to communicate quit signal to send and recv routines.
|
||||||
quitRecv chan struct{} // Channel used to communicate quit signal to recv routine.
|
|
||||||
log log // Used to log any messages.
|
log log // Used to log any messages.
|
||||||
|
|
||||||
err chan error // Client will send any errors through this chan. Can be accessed by Err().
|
err chan error // Client will send any errors through this chan. Can be accessed by Err().
|
||||||
|
@ -82,8 +81,7 @@ func NewClient(clientAddress, serverAddress, name string, sendInterval time.Dura
|
||||||
c := &Client{
|
c := &Client{
|
||||||
name: name,
|
name: name,
|
||||||
err: make(chan error),
|
err: make(chan error),
|
||||||
quitSend: make(chan struct{}),
|
quit: make(chan struct{}),
|
||||||
quitRecv: make(chan struct{}),
|
|
||||||
interval: sendInterval,
|
interval: sendInterval,
|
||||||
sourceSSRC: rtpSSRC,
|
sourceSSRC: rtpSSRC,
|
||||||
log: l,
|
log: l,
|
||||||
|
@ -121,8 +119,7 @@ func (c *Client) Start() {
|
||||||
// UDP connection. It will wait until both routines have returned.
|
// UDP connection. It will wait until both routines have returned.
|
||||||
func (c *Client) Stop() {
|
func (c *Client) Stop() {
|
||||||
c.log(logger.Debug, pkg+"Client is stopping")
|
c.log(logger.Debug, pkg+"Client is stopping")
|
||||||
close(c.quitSend)
|
close(c.quit)
|
||||||
close(c.quitRecv)
|
|
||||||
c.conn.Close()
|
c.conn.Close()
|
||||||
c.wg.Wait()
|
c.wg.Wait()
|
||||||
}
|
}
|
||||||
|
@ -140,7 +137,7 @@ func (c *Client) recv() {
|
||||||
buf := make([]byte, 4096)
|
buf := make([]byte, 4096)
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-c.quitRecv:
|
case <-c.quit:
|
||||||
return
|
return
|
||||||
default:
|
default:
|
||||||
n, _, err := c.conn.ReadFromUDP(buf)
|
n, _, err := c.conn.ReadFromUDP(buf)
|
||||||
|
@ -160,7 +157,7 @@ func (c *Client) send() {
|
||||||
c.log(logger.Debug, pkg+"Client is sending")
|
c.log(logger.Debug, pkg+"Client is sending")
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-c.quitSend:
|
case <-c.quit:
|
||||||
return
|
return
|
||||||
default:
|
default:
|
||||||
time.Sleep(c.interval)
|
time.Sleep(c.interval)
|
||||||
|
|
Loading…
Reference in New Issue