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