github.com/searKing/golang/go@v1.2.117/net/tcp/connstate.go (about) 1 // Copyright 2020 The searKing Author. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package tcp 6 7 // A ConnState represents the state of a client connection to a server. 8 // It's used by the optional Server.ConnState hook. 9 type ConnState int 10 11 const ( 12 // StateNew represents a new connection that is expected to 13 // send a request immediately. Connections begin at this 14 // state and then transition to either StateActive or 15 // StateClosed. 16 StateNew ConnState = iota 17 18 // StateActive represents a connection that has read 1 or more 19 // bytes of a request. The Server.ConnState hook for 20 // StateActive fires before the request has entered a handler 21 // and doesn't fire again until the request has been 22 // handled. After the request is handled, the state 23 // transitions to StateClosed, StateHijacked, or StateIdle. 24 // For HTTP/2, StateActive fires on the transition from zero 25 // to one active request, and only transitions away once all 26 // active requests are complete. That means that ConnState 27 // cannot be used to do per-request work; ConnState only notes 28 // the overall state of the connection. 29 StateActive 30 31 // StateIdle represents a connection that has finished 32 // handling a request and is in the keep-alive state, waiting 33 // for a new request. Connections transition from StateIdle 34 // to either StateActive or StateClosed. 35 StateIdle 36 37 // StateHijacked represents a hijacked connection. 38 // This is a terminal state. It does not transition to StateClosed. 39 StateHijacked 40 41 // StateClosed represents a closed connection. 42 // This is a terminal state. Hijacked connections do not 43 // transition to StateClosed. 44 StateClosed 45 ) 46 47 var stateName = map[ConnState]string{ 48 StateNew: "new", 49 StateActive: "active", 50 StateIdle: "idle", 51 StateHijacked: "hijacked", 52 StateClosed: "closed", 53 } 54 55 func (c ConnState) String() string { 56 return stateName[c] 57 }