diff options
author | gVisor bot <gvisor-bot@google.com> | 2021-10-08 00:45:12 +0000 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2021-10-08 00:45:12 +0000 |
commit | 89e1ae16f75923312bf487fd96ab74ce0211df73 (patch) | |
tree | 8b1a7c1b20231f33ac76361d3634b70b4c89d8d2 /pkg/tcpip/link/rawfile/rawfile_unsafe.go | |
parent | fd0024109aac305a161145ce219f936a0b61a0de (diff) | |
parent | e44b100654ca639d11221e547384f699e461296d (diff) |
Merge release-20210927.0-50-ge44b10065 (automated)
Diffstat (limited to 'pkg/tcpip/link/rawfile/rawfile_unsafe.go')
-rw-r--r-- | pkg/tcpip/link/rawfile/rawfile_unsafe.go | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/pkg/tcpip/link/rawfile/rawfile_unsafe.go b/pkg/tcpip/link/rawfile/rawfile_unsafe.go index 87a0b9a62..e53789d92 100644 --- a/pkg/tcpip/link/rawfile/rawfile_unsafe.go +++ b/pkg/tcpip/link/rawfile/rawfile_unsafe.go @@ -152,10 +152,22 @@ type PollEvent struct { // no data is available, it will block in a poll() syscall until the file // descriptor becomes readable. func BlockingRead(fd int, b []byte) (int, tcpip.Error) { + n, err := BlockingReadUntranslated(fd, b) + if err != 0 { + return n, TranslateErrno(err) + } + return n, nil +} + +// BlockingReadUntranslated reads from a file descriptor that is set up as +// non-blocking. If no data is available, it will block in a poll() syscall +// until the file descriptor becomes readable. It returns the raw unix.Errno +// value returned by the underlying syscalls. +func BlockingReadUntranslated(fd int, b []byte) (int, unix.Errno) { for { n, _, e := unix.RawSyscall(unix.SYS_READ, uintptr(fd), uintptr(unsafe.Pointer(&b[0])), uintptr(len(b))) if e == 0 { - return int(n), nil + return int(n), 0 } event := PollEvent{ @@ -165,7 +177,7 @@ func BlockingRead(fd int, b []byte) (int, tcpip.Error) { _, e = BlockingPoll(&event, 1, nil) if e != 0 && e != unix.EINTR { - return 0, TranslateErrno(e) + return 0, e } } } |