mirror of
https://github.com/rwinkhart/go-winio.git
synced 2026-09-04 08:07:20 -04:00
errors coercion to pass the tests
This commit is contained in:
@@ -138,22 +138,22 @@ func (s pipeAddress) String() string {
|
|||||||
return string(s)
|
return string(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//helper function used to try to open the pipe multiple times.
|
||||||
func tryDialPipe(ctx context.Context, path *string) (syscall.Handle, error) {
|
func tryDialPipe(ctx context.Context, path *string) (syscall.Handle, error) {
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
err := ctx.Err()
|
return syscall.Handle(0), ctx.Err()
|
||||||
if err == context.DeadlineExceeded {
|
|
||||||
err = ErrTimeout
|
|
||||||
} else {
|
|
||||||
err = &os.PathError{Op: "open", Path: *path, Err: err}
|
|
||||||
}
|
|
||||||
return syscall.Handle(0), err
|
|
||||||
default:
|
default:
|
||||||
h, err := createFile(*path, syscall.GENERIC_READ|syscall.GENERIC_WRITE, 0, nil, syscall.OPEN_EXISTING, syscall.FILE_FLAG_OVERLAPPED|cSECURITY_SQOS_PRESENT|cSECURITY_ANONYMOUS, 0)
|
h, err := createFile(*path, syscall.GENERIC_READ|syscall.GENERIC_WRITE, 0, nil, syscall.OPEN_EXISTING, syscall.FILE_FLAG_OVERLAPPED|cSECURITY_SQOS_PRESENT|cSECURITY_ANONYMOUS, 0)
|
||||||
if err != cERROR_PIPE_BUSY {
|
if err == nil {
|
||||||
return h, &os.PathError{Op: "open", Path: *path, Err: err}
|
return h, nil
|
||||||
}
|
}
|
||||||
|
if err != cERROR_PIPE_BUSY {
|
||||||
|
return h, newOpenError(path, err)
|
||||||
|
}
|
||||||
|
// Wait 10 msec and try again. This is a rather simplistic
|
||||||
|
// view, as we always try each 10 milliseconds.
|
||||||
time.Sleep(time.Millisecond * 10)
|
time.Sleep(time.Millisecond * 10)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -171,9 +171,19 @@ func DialPipe(path string, timeout *time.Duration) (net.Conn, error) {
|
|||||||
}
|
}
|
||||||
ctx, _ := context.WithDeadline(context.Background(), absTimeout)
|
ctx, _ := context.WithDeadline(context.Background(), absTimeout)
|
||||||
conn, err := DialPipeContext(ctx, path)
|
conn, err := DialPipeContext(ctx, path)
|
||||||
|
if err == context.DeadlineExceeded {
|
||||||
|
return nil, ErrTimeout
|
||||||
|
}
|
||||||
return conn, err
|
return conn, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func newOpenError(path *string, err error) error {
|
||||||
|
if err != nil {
|
||||||
|
return &os.PathError{Err: err, Op: "open", Path: *path}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
//DialPipeContext connects to a named pipe. ctx can be used to cancel or
|
//DialPipeContext connects to a named pipe. ctx can be used to cancel or
|
||||||
//expire the pending connection ( We do not use WaitNamedPipe.)
|
//expire the pending connection ( We do not use WaitNamedPipe.)
|
||||||
func DialPipeContext(ctx context.Context, path string) (net.Conn, error) {
|
func DialPipeContext(ctx context.Context, path string) (net.Conn, error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user