mirror of https://github.com/grpc/grpc-go.git
Comment formatting
This commit is contained in:
parent
eeb6f5bade
commit
49d2a88c27
|
@ -231,7 +231,7 @@ func WithUserAgent(s string) DialOption {
|
|||
}
|
||||
}
|
||||
|
||||
// WithKeepaliveParams returns a DialOption that specifies a user agent string for all the RPCs.
|
||||
// WithKeepaliveParams returns a DialOption that specifies keepalive paramaters for the client transport.
|
||||
func WithKeepaliveParams(k keepalive.Params) DialOption {
|
||||
return func(o *dialOptions) {
|
||||
o.copts.KeepaliveParams = k
|
||||
|
|
|
@ -16,33 +16,33 @@ type Params struct {
|
|||
PermitWithoutStream bool
|
||||
}
|
||||
|
||||
// DefaultParams contains default values for keepalive parameters
|
||||
// DefaultParams contains default values for keepalive parameters.
|
||||
var DefaultParams = Params{
|
||||
Time: time.Duration(math.MaxInt64), // default to infinite
|
||||
Time: time.Duration(math.MaxInt64), // default to infinite.
|
||||
Timeout: time.Duration(20 * time.Second),
|
||||
}
|
||||
|
||||
// mu is a mutex to protect Enabled variable
|
||||
// mu is a mutex to protect Enabled variable.
|
||||
var mu = sync.Mutex{}
|
||||
|
||||
// enable is a knob used to turn keepalive on or off
|
||||
// enable is a knob used to turn keepalive on or off.
|
||||
var enable = false
|
||||
|
||||
// Enabled exposes the value of enable variable
|
||||
// Enabled exposes the value of enable variable.
|
||||
func Enabled() bool {
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
return enable
|
||||
}
|
||||
|
||||
// Enable can be called to enable keepalives
|
||||
// Enable can be called to enable keepalives.
|
||||
func Enable() {
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
enable = true
|
||||
}
|
||||
|
||||
// Disable can be called to disable keepalive
|
||||
// Disable can be called to disable keepalive.
|
||||
func Disable() {
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
|
|
|
@ -100,9 +100,9 @@ type http2Client struct {
|
|||
|
||||
creds []credentials.PerRPCCredentials
|
||||
|
||||
// activity counter
|
||||
activity uint64 // accessed atomically
|
||||
// keepalive parameters
|
||||
// Counter to keep track of activity(reading and writing on transport).
|
||||
activity uint64 // accessed atomically.
|
||||
// keepalive parameters.
|
||||
kp keepalive.Params
|
||||
|
||||
mu sync.Mutex // guard the following variables
|
||||
|
@ -702,7 +702,6 @@ func (t *http2Client) Write(s *Stream, data []byte, opts *Options) error {
|
|||
break
|
||||
}
|
||||
}
|
||||
// activity++
|
||||
atomic.AddUint64(&t.activity, 1)
|
||||
if !opts.Last {
|
||||
return nil
|
||||
|
@ -990,7 +989,6 @@ func (t *http2Client) reader() {
|
|||
// loop to keep reading incoming messages on this transport.
|
||||
for {
|
||||
frame, err := t.framer.readFrame()
|
||||
// activity++
|
||||
atomic.AddUint64(&t.activity, 1)
|
||||
if err != nil {
|
||||
// Abort an active stream if the http2.Framer returns a
|
||||
|
@ -1118,7 +1116,7 @@ func (t *http2Client) controller() {
|
|||
isPingSent = false
|
||||
} else {
|
||||
if !isPingSent {
|
||||
// send ping
|
||||
// Send ping.
|
||||
t.controlBuf.put(keepalivePing)
|
||||
isPingSent = true
|
||||
timer.Reset(t.kp.Timeout)
|
||||
|
|
|
@ -381,7 +381,7 @@ type ConnectOptions struct {
|
|||
PerRPCCredentials []credentials.PerRPCCredentials
|
||||
// TransportCredentials stores the Authenticator required to setup a client connection.
|
||||
TransportCredentials credentials.TransportCredentials
|
||||
// Keepalive parameters
|
||||
// KeepaliveParams stores the keepalive parameters.
|
||||
KeepaliveParams keepalive.Params
|
||||
}
|
||||
|
||||
|
|
|
@ -279,7 +279,7 @@ func setUpWithNoPingServer(t *testing.T, copts ConnectOptions, done chan net.Con
|
|||
if err != nil {
|
||||
t.Fatalf("Failed to listen: %v", err)
|
||||
}
|
||||
// launch a non responsive server
|
||||
// Launch a non responsive server.
|
||||
go func() {
|
||||
defer lis.Close()
|
||||
conn, err := lis.Accept()
|
||||
|
@ -302,9 +302,9 @@ func TestKeepaliveClientClosesIdleTransport(t *testing.T) {
|
|||
defer keepalive.Disable()
|
||||
done := make(chan net.Conn, 1)
|
||||
tr := setUpWithNoPingServer(t, ConnectOptions{KeepaliveParams: keepalive.Params{
|
||||
Time: 2 * time.Second, // keepalive time = 2 sec
|
||||
Timeout: 1 * time.Second, // keepalive timeout = 1 sec
|
||||
PermitWithoutStream: true, // run keepalive even with no RPCs
|
||||
Time: 2 * time.Second, // Keepalive time = 2 sec.
|
||||
Timeout: 1 * time.Second, // Keepalive timeout = 1 sec.
|
||||
PermitWithoutStream: true, // Run keepalive even with no RPCs.
|
||||
}}, done)
|
||||
defer tr.Close()
|
||||
conn, ok := <-done
|
||||
|
@ -312,9 +312,9 @@ func TestKeepaliveClientClosesIdleTransport(t *testing.T) {
|
|||
t.Fatalf("Server didn't return connection object")
|
||||
}
|
||||
defer conn.Close()
|
||||
// Sleep for keepalive to close the connection
|
||||
// Sleep for keepalive to close the connection.
|
||||
time.Sleep(4 * time.Second)
|
||||
// Assert that the connection was closed
|
||||
// Assert that the connection was closed.
|
||||
ct := tr.(*http2Client)
|
||||
ct.mu.Lock()
|
||||
defer ct.mu.Unlock()
|
||||
|
@ -328,9 +328,9 @@ func TestKeepaliveClientStaysHealthyOnIdleTransport(t *testing.T) {
|
|||
defer keepalive.Disable()
|
||||
done := make(chan net.Conn, 1)
|
||||
tr := setUpWithNoPingServer(t, ConnectOptions{KeepaliveParams: keepalive.Params{
|
||||
Time: 2 * time.Second, // keepalive time = 2 sec
|
||||
Timeout: 1 * time.Second, // keepalive timeout = 1 sec
|
||||
PermitWithoutStream: false, // don't run keepalive even with no RPCs
|
||||
Time: 2 * time.Second, // Keepalive time = 2 sec.
|
||||
Timeout: 1 * time.Second, // Keepalive timeout = 1 sec.
|
||||
PermitWithoutStream: false, // Don't run keepalive even with no RPCs.
|
||||
}}, done)
|
||||
defer tr.Close()
|
||||
conn, ok := <-done
|
||||
|
@ -338,9 +338,9 @@ func TestKeepaliveClientStaysHealthyOnIdleTransport(t *testing.T) {
|
|||
t.Fatalf("server didn't reutrn connection object")
|
||||
}
|
||||
defer conn.Close()
|
||||
// Give keepalive some time
|
||||
// Give keepalive some time.
|
||||
time.Sleep(4 * time.Second)
|
||||
// Assert that connections is still healthy
|
||||
// Assert that connections is still healthy.
|
||||
ct := tr.(*http2Client)
|
||||
ct.mu.Lock()
|
||||
defer ct.mu.Unlock()
|
||||
|
@ -354,9 +354,9 @@ func TestKeepaliveClientClosesWithActiveStreams(t *testing.T) {
|
|||
defer keepalive.Disable()
|
||||
done := make(chan net.Conn, 1)
|
||||
tr := setUpWithNoPingServer(t, ConnectOptions{KeepaliveParams: keepalive.Params{
|
||||
Time: 2 * time.Second, // keepalive time = 2 sec
|
||||
Timeout: 1 * time.Second, // keepalive timeout = 1 sec
|
||||
PermitWithoutStream: false, // don't run keepalive even with no RPCs
|
||||
Time: 2 * time.Second, // Keepalive time = 2 sec.
|
||||
Timeout: 1 * time.Second, // Keepalive timeout = 1 sec.
|
||||
PermitWithoutStream: false, // Don't run keepalive even with no RPCs.
|
||||
}}, done)
|
||||
defer tr.Close()
|
||||
conn, ok := <-done
|
||||
|
@ -364,14 +364,14 @@ func TestKeepaliveClientClosesWithActiveStreams(t *testing.T) {
|
|||
t.Fatalf("Server didn't return connection object")
|
||||
}
|
||||
defer conn.Close()
|
||||
// create a stream
|
||||
// Create a stream.
|
||||
_, err := tr.NewStream(context.Background(), &CallHdr{})
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create a new stream: %v", err)
|
||||
}
|
||||
// Give keepalive some time
|
||||
// Give keepalive some time.
|
||||
time.Sleep(4 * time.Second)
|
||||
// Asser that transport was closed
|
||||
// Assert that transport was closed.
|
||||
ct := tr.(*http2Client)
|
||||
ct.mu.Lock()
|
||||
defer ct.mu.Unlock()
|
||||
|
@ -384,15 +384,15 @@ func TestKeepaliveClientStaysHealthyWithResponsiveServer(t *testing.T) {
|
|||
keepalive.Enable()
|
||||
defer keepalive.Disable()
|
||||
s, tr := setUpWithOptions(t, 0, math.MaxUint32, normal, ConnectOptions{KeepaliveParams: keepalive.Params{
|
||||
Time: 2 * time.Second, // keepalive time = 2 sec
|
||||
Timeout: 1 * time.Second, // keepalive timeout = 1 sec
|
||||
PermitWithoutStream: true, // don't run keepalive even with no RPCs
|
||||
Time: 2 * time.Second, // Keepalive time = 2 sec.
|
||||
Timeout: 1 * time.Second, // Keepalive timeout = 1 sec.
|
||||
PermitWithoutStream: true, // Don't run keepalive even with no RPCs.
|
||||
}})
|
||||
defer s.stop()
|
||||
defer tr.Close()
|
||||
// Give keep alive some time
|
||||
// Give keep alive some time.
|
||||
time.Sleep(4 * time.Second)
|
||||
// Assert that transport is healthy
|
||||
// Assert that transport is healthy.
|
||||
ct := tr.(*http2Client)
|
||||
ct.mu.Lock()
|
||||
defer ct.mu.Unlock()
|
||||
|
|
Loading…
Reference in New Issue