fix reading from tty
This commit is contained in:
@@ -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)
|
buf := make([]byte, 0, utils.DEFAULT_IO_BUFFER_SIZE)
|
||||||
|
|
||||||
for !response_received {
|
for !response_received {
|
||||||
buf = buf[:0]
|
buf = buf[:cap(buf)]
|
||||||
var n int
|
var n int
|
||||||
n, err = tty.ReadWithTimeout(buf, response_timeout)
|
n, err = tty.ReadWithTimeout(buf, response_timeout)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -180,8 +180,8 @@ func (self *Term) ReadWithTimeout(b []byte, d time.Duration) (n int, err error)
|
|||||||
return self.Read(b)
|
return self.Read(b)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Term) Read(b []byte) (int, error) {
|
func (self *Term) Read(b []byte) (int, error) {
|
||||||
n, e := eintr_retry_intret(func() (int, error) { return unix.Read(t.fd, b) })
|
n, e := eintr_retry_intret(func() (int, error) { return unix.Read(self.fd, b) })
|
||||||
if n < 0 {
|
if n < 0 {
|
||||||
n = 0
|
n = 0
|
||||||
}
|
}
|
||||||
@@ -189,13 +189,13 @@ func (t *Term) Read(b []byte) (int, error) {
|
|||||||
return 0, io.EOF
|
return 0, io.EOF
|
||||||
}
|
}
|
||||||
if e != nil {
|
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
|
return n, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Term) Write(b []byte) (int, error) {
|
func (self *Term) Write(b []byte) (int, error) {
|
||||||
n, e := eintr_retry_intret(func() (int, error) { return unix.Write(t.fd, b) })
|
n, e := eintr_retry_intret(func() (int, error) { return unix.Write(self.fd, b) })
|
||||||
if n < 0 {
|
if n < 0 {
|
||||||
n = 0
|
n = 0
|
||||||
}
|
}
|
||||||
@@ -203,7 +203,7 @@ func (t *Term) Write(b []byte) (int, error) {
|
|||||||
return n, io.ErrShortWrite
|
return n, io.ErrShortWrite
|
||||||
}
|
}
|
||||||
if e != nil {
|
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
|
return n, nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user