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

Method ServeConn

server.go:2194–2225  ·  view source on GitHub ↗

ServeConn serves HTTP requests from the given connection. ServeConn returns nil if all requests from the c are successfully served. It returns non-nil error otherwise. Connection c must immediately propagate all the data passed to Write() to the client. Otherwise requests' processing may hang. Se

(c net.Conn)

Source from the content-addressed store, hash-verified

2192//
2193// ServeConn closes c before returning.
2194func (s *Server) ServeConn(c net.Conn) error {
2195 if s.MaxConnsPerIP > 0 {
2196 pic := wrapPerIPConn(s, c)
2197 if pic == nil {
2198 return ErrPerIPConnLimit
2199 }
2200 c = pic
2201 }
2202
2203 if !s.tryAcquireConcurrency() {
2204 s.writeFastError(c, StatusServiceUnavailable, "The connection cannot be served because Server.Concurrency limit exceeded")
2205 c.Close()
2206 return ErrConcurrencyLimit
2207 }
2208 defer s.releaseConcurrency()
2209
2210 s.open.Add(1)
2211
2212 err := s.serveConnCounted(c, false)
2213
2214 if err != errHijacked {
2215 errc := c.Close()
2216 s.setState(c, StateClosed)
2217 if err == nil {
2218 err = errc
2219 }
2220 } else {
2221 err = nil
2222 s.setState(c, StateHijacked)
2223 }
2224 return err
2225}
2226
2227func (s *Server) tryAcquireConcurrency() bool {
2228 n := int(s.concurrency.Add(1)) // #nosec G115

Calls 8

tryAcquireConcurrencyMethod · 0.95
writeFastErrorMethod · 0.95
releaseConcurrencyMethod · 0.95
serveConnCountedMethod · 0.95
setStateMethod · 0.95
wrapPerIPConnFunction · 0.85
CloseMethod · 0.65
AddMethod · 0.45