mirror of
https://github.com/kovidgoyal/kitty.git
synced 2026-05-13 08:26:56 +00:00
tty: retry on temporary read errors
This commit is contained in:
parent
61a89a14b6
commit
0fcb055246
1 changed files with 13 additions and 2 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue