Switch ALPN/NPN to advertise only h2

This commit is contained in:
iamqizhao
2015-07-31 14:16:02 -07:00
parent 5a1c16b4e6
commit 244bc75d79
2 changed files with 39 additions and 3 deletions

View File

@ -144,6 +144,7 @@ func Dial(target string, opts ...DialOption) (*ClientConn, error) {
// Set the default codec.
cc.dopts.codec = protoCodec{}
}
cc.stateCV = sync.NewCond(&cc.mu)
if cc.dopts.block {
if err := cc.resetTransport(false); err != nil {
cc.Close()
@ -188,8 +189,9 @@ type ClientConn struct {
dopts dialOptions
shutdownChan chan struct{}
mu sync.Mutex
state ConnectivityState
mu sync.Mutex
state ConnectivityState
stateCV *sync.Cond
// ready is closed and becomes nil when a new transport is up or failed
// due to timeout.
ready chan struct{}
@ -200,6 +202,40 @@ type ClientConn struct {
transport transport.ClientTransport
}
// State returns the connectivity state of the ClientConn
func (cc *ClientConn) State() ConnectivityState {
cc.mu.Lock()
defer cc.mu.Unlock()
return cc.state
}
// WaitForStateChange returns true when the state changes to something other than the
// sourceState and false if timeout fires.
func (cc *ClientConn) WaitForStateChange(timeout time.Duration, sourceState ConnectivityState) bool {
cc.mu.Lock()
defer cc.mu.Unlock()
if sourceState != cc.state {
return true
}
// Shutdown state is a sink -- once it is entered, no furhter state change could happen.
if sourceState == Shutdown {
return false
}
done := make(chan struct{})
go func() {
select {
case <-time.After(timeout):
cc.stateCV.Broadcast()
case <-done:
}
}()
for sourceState == cc.state {
cc.stateCV.Wait()
}
close(done)
return true
}
func (cc *ClientConn) resetTransport(closeTransport bool) error {
var retries int
start := time.Now()

View File

@ -51,7 +51,7 @@ import (
var (
// alpnProtoStr are the specified application level protocols for gRPC.
alpnProtoStr = []string{"h2", "h2-14", "h2-15", "h2-16"}
alpnProtoStr = []string{"h2"}
)
// Credentials defines the common interface all supported credentials must