MCPcopy
hub / github.com/grpc/grpc-go / NewSubConn

Method NewSubConn

interop/orcalb.go:115–132  ·  view source on GitHub ↗

NewSubConn intercepts SubConn creation from pick_first children to wrap the StateListener for OOB listener management on READY transitions.

(addrs []resolver.Address, opts balancer.NewSubConnOptions)

Source from the content-addressed store, hash-verified

113// NewSubConn intercepts SubConn creation from pick_first children to wrap the
114// StateListener for OOB listener management on READY transitions.
115func (b *orcab) NewSubConn(addrs []resolver.Address, opts balancer.NewSubConnOptions) (balancer.SubConn, error) {
116 // The variable sc is declared before the closure so the closure captures
117 // the variable, not its (zero) value. After ClientConn.NewSubConn assigns
118 // to sc, the closure sees the real SubConn when invoked.
119 var sc balancer.SubConn
120 oldListener := opts.StateListener
121 opts.StateListener = func(state balancer.SubConnState) {
122 b.updateSubConnState(sc, state)
123 if oldListener != nil {
124 oldListener(state)
125 }
126 }
127 sc, err := b.ClientConn.NewSubConn(addrs, opts)
128 if err != nil {
129 return nil, err
130 }
131 return sc, nil
132}
133
134func (b *orcab) updateSubConnState(sc balancer.SubConn, state balancer.SubConnState) {
135 b.mu.Lock()

Callers

nothing calls this directly

Calls 2

updateSubConnStateMethod · 0.95
NewSubConnMethod · 0.65

Tested by

no test coverage detected