| OLD | NEW |
| 1 // Copyright 2016 The LUCI Authors. All rights reserved. | 1 // Copyright 2016 The LUCI Authors. All rights reserved. |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
| 3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
| 4 | 4 |
| 5 package streamclient | 5 package localclient |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "io" | 8 "io" |
| 9 | 9 |
| 10 "github.com/luci/luci-go/logdog/client/butler" | 10 "github.com/luci/luci-go/logdog/client/butler" |
| 11 "github.com/luci/luci-go/logdog/client/butlerlib/streamclient" |
| 11 "github.com/luci/luci-go/logdog/client/butlerlib/streamproto" | 12 "github.com/luci/luci-go/logdog/client/butlerlib/streamproto" |
| 12 ) | 13 ) |
| 13 | 14 |
| 14 // localClient is a Client implementation that is directly bound to a Butler | 15 // localClient is a Client implementation that is directly bound to a Butler |
| 15 // instance. | 16 // instance. |
| 16 type localClient struct { | 17 type localClient struct { |
| 17 *butler.Butler | 18 *butler.Butler |
| 18 } | 19 } |
| 19 | 20 |
| 20 // NewLocal creates a new Client instance bound to a local Butler instance. This | 21 var _ streamclient.Client = (*localClient)(nil) |
| 22 |
| 23 // New creates a new Client instance bound to a local Butler instance. This |
| 21 // sidesteps the need for an actual server socket and negotiation protocol and | 24 // sidesteps the need for an actual server socket and negotiation protocol and |
| 22 // directly registers streams via Butler API calls. | 25 // directly registers streams via Butler API calls. |
| 23 // | 26 // |
| 24 // Internally, the Stream uses an io.PipeWriter and io.PipeReader to ferry | 27 // Internally, the Stream uses an io.PipeWriter and io.PipeReader to ferry |
| 25 // data from the Stream's owner to the Butler. | 28 // data from the Stream's owner to the Butler. |
| 26 func NewLocal(b *butler.Butler) Client { | 29 func New(b *butler.Butler) streamclient.Client { |
| 27 return &localClient{b} | 30 return &localClient{b} |
| 28 } | 31 } |
| 29 | 32 |
| 30 func (c *localClient) NewStream(f streamproto.Flags) (s Stream, err error) { | 33 func (c *localClient) NewStream(f streamproto.Flags) (s streamclient.Stream, err
error) { |
| 31 pr, pw := io.Pipe() | 34 pr, pw := io.Pipe() |
| 32 defer func() { | 35 defer func() { |
| 33 if err != nil { | 36 if err != nil { |
| 34 pr.Close() | 37 pr.Close() |
| 35 pw.Close() | 38 pw.Close() |
| 36 } | 39 } |
| 37 }() | 40 }() |
| 38 | 41 |
| 39 props := f.Properties() | 42 props := f.Properties() |
| 40 » stream := streamImpl{ | 43 » stream := streamclient.BaseStream{ |
| 41 WriteCloser: pw, | 44 WriteCloser: pw, |
| 42 » » props: props, | 45 » » P: props, |
| 43 } | 46 } |
| 44 | 47 |
| 45 // Add the Stream to the Butler. | 48 // Add the Stream to the Butler. |
| 46 if err = c.AddStream(pr, props); err != nil { | 49 if err = c.AddStream(pr, props); err != nil { |
| 47 return | 50 return |
| 48 } | 51 } |
| 49 return &stream, nil | 52 return &stream, nil |
| 50 } | 53 } |
| OLD | NEW |