diff --git a/go.mod b/go.mod index b234ba7..fe33485 100644 --- a/go.mod +++ b/go.mod @@ -2,4 +2,4 @@ module github.com/jstarks/npiperelay go 1.13 -require golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae +require golang.org/x/sys v0.5.0 diff --git a/go.sum b/go.sum index 06d6848..ce01524 100644 --- a/go.sum +++ b/go.sum @@ -1,2 +1,4 @@ golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae h1:Ih9Yo4hSPImZOpfGuA4bR/ORKTAbhZo2AbWNRCnevdo= golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU= +golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= diff --git a/npiperelay.go b/npiperelay.go index 08cbaab..e9c9a06 100644 --- a/npiperelay.go +++ b/npiperelay.go @@ -15,7 +15,7 @@ import ( const cERROR_PIPE_NOT_CONNECTED syscall.Errno = 233 var ( - poll = flag.Bool("p", false, "poll until the the named pipe exists") + poll = flag.Bool("p", true, "poll until the the named pipe exists") closeWrite = flag.Bool("s", false, "send a 0-byte message to the pipe after EOF on stdin") closeOnEOF = flag.Bool("ep", false, "terminate on EOF reading from the pipe, even if there is more data to write") closeOnStdinEOF = flag.Bool("ei", false, "terminate on EOF reading from stdin, even if there is more data to write") @@ -27,6 +27,7 @@ func dialPipe(p string, poll bool) (*overlappedFile, error) { if err != nil { return nil, err } + var errCount int for { h, err := windows.CreateFile(&p16[0], windows.GENERIC_READ|windows.GENERIC_WRITE, 0, nil, windows.OPEN_EXISTING, windows.FILE_FLAG_OVERLAPPED, 0) if err == nil { @@ -36,6 +37,11 @@ func dialPipe(p string, poll bool) (*overlappedFile, error) { time.Sleep(200 * time.Millisecond) continue } + if err != nil && errCount < 200 { + time.Sleep(200 * time.Millisecond) + errCount++ + continue + } return nil, &os.PathError{Path: p, Op: "open", Err: err} } }