Added timeout to read failure in rdpControlConn to avoid spinning on error.
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"net/netip"
|
"net/netip"
|
||||||
|
"time"
|
||||||
|
|
||||||
"vppn/peer/control"
|
"vppn/peer/control"
|
||||||
)
|
)
|
||||||
@@ -32,11 +33,14 @@ func (c *udpControlConn) SendPing(dst netip.AddrPort, ping control.Ping, buf []b
|
|||||||
// run reads incoming ping packets and forwards them to ch until ctx is done.
|
// run reads incoming ping packets and forwards them to ch until ctx is done.
|
||||||
// Call this in a goroutine before starting the App event loop.
|
// Call this in a goroutine before starting the App event loop.
|
||||||
func (c *udpControlConn) run(ch chan<- PingEvent) {
|
func (c *udpControlConn) run(ch chan<- PingEvent) {
|
||||||
|
const errorTimeout = 8 * time.Second
|
||||||
|
|
||||||
var buf [control.Size]byte
|
var buf [control.Size]byte
|
||||||
for {
|
for {
|
||||||
n, src, err := c.conn.ReadFromUDP(buf[:])
|
n, src, err := c.conn.ReadFromUDP(buf[:])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("control read: %v", err)
|
log.Printf("control read: %v", err)
|
||||||
|
time.Sleep(errorTimeout)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -175,7 +175,7 @@ func nlAttr(attrType uint16, data []byte) []byte {
|
|||||||
|
|
||||||
func ioctlSetAddr(name string, ip net.IP, prefixLen int) error {
|
func ioctlSetAddr(name string, ip net.IP, prefixLen int) error {
|
||||||
if ip.To4() == nil {
|
if ip.To4() == nil {
|
||||||
return errors.New("attempted to set nil IP on interface")
|
return errors.New("attempted to set non-IPv4 address on interface")
|
||||||
}
|
}
|
||||||
|
|
||||||
fd, err := unix.Socket(unix.AF_INET, unix.SOCK_DGRAM, unix.IPPROTO_IP)
|
fd, err := unix.Socket(unix.AF_INET, unix.SOCK_DGRAM, unix.IPPROTO_IP)
|
||||||
|
|||||||
Reference in New Issue
Block a user