Retry syscall.Write in Flush
This commit is contained in:
parent
b1e823dbd5
commit
cd2b4dd322
@ -3,9 +3,12 @@
|
|||||||
package prompt
|
package prompt
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"log"
|
||||||
"syscall"
|
"syscall"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const flushMaxRetryCount = 3
|
||||||
|
|
||||||
// PosixWriter is a ConsoleWriter implementation for POSIX environment.
|
// PosixWriter is a ConsoleWriter implementation for POSIX environment.
|
||||||
// To control terminal emulator, this outputs VT100 escape sequences.
|
// To control terminal emulator, this outputs VT100 escape sequences.
|
||||||
type PosixWriter struct {
|
type PosixWriter struct {
|
||||||
@ -17,9 +20,15 @@ type PosixWriter struct {
|
|||||||
func (w *PosixWriter) Flush() error {
|
func (w *PosixWriter) Flush() error {
|
||||||
l := len(w.buffer)
|
l := len(w.buffer)
|
||||||
offset := 0
|
offset := 0
|
||||||
|
retry := 0
|
||||||
for {
|
for {
|
||||||
n, err := syscall.Write(w.fd, w.buffer[offset:])
|
n, err := syscall.Write(w.fd, w.buffer[offset:])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Printf("[DEBUG] flush error: %s", err)
|
||||||
|
if retry < flushMaxRetryCount {
|
||||||
|
retry++
|
||||||
|
continue
|
||||||
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
offset += n
|
offset += n
|
||||||
|
Loading…
Reference in New Issue
Block a user