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