mirror of
https://github.com/SagerNet/sing-tun.git
synced 2025-04-03 03:47:39 +03:00
Fix darwin monitor
This commit is contained in:
parent
e8633c66d2
commit
8d285f70fb
2 changed files with 16 additions and 4 deletions
|
@ -170,6 +170,8 @@ func getDefaultInterfaceBySocket() (*net.Interface, error) {
|
|||
Port: 80,
|
||||
})
|
||||
result := make(chan netip.Addr, 1)
|
||||
done := make(chan struct{})
|
||||
defer close(done)
|
||||
go func() {
|
||||
for {
|
||||
sockname, sockErr := unix.Getsockname(socketFd)
|
||||
|
@ -182,8 +184,13 @@ func getDefaultInterfaceBySocket() (*net.Interface, error) {
|
|||
}
|
||||
addr := netip.AddrFrom4(sockaddr.Addr)
|
||||
if addr.IsUnspecified() {
|
||||
time.Sleep(time.Millisecond)
|
||||
continue
|
||||
select {
|
||||
case <-done:
|
||||
break
|
||||
default:
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
continue
|
||||
}
|
||||
}
|
||||
result <- addr
|
||||
break
|
||||
|
@ -193,7 +200,7 @@ func getDefaultInterfaceBySocket() (*net.Interface, error) {
|
|||
select {
|
||||
case selectedAddr = <-result:
|
||||
case <-time.After(time.Second):
|
||||
return nil, os.ErrDeadlineExceeded
|
||||
return nil, nil
|
||||
}
|
||||
interfaces, err := net.Interfaces()
|
||||
if err != nil {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue