revid: simplified multiSender Write method

This commit is contained in:
Saxon 2019-03-12 15:13:24 +10:30
parent 1c75867ba5
commit 30ea5d74f6
1 changed files with 13 additions and 17 deletions

View File

@ -57,6 +57,7 @@ type Sender interface {
type multiSender struct {
owner *Revid
senders []loadSender
retry bool
}
// newMultiSender returns a pointer to a new multiSender.
@ -69,28 +70,23 @@ func newMultiSender(owner *Revid, senders []loadSender) *multiSender {
// 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 {
for _, sender := range s.senders {
sender.load(d)
err := sender.send()
if err != nil {
s.owner.config.Logger.Log(logger.Warning, "send failed", "output", i, "error", err)
s.handleFail(sender, err)
if s.owner.config.SendRetry {
for {
if !s.owner.IsRunning() {
sender.release()
return 0, err
}
err = sender.send()
if err == nil {
break
}
s.handleFail(sender, err)
}
for s.owner.IsRunning() {
err := sender.send()
if err != nil {
s.handleFail(sender, err)
}
if err == nil || !s.retry {
break
}
}
}
for _, sender := range s.senders {
sender.release()
}
return len(d), nil
}