@@ -759,6 +759,61 @@ func (cc *ClientConn) ReserveNewRequest() bool {
759
759
return true
760
760
}
761
761
762
+ // ClientConnState describes the state of a ClientConn.
763
+ type ClientConnState struct {
764
+ // Closed is whether the connection is closed.
765
+ Closed bool
766
+
767
+ // Closing is whether the connection is in the process of
768
+ // closing. It may be closing due to shutdown, being a
769
+ // single-use connection, being marked as DoNotReuse, or
770
+ // having received a GOAWAY frame.
771
+ Closing bool
772
+
773
+ // StreamsActive is how many streams are active.
774
+ StreamsActive int
775
+
776
+ // StreamsReserved is how many streams have been reserved via
777
+ // ClientConn.ReserveNewRequest.
778
+ StreamsReserved int
779
+
780
+ // StreamsPending is how many requests have been sent in excess
781
+ // of the peer's advertised MaxConcurrentStreams setting and
782
+ // are waiting for other streams to complete.
783
+ StreamsPending int
784
+
785
+ // MaxConcurrentStreams is how many concurrent streams the
786
+ // peer advertised as acceptable. Zero means no SETTINGS
787
+ // frame has been received yet.
788
+ MaxConcurrentStreams uint32
789
+
790
+ // LastIdle, if non-zero, is when the connection last
791
+ // transitioned to idle state.
792
+ LastIdle time.Time
793
+ }
794
+
795
+ // State returns a snapshot of cc's state.
796
+ func (cc * ClientConn ) State () ClientConnState {
797
+ cc .wmu .Lock ()
798
+ maxConcurrent := cc .maxConcurrentStreams
799
+ if ! cc .seenSettings {
800
+ maxConcurrent = 0
801
+ }
802
+ cc .wmu .Unlock ()
803
+
804
+ cc .mu .Lock ()
805
+ defer cc .mu .Unlock ()
806
+ return ClientConnState {
807
+ Closed : cc .closed ,
808
+ Closing : cc .closing || cc .singleUse || cc .doNotReuse || cc .goAway != nil ,
809
+ StreamsActive : len (cc .streams ),
810
+ StreamsReserved : cc .streamsReserved ,
811
+ StreamsPending : cc .pendingRequests ,
812
+ LastIdle : cc .lastIdle ,
813
+ MaxConcurrentStreams : maxConcurrent ,
814
+ }
815
+ }
816
+
762
817
// clientConnIdleState describes the suitability of a client
763
818
// connection to initiate a new RoundTrip request.
764
819
type clientConnIdleState struct {
0 commit comments