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.
|
||||
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.
|
||||
quitSend chan struct{} // Channel used to communicate quit signal to send routine.
|
||||
quitRecv chan struct{} // Channel used to communicate quit signal to recv routine.
|
||||
quit chan struct{} // Channel used to communicate quit signal to send and recv routines.
|
||||
log log // Used to log any messages.
|
||||
|
||||
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{
|
||||
name: name,
|
||||
err: make(chan error),
|
||||
quitSend: make(chan struct{}),
|
||||
quitRecv: make(chan struct{}),
|
||||
quit: make(chan struct{}),
|
||||
interval: sendInterval,
|
||||
sourceSSRC: rtpSSRC,
|
||||
log: l,
|
||||
|
@ -121,8 +119,7 @@ func (c *Client) Start() {
|
|||
// UDP connection. It will wait until both routines have returned.
|
||||
func (c *Client) Stop() {
|
||||
c.log(logger.Debug, pkg+"Client is stopping")
|
||||
close(c.quitSend)
|
||||
close(c.quitRecv)
|
||||
close(c.quit)
|
||||
c.conn.Close()
|
||||
c.wg.Wait()
|
||||
}
|
||||
|
@ -140,7 +137,7 @@ func (c *Client) recv() {
|
|||
buf := make([]byte, 4096)
|
||||
for {
|
||||
select {
|
||||
case <-c.quitRecv:
|
||||
case <-c.quit:
|
||||
return
|
||||
default:
|
||||
n, _, err := c.conn.ReadFromUDP(buf)
|
||||
|
@ -160,7 +157,7 @@ func (c *Client) send() {
|
|||
c.log(logger.Debug, pkg+"Client is sending")
|
||||
for {
|
||||
select {
|
||||
case <-c.quitSend:
|
||||
case <-c.quit:
|
||||
return
|
||||
default:
|
||||
time.Sleep(c.interval)
|
||||
|
|
Loading…
Reference in New Issue