diff options
Diffstat (limited to 'vendor/github.com/hashicorp/go-plugin/rpc_client.go')
-rw-r--r-- | vendor/github.com/hashicorp/go-plugin/rpc_client.go | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/vendor/github.com/hashicorp/go-plugin/rpc_client.go b/vendor/github.com/hashicorp/go-plugin/rpc_client.go index 29f9bf0..f30a4b1 100644 --- a/vendor/github.com/hashicorp/go-plugin/rpc_client.go +++ b/vendor/github.com/hashicorp/go-plugin/rpc_client.go | |||
@@ -1,6 +1,7 @@ | |||
1 | package plugin | 1 | package plugin |
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | "crypto/tls" | ||
4 | "fmt" | 5 | "fmt" |
5 | "io" | 6 | "io" |
6 | "net" | 7 | "net" |
@@ -19,6 +20,42 @@ type RPCClient struct { | |||
19 | stdout, stderr net.Conn | 20 | stdout, stderr net.Conn |
20 | } | 21 | } |
21 | 22 | ||
23 | // newRPCClient creates a new RPCClient. The Client argument is expected | ||
24 | // to be successfully started already with a lock held. | ||
25 | func newRPCClient(c *Client) (*RPCClient, error) { | ||
26 | // Connect to the client | ||
27 | conn, err := net.Dial(c.address.Network(), c.address.String()) | ||
28 | if err != nil { | ||
29 | return nil, err | ||
30 | } | ||
31 | if tcpConn, ok := conn.(*net.TCPConn); ok { | ||
32 | // Make sure to set keep alive so that the connection doesn't die | ||
33 | tcpConn.SetKeepAlive(true) | ||
34 | } | ||
35 | |||
36 | if c.config.TLSConfig != nil { | ||
37 | conn = tls.Client(conn, c.config.TLSConfig) | ||
38 | } | ||
39 | |||
40 | // Create the actual RPC client | ||
41 | result, err := NewRPCClient(conn, c.config.Plugins) | ||
42 | if err != nil { | ||
43 | conn.Close() | ||
44 | return nil, err | ||
45 | } | ||
46 | |||
47 | // Begin the stream syncing so that stdin, out, err work properly | ||
48 | err = result.SyncStreams( | ||
49 | c.config.SyncStdout, | ||
50 | c.config.SyncStderr) | ||
51 | if err != nil { | ||
52 | result.Close() | ||
53 | return nil, err | ||
54 | } | ||
55 | |||
56 | return result, nil | ||
57 | } | ||
58 | |||
22 | // NewRPCClient creates a client from an already-open connection-like value. | 59 | // NewRPCClient creates a client from an already-open connection-like value. |
23 | // Dial is typically used instead. | 60 | // Dial is typically used instead. |
24 | func NewRPCClient(conn io.ReadWriteCloser, plugins map[string]Plugin) (*RPCClient, error) { | 61 | func NewRPCClient(conn io.ReadWriteCloser, plugins map[string]Plugin) (*RPCClient, error) { |
@@ -121,3 +158,13 @@ func (c *RPCClient) Dispense(name string) (interface{}, error) { | |||
121 | 158 | ||
122 | return p.Client(c.broker, rpc.NewClient(conn)) | 159 | return p.Client(c.broker, rpc.NewClient(conn)) |
123 | } | 160 | } |
161 | |||
162 | // Ping pings the connection to ensure it is still alive. | ||
163 | // | ||
164 | // The error from the RPC call is returned exactly if you want to inspect | ||
165 | // it for further error analysis. Any error returned from here would indicate | ||
166 | // that the connection to the plugin is not healthy. | ||
167 | func (c *RPCClient) Ping() error { | ||
168 | var empty struct{} | ||
169 | return c.control.Call("Control.Ping", true, &empty) | ||
170 | } | ||