mdlayher / raw

Package raw enables reading and writing data at the device driver level for a network interface. MIT Licensed.
MIT License
425 stars 71 forks source link

raw: return poller error from Recvfrom on i/o timeout #70

Closed lmb closed 2 years ago

lmb commented 2 years ago

sysSocket.Recvfrom currently returns the error from the syscall instead of the error from RawConn.Read. This is problematic when using SetReadDeadline.

cerr := s.rc.Read(func(fd uintptr) bool {
    n, addr, err = unix.Recvfrom(int(fd), p, flags) // err == EAGAIN
    return err != unix.EAGAIN                       // return false
})
// Since we return false we enter the poller, Read blocks until
// deadline elapses. cerr is an i/o timeout now.
if err != nil {         // err is still EAGAIN from call to read
    return n, addr, err // return EAGAIN instead of i/o timeout
}

The fix is to prefer returning cerr over err.