server.go
func (s *Server) ServeConn(c net.Conn) error {
	if s.MaxConnsPerIP > 0 {
		pic := wrapPerIPConn(s, c)
		if pic == nil {
			return ErrPerIPConnLimit
		}
		c = pic
	}

	n := atomic.AddUint32(&s.concurrency, 1)
	if n > uint32(s.getConcurrency()) {
		atomic.AddUint32(&s.concurrency, ^uint32(0))
		s.writeFastError(c, StatusServiceUnavailable, "The connection cannot be served because Server.Concurrency limit exceeded")
		c.Close()
		return ErrConcurrencyLimit
	}

	atomic.AddInt32(&s.open, 1)

	err := s.serveConn(c)

	atomic.AddUint32(&s.concurrency, ^uint32(0))

	if err != errHijacked {
		err1 := c.Close()
		s.setState(c, StateClosed)
		if err == nil {
			err = err1
		}
	} else {
		err = nil
		s.setState(c, StateHijacked)
	}
	return err
}
func (s *Server) ServeConn(c net.Conn) error {
	if s.MaxConnsPerIP > 0 {
		pic := wrapPerIPConn(s, c)
		if pic == nil {
			return ErrPerIPConnLimit
		}
		c = pic
	}

	n := atomic.AddUint32(&s.concurrency, 1)
	if n > uint32(s.getConcurrency()) {
		atomic.AddUint32(&s.concurrency, ^uint32(0))
		s.writeFastError(c, StatusServiceUnavailable, "The connection cannot be served because Server.Concurrency limit exceeded")
		c.Close()
		return ErrConcurrencyLimit
	}

	atomic.AddInt32(&s.open, 1)

	err := s.serveConn(c)

	atomic.AddUint32(&s.concurrency, ^uint32(0))

	if err != errHijacked {
		err1 := c.Close()
		s.setState(c, StateClosed)
		if err == nil {
			err = err1
		}
	} else {
		err = nil
		s.setState(c, StateHijacked)
	}
	return err
}
func ( s * Server ) ServeConn ( c net . Conn ) error { if s . MaxConnsPerIP > 0 { pic := wrapPerIPConn ( s , c ) if pic == nil { return ErrPerIPConnLimit } c = pic } n := atomic . AddUint32 ( & s . concurrency , 1 ) if n > uint32 ( s . getConcurrency ( ) ) { atomic . AddUint32 ( & s . concurrency , ^ uint32 ( 0 ) ) s . writeFastError ( c , StatusServiceUnavailable , " " ) c . Close ( ) return ErrConcurrencyLimit } atomic . AddInt32 ( & s . open , 1 ) err := s . serveConn ( c ) atomic . AddUint32 ( & s . concurrency , ^ uint32 ( 0 ) ) if err != errHijacked { err1 := c . Close ( ) s . setState ( c , StateClosed ) if err == nil { err = err1 } } else { err = nil s . setState ( c , StateHijacked ) } return err }
// 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.
//
// ServeConn closes c before returning.
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 . ServeConn closes c before returning .