MCPcopy
hub / github.com/valyala/fasthttp / serveConnCounted

Method serveConnCounted

server.go:2310–2755  ·  view source on GitHub ↗
(c net.Conn, countConcurrency bool)

Source from the content-addressed store, hash-verified

2308}
2309
2310func (s *Server) serveConnCounted(c net.Conn, countConcurrency bool) error {
2311 defer s.serveConnCleanup(countConcurrency)
2312 if countConcurrency {
2313 s.concurrency.Add(1)
2314 }
2315
2316 proto, err := s.getNextProto(c)
2317 if err != nil {
2318 return err
2319 }
2320 if handler, ok := s.nextProtos[proto]; ok {
2321 // Remove read or write deadlines that might have previously been set.
2322 // The next handler is responsible for setting its own deadlines.
2323 if s.ReadTimeout > 0 || s.WriteTimeout > 0 {
2324 if err := c.SetDeadline(zeroTime); err != nil {
2325 return err
2326 }
2327 }
2328
2329 return handler(c)
2330 }
2331
2332 s.idleConnsMu.Lock()
2333 if s.idleConns == nil {
2334 s.idleConns = make(map[net.Conn]*atomic.Int64)
2335 }
2336 idleConnTime, ok := s.idleConns[c]
2337 if !ok {
2338 v := idleConnTimePool.Get()
2339 if v == nil {
2340 v = &atomic.Int64{}
2341 }
2342 idleConnTime = v.(*atomic.Int64)
2343 s.idleConns[c] = idleConnTime
2344 }
2345
2346 // Count the connection as Idle after 5 seconds.
2347 // Same as net/http.Server:
2348 // https://github.com/golang/go/blob/85d7bab91d9a3ed1f76842e4328973ea75efef54/src/net/http/server.go#L2834-L2836
2349 idleConnTime.Store(time.Now().Add(time.Second * 5).Unix())
2350 s.idleConnsMu.Unlock()
2351
2352 serverName := s.getServerName()
2353 connRequestNum := uint64(0)
2354 connID := nextConnID()
2355 connTime := time.Now()
2356 maxRequestBodySize := s.MaxRequestBodySize
2357 if maxRequestBodySize <= 0 {
2358 maxRequestBodySize = DefaultMaxRequestBodySize
2359 }
2360 writeTimeout := s.WriteTimeout
2361 previousWriteTimeout := time.Duration(0)
2362
2363 ctx := s.acquireCtx(c)
2364 ctx.connTime = connTime
2365 isTLS := ctx.IsTLS()
2366 var (
2367 br *bufio.Reader

Callers 2

ServeConnMethod · 0.95
serveConnMethod · 0.95

Calls 15

serveConnCleanupMethod · 0.95
getNextProtoMethod · 0.95
getServerNameMethod · 0.95
acquireCtxMethod · 0.95
idleTimeoutMethod · 0.95
setStateMethod · 0.95
writeErrorResponseMethod · 0.95
releaseCtxMethod · 0.95
nextConnIDFunction · 0.85
acquireReaderFunction · 0.85
acquireByteReaderFunction · 0.85
releaseReaderFunction · 0.85

Tested by

no test coverage detected