]> Cypherpunks repositories - gostls13.git/commitdiff
exit with error status EPIPE if
authorRuss Cox <rsc@golang.org>
Thu, 30 Apr 2009 01:18:42 +0000 (18:18 -0700)
committerRuss Cox <rsc@golang.org>
Thu, 30 Apr 2009 01:18:42 +0000 (18:18 -0700)
one fd gets too many EPIPEs in a row
during write.

R=r
DELTA=10  (9 added, 0 deleted, 1 changed)
OCL=28057
CL=28057

src/lib/os/file.go

index d7ea573fc55dae06e39691a86787957421386ae4..fa1784a426f34b232bed4d4b56f60e56310fbe72 100644 (file)
@@ -23,6 +23,7 @@ type File struct {
        fd int64;
        name    string;
        dirinfo *dirInfo;       // nil unless directory being read
+       nepipe  int;    // number of consecutive EPIPE in Write
 }
 
 // Fd returns the integer Unix file descriptor referencing the open file.
@@ -40,7 +41,7 @@ func NewFile(file int64, name string) *File {
        if file < 0 {
                return nil
        }
-       return &File{file, name, nil}
+       return &File{file, name, nil, 0}
 }
 
 // Stdin, Stdout, and Stderr are open Files pointing to the standard input,
@@ -128,6 +129,14 @@ func (file *File) Write(b []byte) (ret int, err Error) {
                        r = 0
                }
        }
+       if e == syscall.EPIPE {
+               file.nepipe++;
+               if file.nepipe >= 10 {
+                       sys.Exit(syscall.EPIPE);
+               }
+       } else {
+               file.nepipe = 0;
+       }
        return int(r), ErrnoToError(e)
 }