aboutsummaryrefslogtreecommitdiffstats
path: root/rpc/ipc_windows.go
diff options
context:
space:
mode:
Diffstat (limited to 'rpc/ipc_windows.go')
-rw-r--r--rpc/ipc_windows.go15
1 files changed, 13 insertions, 2 deletions
diff --git a/rpc/ipc_windows.go b/rpc/ipc_windows.go
index 8342d04d5..68234d215 100644
--- a/rpc/ipc_windows.go
+++ b/rpc/ipc_windows.go
@@ -22,16 +22,27 @@ import (
"net"
"time"
+ "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 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
+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)
}