Correct success/error handling for multicast/broadcast sends
This commit is contained in:
@@ -124,12 +124,14 @@ func (w *broadcastWriter) Serve() {
|
|||||||
l.Debugln("addresses:", dsts)
|
l.Debugln("addresses:", dsts)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
success := 0
|
||||||
for _, ip := range dsts {
|
for _, ip := range dsts {
|
||||||
dst := &net.UDPAddr{IP: ip, Port: w.port}
|
dst := &net.UDPAddr{IP: ip, Port: w.port}
|
||||||
|
|
||||||
w.conn.SetWriteDeadline(time.Now().Add(time.Second))
|
w.conn.SetWriteDeadline(time.Now().Add(time.Second))
|
||||||
_, err := w.conn.WriteTo(bs, dst)
|
_, err := w.conn.WriteTo(bs, dst)
|
||||||
w.conn.SetWriteDeadline(time.Time{})
|
w.conn.SetWriteDeadline(time.Time{})
|
||||||
|
|
||||||
if err, ok := err.(net.Error); ok && err.Timeout() {
|
if err, ok := err.(net.Error); ok && err.Timeout() {
|
||||||
// Write timeouts should not happen. We treat it as a fatal
|
// Write timeouts should not happen. We treat it as a fatal
|
||||||
// error on the socket.
|
// error on the socket.
|
||||||
@@ -138,23 +140,34 @@ func (w *broadcastWriter) Serve() {
|
|||||||
}
|
}
|
||||||
w.setError(err)
|
w.setError(err)
|
||||||
return
|
return
|
||||||
} else if err, ok := err.(net.Error); ok && err.Temporary() {
|
}
|
||||||
|
|
||||||
|
if err, ok := err.(net.Error); ok && err.Temporary() {
|
||||||
// A transient error. Lets hope for better luck in the future.
|
// A transient error. Lets hope for better luck in the future.
|
||||||
if debug {
|
if debug {
|
||||||
l.Debugln(err)
|
l.Debugln(err)
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
} else if err != nil {
|
}
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
// Some other error that we don't expect. Bail and retry.
|
// Some other error that we don't expect. Bail and retry.
|
||||||
if debug {
|
if debug {
|
||||||
l.Debugln(err)
|
l.Debugln(err)
|
||||||
}
|
}
|
||||||
w.setError(err)
|
w.setError(err)
|
||||||
return
|
return
|
||||||
} else if debug {
|
|
||||||
l.Debugf("sent %d bytes to %s", len(bs), dst)
|
|
||||||
w.setError(nil)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if debug {
|
||||||
|
l.Debugf("sent %d bytes to %s", len(bs), dst)
|
||||||
|
}
|
||||||
|
|
||||||
|
success++
|
||||||
|
}
|
||||||
|
|
||||||
|
if success > 0 {
|
||||||
|
w.setError(nil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -124,19 +124,26 @@ func (w *multicastWriter) Serve() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var success int
|
success := 0
|
||||||
|
|
||||||
for _, intf := range intfs {
|
for _, intf := range intfs {
|
||||||
wcm.IfIndex = intf.Index
|
wcm.IfIndex = intf.Index
|
||||||
pconn.SetWriteDeadline(time.Now().Add(time.Second))
|
pconn.SetWriteDeadline(time.Now().Add(time.Second))
|
||||||
_, err = pconn.WriteTo(bs, wcm, gaddr)
|
_, err = pconn.WriteTo(bs, wcm, gaddr)
|
||||||
pconn.SetWriteDeadline(time.Time{})
|
pconn.SetWriteDeadline(time.Time{})
|
||||||
if err != nil && debug {
|
|
||||||
|
if err != nil {
|
||||||
|
if debug {
|
||||||
l.Debugln(err, "on write to", gaddr, intf.Name)
|
l.Debugln(err, "on write to", gaddr, intf.Name)
|
||||||
} else if debug {
|
|
||||||
l.Debugf("sent %d bytes to %v on %s", len(bs), gaddr, intf.Name)
|
|
||||||
success++
|
|
||||||
}
|
}
|
||||||
|
w.setError(err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if debug {
|
||||||
|
l.Debugf("sent %d bytes to %v on %s", len(bs), gaddr, intf.Name)
|
||||||
|
}
|
||||||
|
|
||||||
|
success++
|
||||||
}
|
}
|
||||||
|
|
||||||
if success > 0 {
|
if success > 0 {
|
||||||
|
|||||||
Reference in New Issue
Block a user