Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(484)

Side by Side Diff: logdog/client/butlerlib/streamclient/local.go

Issue 2737603003: Butler stream servers can generate client address. (Closed)
Patch Set: better comment Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 }
OLDNEW
« no previous file with comments | « logdog/client/butlerlib/streamclient/client_test.go ('k') | logdog/client/butlerlib/streamclient/stream.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698