Fix syscall packet read waiter

This commit is contained in:
世界 2024-03-25 01:46:48 +08:00
parent 04152ea672
commit 5bfc326913
No known key found for this signature in database
GPG key ID: CD109927C34A63C4

View file

@ -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
} }