diff options
Diffstat (limited to 'rpc/ipc_windows.go')
-rw-r--r-- | rpc/ipc_windows.go | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/rpc/ipc_windows.go b/rpc/ipc_windows.go index 8762cdb0d..68234d215 100644 --- a/rpc/ipc_windows.go +++ b/rpc/ipc_windows.go @@ -22,16 +22,27 @@ import ( "net" "time" - winio "github.com/microsoft/go-winio" + "golang.org/x/net/context" + "gopkg.in/natefinch/npipe.v2" ) +// This is used if the dialing context has no deadline. It is much smaller than the +// defaultDialTimeout because named pipes are local and there is no need to wait so long. +const defaultPipeDialTimeout = 2 * time.Second + // ipcListen will create a named pipe on the given endpoint. func ipcListen(endpoint string) (net.Listener, error) { - return winio.ListenPipe(endpoint, &winio.PipeConfig{}) + return npipe.Listen(endpoint) } // newIPCConnection will connect to a named pipe with the given endpoint as name. -func newIPCConnection(endpoint string) (net.Conn, error) { - timeout := 5 * time.Second - return winio.DialPipe(endpoint, &timeout) +func newIPCConnection(ctx context.Context, endpoint string) (net.Conn, error) { + timeout := defaultPipeDialTimeout + if deadline, ok := ctx.Deadline(); ok { + timeout = deadline.Sub(time.Now()) + if timeout < 0 { + timeout = 0 + } + } + return npipe.DialTimeout(endpoint, timeout) } |