summaryrefslogtreecommitdiffhomepage
path: root/vendor/github.com/containerd/ttrpc/client.go
diff options
context:
space:
mode:
authorLantao Liu <lantaol@google.com>2019-05-10 18:27:49 -0700
committerIan Lewis <ianlewis@google.com>2019-05-11 10:27:49 +0900
commit97875daf63d03cda6ff3c4f393a004a8295a748e (patch)
tree30dce772c1d7bb9d77fab8b224675630e3c10b2d /vendor/github.com/containerd/ttrpc/client.go
parent14f1de4a45daa75ef016fabb56d86cbd9b902504 (diff)
Port shim fix (#27)
Port shim fixes containerd/containerd#3264, containerd/containerd#3264 Update containerd to newest release/1.2 commit.
Diffstat (limited to 'vendor/github.com/containerd/ttrpc/client.go')
-rw-r--r--vendor/github.com/containerd/ttrpc/client.go27
1 files changed, 20 insertions, 7 deletions
diff --git a/vendor/github.com/containerd/ttrpc/client.go b/vendor/github.com/containerd/ttrpc/client.go
index e40592dd7..35ca91fba 100644
--- a/vendor/github.com/containerd/ttrpc/client.go
+++ b/vendor/github.com/containerd/ttrpc/client.go
@@ -24,6 +24,7 @@ import (
"strings"
"sync"
"syscall"
+ "time"
"github.com/gogo/protobuf/proto"
"github.com/pkg/errors"
@@ -48,7 +49,15 @@ type Client struct {
err error
}
-func NewClient(conn net.Conn) *Client {
+type ClientOpts func(c *Client)
+
+func WithOnClose(onClose func()) ClientOpts {
+ return func(c *Client) {
+ c.closeFunc = onClose
+ }
+}
+
+func NewClient(conn net.Conn, opts ...ClientOpts) *Client {
c := &Client{
codec: codec{},
conn: conn,
@@ -59,6 +68,10 @@ func NewClient(conn net.Conn) *Client {
closeFunc: func() {},
}
+ for _, o := range opts {
+ o(c)
+ }
+
go c.run()
return c
}
@@ -86,6 +99,10 @@ func (c *Client) Call(ctx context.Context, service, method string, req, resp int
cresp = &Response{}
)
+ if dl, ok := ctx.Deadline(); ok {
+ creq.TimeoutNano = dl.Sub(time.Now()).Nanoseconds()
+ }
+
if err := c.dispatch(ctx, creq, cresp); err != nil {
return err
}
@@ -104,6 +121,7 @@ func (c *Client) Call(ctx context.Context, service, method string, req, resp int
func (c *Client) dispatch(ctx context.Context, req *Request, resp *Response) error {
errs := make(chan error, 1)
call := &callRequest{
+ ctx: ctx,
req: req,
resp: resp,
errs: errs,
@@ -135,11 +153,6 @@ func (c *Client) Close() error {
return nil
}
-// OnClose allows a close func to be called when the server is closed
-func (c *Client) OnClose(closer func()) {
- c.closeFunc = closer
-}
-
type message struct {
messageHeader
p []byte
@@ -249,7 +262,7 @@ func (c *Client) recv(resp *Response, msg *message) error {
}
if msg.Type != messageTypeResponse {
- return errors.New("unkown message type received")
+ return errors.New("unknown message type received")
}
defer c.channel.putmbuf(msg.p)