diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-05-24 15:29:16 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-05-24 15:36:29 +0200 |
commit | 2f2eca894744baef365aaa07554f56979159d988 (patch) | |
tree | 56ecc658ff124222643a13ed9bd75c3a703e726b /rwcancel/rwcancel.go | |
parent | 66f6ca3e4a435935c38b93c4441575e3b003137d (diff) |
Catch EINTR
Diffstat (limited to 'rwcancel/rwcancel.go')
-rw-r--r-- | rwcancel/rwcancel.go | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/rwcancel/rwcancel.go b/rwcancel/rwcancel.go index aac743a..e73c58a 100644 --- a/rwcancel/rwcancel.go +++ b/rwcancel/rwcancel.go @@ -40,15 +40,16 @@ func NewRWCancel(fd int) (*RWCancel, error) { return &rwcancel, nil } -/* https://golang.org/src/crypto/rand/eagain.go */ -func ErrorIsEAGAIN(err error) bool { +func RetryAfterError(err error) bool { if pe, ok := err.(*os.PathError); ok { - if errno, ok := pe.Err.(syscall.Errno); ok && errno == syscall.EAGAIN { + err = pe.Err + } + if errno, ok := err.(syscall.Errno); ok { + switch errno { + case syscall.EAGAIN, syscall.EINTR: return true } - } - if errno, ok := err.(syscall.Errno); ok && errno == syscall.EAGAIN { - return true + } return false } @@ -86,7 +87,7 @@ func (rw *RWCancel) ReadyWrite() bool { func (rw *RWCancel) Read(p []byte) (n int, err error) { for { n, err := unix.Read(rw.fd, p) - if err == nil || !ErrorIsEAGAIN(err) { + if err == nil || !RetryAfterError(err) { return n, err } if !rw.ReadyRead() { @@ -98,7 +99,7 @@ func (rw *RWCancel) Read(p []byte) (n int, err error) { func (rw *RWCancel) Write(p []byte) (n int, err error) { for { n, err := unix.Write(rw.fd, p) - if err == nil || !ErrorIsEAGAIN(err) { + if err == nil || !RetryAfterError(err) { return n, err } if !rw.ReadyWrite() { |