mirror of https://bitbucket.org/ausocean/av.git
revid: multiSender is no longer a struct, but rather a type derived from a []loadSender
This commit is contained in:
parent
f9c5e1cfa7
commit
9b3a1d0ae7
|
@ -212,7 +212,7 @@ func (r *Revid) reset(config Config) error {
|
|||
// encoder to revid's encoder slice, and give this encoder the mtsSenders
|
||||
// as a destination.
|
||||
if len(mtsSenders) != 0 {
|
||||
ms := newMultiSender(mtsSenders)
|
||||
ms := multiSender(mtsSenders)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -224,7 +224,7 @@ func (r *Revid) reset(config Config) error {
|
|||
// encoder to revid's encoder slice, and give this encoder the flvSenders
|
||||
// as a destination.
|
||||
if len(flvSenders) != 0 {
|
||||
ms := newMultiSender(flvSenders)
|
||||
ms := multiSender(flvSenders)
|
||||
e, err := flv.NewEncoder(ms, true, true, int(r.config.FrameRate))
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
@ -229,7 +229,7 @@ func TestResetEncoderSenderSetup(t *testing.T) {
|
|||
|
||||
// Now check that this encoder has correct number of destinations (senders).
|
||||
ms := e.GetDst()
|
||||
senders := ms.(*multiSender).senders
|
||||
senders := []loadSender(ms.(multiSender))
|
||||
got = len(senders)
|
||||
want = len(test.encoders[idx].destinations)
|
||||
if got != want {
|
||||
|
|
|
@ -52,38 +52,23 @@ type Sender interface {
|
|||
send(d []byte) error
|
||||
}
|
||||
|
||||
// multiSender allows for the sending through multi loadSenders using a single
|
||||
// call to multiSender.Write.
|
||||
type multiSender struct {
|
||||
senders []loadSender
|
||||
}
|
||||
// multiSender implements io.Writer. It provides the capacity to send to multiple
|
||||
// senders from a single Write call.
|
||||
type multiSender []loadSender
|
||||
|
||||
// newMultiSender returns a pointer to a new multiSender. active is a function
|
||||
// to indicate the state of the multiSenders owner i.e. whether it is running
|
||||
// or not.
|
||||
func newMultiSender(senders []loadSender) *multiSender {
|
||||
s := &multiSender{
|
||||
senders: senders,
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
// Write implements io.Writer. The written slice will be sent to each loadSender
|
||||
// in multiSender.senders as long as s.active() is true. If a send fails, and
|
||||
// s.retry is true, the send will be tried again.
|
||||
func (s *multiSender) Write(d []byte) (int, error) {
|
||||
for _, sender := range s.senders {
|
||||
// Write implements io.Writer. This will call load (with the passed slice), send
|
||||
// and release on all senders of multiSender.
|
||||
func (s multiSender) Write(d []byte) (int, error) {
|
||||
for _, sender := range s {
|
||||
sender.load(d)
|
||||
err := sender.send()
|
||||
if err != nil {
|
||||
sender.handleSendFail(err)
|
||||
}
|
||||
}
|
||||
|
||||
for _, sender := range s.senders {
|
||||
for _, sender := range s {
|
||||
sender.release()
|
||||
}
|
||||
|
||||
return len(d), nil
|
||||
}
|
||||
|
||||
|
|
|
@ -321,7 +321,7 @@ func TestMultiSenderWrite(t *testing.T) {
|
|||
newDummyLoadSender(false, false),
|
||||
newDummyLoadSender(false, false),
|
||||
}
|
||||
ms := newMultiSender(senders)
|
||||
ms := multiSender(senders)
|
||||
|
||||
// Perform some multiSender writes.
|
||||
const noOfWrites = 5
|
||||
|
@ -331,7 +331,7 @@ func TestMultiSenderWrite(t *testing.T) {
|
|||
|
||||
// Check that the senders got the data correctly from the writes.
|
||||
for i := byte(0); i < noOfWrites; i++ {
|
||||
for j, dest := range ms.senders {
|
||||
for j, dest := range []loadSender(ms) {
|
||||
got := dest.(*dummyLoadSender).buf[i][0]
|
||||
if got != i {
|
||||
t.Errorf("Did not get expected result for sender: %v. \nGot: %v\nWant: %v\n", j, got, i)
|
||||
|
@ -349,7 +349,7 @@ func TestMultiSenderFailNoRetry(t *testing.T) {
|
|||
newDummyLoadSender(false, false),
|
||||
}
|
||||
|
||||
ms := newMultiSender(senders)
|
||||
ms := multiSender(senders)
|
||||
|
||||
// We will perform two writes. We expect the second write not to be complete,
|
||||
// i.e. the senders should not send anything on this write.
|
||||
|
@ -357,7 +357,7 @@ func TestMultiSenderFailNoRetry(t *testing.T) {
|
|||
|
||||
// Make second sender fail a send.
|
||||
const failedSenderIdx = 1
|
||||
failedSender := ms.senders[failedSenderIdx].(*dummyLoadSender)
|
||||
failedSender := []loadSender(ms)[failedSenderIdx].(*dummyLoadSender)
|
||||
failedSender.failOnSend = true
|
||||
ms.Write([]byte{0x01})
|
||||
|
||||
|
@ -371,7 +371,7 @@ func TestMultiSenderFailNoRetry(t *testing.T) {
|
|||
ms.Write([]byte{0x02})
|
||||
|
||||
// Check number of slices sent for each sender and also check data.
|
||||
for i, sender := range ms.senders {
|
||||
for i, sender := range []loadSender(ms) {
|
||||
// First check number of slices sent for each sender.
|
||||
wantLen := 3
|
||||
if i == failedSenderIdx {
|
||||
|
|
Loading…
Reference in New Issue