fix reading from tty

This commit is contained in:
Kovid Goyal 2022-08-22 15:18:12 +05:30
parent 3a7d26a3ef
commit eec8f04e93
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 7 additions and 7 deletions

View File

@ -132,7 +132,7 @@ func do_tty_io(tty TTYIO, input utils.Reader, no_response bool, response_timeout
buf := make([]byte, 0, utils.DEFAULT_IO_BUFFER_SIZE)
for !response_received {
buf = buf[:0]
buf = buf[:cap(buf)]
var n int
n, err = tty.ReadWithTimeout(buf, response_timeout)
if err != nil {

View File

@ -180,8 +180,8 @@ func (self *Term) ReadWithTimeout(b []byte, d time.Duration) (n int, err error)
return self.Read(b)
}
func (t *Term) Read(b []byte) (int, error) {
n, e := eintr_retry_intret(func() (int, error) { return unix.Read(t.fd, b) })
func (self *Term) Read(b []byte) (int, error) {
n, e := eintr_retry_intret(func() (int, error) { return unix.Read(self.fd, b) })
if n < 0 {
n = 0
}
@ -189,13 +189,13 @@ func (t *Term) Read(b []byte) (int, error) {
return 0, io.EOF
}
if e != nil {
return n, &os.PathError{Op: "read", Path: t.name, Err: e}
return n, &os.PathError{Op: "read", Path: self.name, Err: e}
}
return n, nil
}
func (t *Term) Write(b []byte) (int, error) {
n, e := eintr_retry_intret(func() (int, error) { return unix.Write(t.fd, b) })
func (self *Term) Write(b []byte) (int, error) {
n, e := eintr_retry_intret(func() (int, error) { return unix.Write(self.fd, b) })
if n < 0 {
n = 0
}
@ -203,7 +203,7 @@ func (t *Term) Write(b []byte) (int, error) {
return n, io.ErrShortWrite
}
if e != nil {
return n, &os.PathError{Op: "write", Path: t.name, Err: e}
return n, &os.PathError{Op: "write", Path: self.name, Err: e}
}
return n, nil
}