Class: Puma::Reactor

### Home Classes Methods

### In Files

- lib/puma/reactor.rb

### Parent

Object

### Methods

- ::new
- #add
- #calculate_sleep
- #clear!
- #run
- #run_in_thread
- #shutdown

### Files

- Manifest.txt

### Class/Module Index

Quicksearch

- Puma
- Puma::App
- Puma::App::Status
- Puma::Binder
- Puma::CLI
- Puma::Client
- Puma::Cluster
- Puma::Cluster::Worker
- Puma::CommonLogger
- Puma::ConfigDefault
- Puma::Configuration
- Puma::Configuration::ConfigMiddleware
- Puma::ConnectionError
- Puma::Const
- Puma::ControlCLI
- Puma::DSL
- Puma::Delegation
- Puma::Events
- Puma::Events::DefaultFormatter
- Puma::Events::PidFormatter
- Puma::IOBuffer
- Puma::JRubyRestart
- Puma::JavaIOBuffer
- Puma::MiniSSL
- Puma::MiniSSL::Context
- Puma::MiniSSL::SSLError
- Puma::MiniSSL::Server
- Puma::MiniSSL::Socket
- Puma::NullIO
- Puma::Rack
- Puma::Rack::Builder
- Puma::Rack::Options
- Puma::Rack::URLMap
- Puma::Reactor
- Puma::Runner
- Puma::Server
- Puma::Single
- Puma::TCPLogger
- Puma::ThreadPool
- Puma::ThreadPool::AutoTrim
- Puma::ThreadPool::Reaper
- Puma::UnsupportedOption
- Puma::Util
- Puma::Util::HeaderHash
- OpenSSL
- OpenSSL::SSL
- OpenSSL::SSL::SSLServer
- Rack
- Rack::Handler
- Rack::Handler::Puma
- IO
- IO::WaitReadable
- Object
- Process
- String

No matching classes.

# Puma::Reactor

### Constants

DefaultSleepFor

### Public Class Methods

new(server, app_pool) click to toggle source

    # File lib/puma/reactor.rb, line 8
    def initialize(server, app_pool)
      @server = server
      @events = server.events
      @app_pool = app_pool

      @mutex = Mutex.new
      @ready, @trigger = Puma::Util.pipe
      @input = []
      @sleep_for = DefaultSleepFor
      @timeouts = []

      @sockets = [@ready]
    end

### Public Instance Methods

add(c) click to toggle source

    # File lib/puma/reactor.rb, line 164
    def add(c)
      @mutex.synchronize do
        @input << c
        @trigger << "*"

        if c.timeout_at
          @timeouts << c
          @timeouts.sort! { |a,b| a.timeout_at <=> b.timeout_at }

          calculate_sleep
        end
      end
    end

calculate_sleep() click to toggle source

    # File lib/puma/reactor.rb, line 150
    def calculate_sleep
      if @timeouts.empty?
        @sleep_for = DefaultSleepFor
      else
        diff = @timeouts.first.timeout_at.to_f - Time.now.to_f

        if diff < 0.0
          @sleep_for = 0
        else
          @sleep_for = diff
        end
      end
    end

clear!() click to toggle source

Close all watched sockets and clear them from being watched

    # File lib/puma/reactor.rb, line 179
    def clear!
      begin
        @trigger << "c"
      rescue IOError
      end
    end

run() click to toggle source

    # File lib/puma/reactor.rb, line 128
    def run
      run_internal
    ensure
      @trigger.close
      @ready.close
    end

run_in_thread() click to toggle source

    # File lib/puma/reactor.rb, line 135
    def run_in_thread
      @thread = Thread.new do
        begin
          run_internal
        rescue StandardError => e
          STDERR.puts "Error in reactor loop escaped: #{e.message} (#{e.class})"
          STDERR.puts e.backtrace
          retry
        ensure
          @trigger.close
          @ready.close
        end
      end
    end

shutdown() click to toggle source

    # File lib/puma/reactor.rb, line 186
    def shutdown
      begin
        @trigger << "!"
      rescue IOError
      end

      @thread.join
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.