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