mirror of
https://github.com/octoleo/syncthing.git
synced 2025-02-06 22:08:52 +00:00
Correct success/error handling for multicast/broadcast sends
This commit is contained in:
parent
3b81d4b8a5
commit
5ecb8bdd8a
@ -124,12 +124,14 @@ func (w *broadcastWriter) Serve() {
|
||||
l.Debugln("addresses:", dsts)
|
||||
}
|
||||
|
||||
success := 0
|
||||
for _, ip := range dsts {
|
||||
dst := &net.UDPAddr{IP: ip, Port: w.port}
|
||||
|
||||
w.conn.SetWriteDeadline(time.Now().Add(time.Second))
|
||||
_, err := w.conn.WriteTo(bs, dst)
|
||||
w.conn.SetWriteDeadline(time.Time{})
|
||||
|
||||
if err, ok := err.(net.Error); ok && err.Timeout() {
|
||||
// Write timeouts should not happen. We treat it as a fatal
|
||||
// error on the socket.
|
||||
@ -138,23 +140,34 @@ func (w *broadcastWriter) Serve() {
|
||||
}
|
||||
w.setError(err)
|
||||
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.
|
||||
if debug {
|
||||
l.Debugln(err)
|
||||
}
|
||||
continue
|
||||
} else if err != nil {
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
// Some other error that we don't expect. Bail and retry.
|
||||
if debug {
|
||||
l.Debugln(err)
|
||||
}
|
||||
w.setError(err)
|
||||
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
|
||||
}
|
||||
|
||||
var success int
|
||||
|
||||
success := 0
|
||||
for _, intf := range intfs {
|
||||
wcm.IfIndex = intf.Index
|
||||
pconn.SetWriteDeadline(time.Now().Add(time.Second))
|
||||
_, err = pconn.WriteTo(bs, wcm, gaddr)
|
||||
pconn.SetWriteDeadline(time.Time{})
|
||||
if err != nil && debug {
|
||||
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++
|
||||
|
||||
if err != nil {
|
||||
if debug {
|
||||
l.Debugln(err, "on write to", gaddr, intf.Name)
|
||||
}
|
||||
w.setError(err)
|
||||
continue
|
||||
}
|
||||
|
||||
if debug {
|
||||
l.Debugf("sent %d bytes to %v on %s", len(bs), gaddr, intf.Name)
|
||||
}
|
||||
|
||||
success++
|
||||
}
|
||||
|
||||
if success > 0 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user