diff --git a/revid/revid.go b/revid/revid.go index 67da8237..600d46c5 100644 --- a/revid/revid.go +++ b/revid/revid.go @@ -109,7 +109,7 @@ type Revid struct { // to the target destination. buffer *buffer - // destination is the target endpoint. + // encoder holds the required encoders, which then write to destinations. encoder []stream.Encoder // bitrate hold the last send bitrate calculation result. @@ -123,11 +123,12 @@ type Revid struct { err chan error } -// buffer implements io.Writer and handles the writing of data to a -// ring buffer used in tests. +// buffer is a wrapper for a ring.Buffer and provides function to write and +// flush in one Write call. type buffer ring.Buffer -// Write implements the io.Writer interface. +// Write implements the io.Writer interface. It will write to the underlying +// ring.Buffer and then flush to indicate a complete ring.Buffer write. func (b *buffer) Write(d []byte) (int, error) { r := (*ring.Buffer)(b) n, err := r.Write(d) @@ -177,7 +178,6 @@ func (r *Revid) reset(config Config) error { } r.config = config - // Creat ringbuffer. r.buffer = (*buffer)(ring.NewBuffer(ringBufferSize, ringBufferElementSize, writeTimeout)) r.encoder = make([]stream.Encoder, 0, 2) diff --git a/revid/senders.go b/revid/senders.go index f2bb0e4d..34662ccf 100644 --- a/revid/senders.go +++ b/revid/senders.go @@ -51,15 +51,22 @@ 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 { owner *Revid senders []loadSender } +// newMultiSender returns a pointer to a new multiSender. func newMultiSender(owner *Revid, senders []loadSender) *multiSender { return &multiSender{owner: owner, senders: senders} } +// Write implements io.Writer. The written slice will be sent to each loadSender +// in multiSender.senders. If s.owner.config.SendRetry is true then on failed +// sends we notify the current sender to take any required actions and then try +// the send again. func (s *multiSender) Write(d []byte) (int, error) { for i, sender := range s.senders { sender.load(d) @@ -115,6 +122,7 @@ type loadSender interface { // close cleans up after use of the loadSender. close() error + // handleSendFail performs any actions necessary in response to a failed send. handleSendFail(err error) }