mirror of
https://github.com/fosrl/newt.git
synced 2026-02-07 21:46:39 +00:00
Dont block waiting for a rebind signal
This commit is contained in:
@@ -10,7 +10,6 @@ import (
|
|||||||
"runtime"
|
"runtime"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/fosrl/newt/logger"
|
"github.com/fosrl/newt/logger"
|
||||||
"golang.org/x/net/ipv4"
|
"golang.org/x/net/ipv4"
|
||||||
@@ -656,17 +655,11 @@ func (b *SharedBind) receiveIPv4Batch(pc *ipv4.PacketConn, bufs [][]byte, sizes
|
|||||||
|
|
||||||
// receiveIPv4Simple uses simple ReadFromUDP for non-Linux platforms
|
// receiveIPv4Simple uses simple ReadFromUDP for non-Linux platforms
|
||||||
func (b *SharedBind) receiveIPv4Simple(conn *net.UDPConn, bufs [][]byte, sizes []int, eps []wgConn.Endpoint) (int, error) {
|
func (b *SharedBind) receiveIPv4Simple(conn *net.UDPConn, bufs [][]byte, sizes []int, eps []wgConn.Endpoint) (int, error) {
|
||||||
// Set a read deadline so we can periodically check for rebind state
|
// No read deadline - we rely on socket close to unblock during rebind.
|
||||||
// This prevents blocking forever on a socket that's about to be closed
|
// The caller (makeReceiveSocket) handles rebind state when errors occur.
|
||||||
conn.SetReadDeadline(time.Now().Add(1 * time.Second))
|
|
||||||
for {
|
for {
|
||||||
n, addr, err := conn.ReadFromUDP(bufs[0])
|
n, addr, err := conn.ReadFromUDP(bufs[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Check if this is a timeout - if so, just return the error
|
|
||||||
// so the caller can check rebind state and retry
|
|
||||||
if netErr, ok := err.(net.Error); ok && netErr.Timeout() {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user