Repository: puma/puma
File: lib/puma/server.rb (Ruby)

Code before:
    #
    def process_client(client, buffer)
      begin

        clean_thread_locals = @options[:clean_thread_locals]
        close_socket = true

        requests = 0

        while true
          case handle_request(client, buffer)
          when false
            return
          when :async
            close_socket = false
            return
          when true
            buffer.reset

            ThreadPool.clean_thread_locals if clean_thread_locals

            requests += 1

            check_for_more_data = @status == :run

            if requests >= MAX_FAST_INLINE && MAX_FAST_INLINE.positive?
              # This will mean that reset will only try to use the data it already
              # has buffered and won't try to read more data. What this means is that
              # every client, independent of their request speed, gets treated like a slow
              # one once every MAX_FAST_INLINE requests.
              check_for_more_data = false
            end

            next_request_ready = @thread_pool.with_force_shutdown do
              client.reset(check_for_more_data)
            end

            unless next_request_ready
              @shutdown_mutex.synchronize do
                return unless @queue_requests
                close_socket = false
                client.set_timeout @persistent_timeout
                @reactor.add client
                return
              end
            end
          end
        end

      # The client disconnected while we were reading data
      rescue ConnectionError, ThreadPool::ForceShutdown

Review comment (suggestion):
e.g. server should have `@max_fast_inline` set by the options, and then that is read here. Don't check here to see if it's positive, check when you're setting it.

Code after:
    def process_client(client, buffer)
      # Advertise this server into the thread
      Thread.current[ThreadLocalKey] = self

      clean_thread_locals = @options[:clean_thread_locals]
      close_socket = true

      requests = 0

      begin
        if @queue_requests &&
          !client.eagerly_finish

          client.set_timeout(@first_data_timeout)
          if @reactor.add client
            close_socket = false
            return false
          end
        end

        with_force_shutdown(client) do
          client.finish(@first_data_timeout)
        end

        while true
          @requests_count += 1
          case handle_request(client, buffer)
          when false
            break
          when :async
            close_socket = false
            break
          when true
            buffer.reset

            ThreadPool.clean_thread_locals if clean_thread_locals

            requests += 1

            check_for_more_data = @status == :run

            if requests >= @max_fast_inline
              # This will mean that reset will only try to use the data it already
              # has buffered and won't try to read more data. What this means is that
              # every client, independent of their request speed, gets treated like a slow
              # one once every max_fast_inline requests.
              check_for_more_data = false
            end

            next_request_ready = with_force_shutdown(client) do
              client.reset(check_for_more_data)