mirror of
https://github.com/SagerNet/sing.git
synced 2025-04-04 20:37:40 +03:00
Fix syscall packet read waiter
This commit is contained in:
parent
04152ea672
commit
5bfc326913
1 changed files with 13 additions and 14 deletions
|
@ -47,6 +47,7 @@ func (w *syscallReadWaiter) InitializeReadWaiter(options N.ReadWaitOptions) (nee
|
||||||
} else {
|
} else {
|
||||||
buffer.Release()
|
buffer.Release()
|
||||||
}
|
}
|
||||||
|
//goland:noinspection GoDirectComparisonOfErrors
|
||||||
if w.readErr == syscall.EAGAIN {
|
if w.readErr == syscall.EAGAIN {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -105,23 +106,21 @@ func (w *syscallPacketReadWaiter) InitializeReadWaiter(options N.ReadWaitOptions
|
||||||
var readN int
|
var readN int
|
||||||
var from syscall.Sockaddr
|
var from syscall.Sockaddr
|
||||||
readN, _, _, from, w.readErr = syscall.Recvmsg(int(fd), buffer.FreeBytes(), nil, 0)
|
readN, _, _, from, w.readErr = syscall.Recvmsg(int(fd), buffer.FreeBytes(), nil, 0)
|
||||||
|
//goland:noinspection GoDirectComparisonOfErrors
|
||||||
|
if w.readErr != nil {
|
||||||
|
buffer.Release()
|
||||||
|
return w.readErr != syscall.EAGAIN
|
||||||
|
}
|
||||||
if readN > 0 {
|
if readN > 0 {
|
||||||
buffer.Truncate(readN)
|
buffer.Truncate(readN)
|
||||||
w.options.PostReturn(buffer)
|
|
||||||
w.buffer = buffer
|
|
||||||
} else {
|
|
||||||
buffer.Release()
|
|
||||||
}
|
}
|
||||||
if w.readErr == syscall.EAGAIN {
|
w.options.PostReturn(buffer)
|
||||||
return false
|
w.buffer = buffer
|
||||||
}
|
switch fromAddr := from.(type) {
|
||||||
if from != nil {
|
case *syscall.SockaddrInet4:
|
||||||
switch fromAddr := from.(type) {
|
w.readFrom = M.SocksaddrFrom(netip.AddrFrom4(fromAddr.Addr), uint16(fromAddr.Port))
|
||||||
case *syscall.SockaddrInet4:
|
case *syscall.SockaddrInet6:
|
||||||
w.readFrom = M.SocksaddrFrom(netip.AddrFrom4(fromAddr.Addr), uint16(fromAddr.Port))
|
w.readFrom = M.SocksaddrFrom(netip.AddrFrom16(fromAddr.Addr), uint16(fromAddr.Port)).Unwrap()
|
||||||
case *syscall.SockaddrInet6:
|
|
||||||
w.readFrom = M.SocksaddrFrom(netip.AddrFrom16(fromAddr.Addr), uint16(fromAddr.Port)).Unwrap()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue