1// Copyright 2016 go-dockerclient authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5// +build windows
6
7package docker
8
9import (
10	"context"
11	"net"
12	"net/http"
13	"time"
14
15	"github.com/Microsoft/go-winio"
16)
17
18const namedPipeConnectTimeout = 2 * time.Second
19
20type pipeDialer struct {
21	dialFunc func(network, addr string) (net.Conn, error)
22}
23
24func (p pipeDialer) Dial(network, address string) (net.Conn, error) {
25	return p.dialFunc(network, address)
26}
27
28// initializeNativeClient initializes the native Named Pipe client for Windows
29func (c *Client) initializeNativeClient(trFunc func() *http.Transport) {
30	if c.endpointURL.Scheme != namedPipeProtocol {
31		return
32	}
33	namedPipePath := c.endpointURL.Path
34	dialFunc := func(network, addr string) (net.Conn, error) {
35		timeout := namedPipeConnectTimeout
36		return winio.DialPipe(namedPipePath, &timeout)
37	}
38	tr := trFunc()
39	tr.Dial = dialFunc
40	tr.DialContext = func(ctx context.Context, network, addr string) (net.Conn, error) {
41		return dialFunc(network, addr)
42	}
43	c.Dialer = &pipeDialer{dialFunc}
44	c.HTTPClient.Transport = tr
45}
46