From 994f455368cf44e03b31116bd2aa34fd19832a3f Mon Sep 17 00:00:00 2001 From: fangdingjun Date: Thu, 12 Jul 2018 14:42:37 +0800 Subject: [PATCH] add CanTakeNewRequest function on ClientConn --- conn.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/conn.go b/conn.go index 90a60c3..dee4790 100644 --- a/conn.go +++ b/conn.go @@ -358,6 +358,22 @@ func (c *ClientConn) CreateRequest(req *http.Request) (*http.Response, error) { //return nil, fmt.Errorf("unknown error") } +// CanTakeNewRequest check if the ClientConn can submit a new request +func (c *ClientConn) CanTakeNewRequest() bool { + if c.closed { + return false + } + + if c.err != nil { + return false + } + + if c.streamCount > ((1 << 31) / 2) { + return false + } + return true +} + // ServerConn server connection type ServerConn struct { // Handler handler to handle request