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

Side by Side Diff: logdog/client/butler/streamserver/base.go

Issue 2737603003: Butler stream servers can generate client address. (Closed)
Patch Set: better 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
1 // Copyright 2015 The LUCI Authors. All rights reserved. 1 // Copyright 2015 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 streamserver 5 package streamserver
6 6
7 import ( 7 import (
8 "fmt" 8 "fmt"
9 "io" 9 "io"
10 "net" 10 "net"
(...skipping 14 matching lines...) Expand all
25 rc io.ReadCloser 25 rc io.ReadCloser
26 // Negotiated stream properties. 26 // Negotiated stream properties.
27 properties *streamproto.Properties 27 properties *streamproto.Properties
28 } 28 }
29 29
30 // listenerStreamServer is the class for Listener-based stream server 30 // listenerStreamServer is the class for Listener-based stream server
31 // implementations. 31 // implementations.
32 type listenerStreamServer struct { 32 type listenerStreamServer struct {
33 context.Context 33 context.Context
34 34
35 // address is the string returned by the Address method.
36 address string
37
35 // gen is a generator function that is called to produce the stream serv er's 38 // gen is a generator function that is called to produce the stream serv er's
36 // Listener. On success, it returns the instantiated Listener, which wil l be 39 // Listener. On success, it returns the instantiated Listener, which wil l be
37 // closed when the stream server is closed. 40 // closed when the stream server is closed.
38 gen func() (net.Listener, error) 41 gen func() (net.Listener, error)
39 l net.Listener 42 l net.Listener
40 laddr string 43 laddr string
41 44
42 streamParamsC chan *streamParams 45 streamParamsC chan *streamParams
43 closedC chan struct{} 46 closedC chan struct{}
44 acceptFinishedC chan struct{} 47 acceptFinishedC chan struct{}
45 48
46 // closed is an atomically-protected integer. If its value is 1, the str eam 49 // closed is an atomically-protected integer. If its value is 1, the str eam
47 // server has been closed. 50 // server has been closed.
48 closed int32 51 closed int32
49 52
50 // discardC is a testing channel. If not nil, failed client connections will 53 // discardC is a testing channel. If not nil, failed client connections will
51 // be written here. 54 // be written here.
52 discardC chan *streamClient 55 discardC chan *streamClient
53 } 56 }
54 57
55 var _ StreamServer = (*listenerStreamServer)(nil) 58 var _ StreamServer = (*listenerStreamServer)(nil)
56 59
57 func (s *listenerStreamServer) String() string { 60 func (s *listenerStreamServer) String() string {
58 return fmt.Sprintf("%T(%s)", s, s.laddr) 61 return fmt.Sprintf("%T(%s)", s, s.laddr)
59 } 62 }
60 63
64 func (s *listenerStreamServer) Address() string { return s.address }
65
61 func (s *listenerStreamServer) Listen() error { 66 func (s *listenerStreamServer) Listen() error {
62 // Create a listener (OS-specific). 67 // Create a listener (OS-specific).
63 var err error 68 var err error
64 s.l, err = s.gen() 69 s.l, err = s.gen()
65 if err != nil { 70 if err != nil {
66 return err 71 return err
67 } 72 }
68 73
69 s.laddr = s.l.Addr().String() 74 s.laddr = s.l.Addr().String()
70 s.streamParamsC = make(chan *streamParams) 75 s.streamParamsC = make(chan *streamParams)
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 256
252 // Decouples the active connection, returning it and setting the connection to 257 // Decouples the active connection, returning it and setting the connection to
253 // nil. 258 // nil.
254 func (c *streamClient) decoupleConn() (conn net.Conn) { 259 func (c *streamClient) decoupleConn() (conn net.Conn) {
255 c.decoupleMu.Lock() 260 c.decoupleMu.Lock()
256 defer c.decoupleMu.Unlock() 261 defer c.decoupleMu.Unlock()
257 262
258 conn, c.conn = c.conn, nil 263 conn, c.conn = c.conn, nil
259 return 264 return
260 } 265 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698