tty: retry on temporary read errors

This commit is contained in:
Kovid Goyal 2024-01-15 20:08:52 +05:30
parent 61a89a14b6
commit 0fcb055246
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C

View file

@ -285,8 +285,19 @@ func (self *Term) ReadWithTimeout(b []byte, d time.Duration) (n int, err error)
}
}
func (self *Term) Read(b []byte) (int, error) {
return self.os_file.Read(b)
func is_temporary_read_error(err error) bool {
return errors.Is(err, unix.EINTR) || errors.Is(err, unix.EAGAIN) || errors.Is(err, unix.EWOULDBLOCK)
}
func (self *Term) Read(b []byte) (n int, err error) {
for {
n, err = self.os_file.Read(b)
// On macOS we get EAGAIN if another thread is writing to the tty at the same time
if err != nil && is_temporary_read_error(err) && n <= 0 {
continue
}
return
}
}
func (self *Term) Write(b []byte) (int, error) {