Class: Plum::Rack::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/plum/rack/server.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, config) ⇒ Server

Returns a new instance of Server.


7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/plum/rack/server.rb', line 7

def initialize(app, config)
  @config = config
  @state = :null
  @app = config[:debug] ? ::Rack::CommonLogger.new(app) : app
  @logger = Logger.new(config[:log] || $stdout).tap { |l|
    l.level = config[:debug] ? Logger::DEBUG : Logger::INFO
  }
  @listeners = config[:listeners].map { |lc|
    lc[:listener].new(lc)
  }

  @logger.info("Plum #{::Plum::VERSION}")
  @logger.info("Config: #{config}")
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config


5
6
7
# File 'lib/plum/rack/server.rb', line 5

def config
  @config
end

Instance Method Details

#startObject


22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/plum/rack/server.rb', line 22

def start
  @state = :running
  while @state == :running
    break if @listeners.empty?
    begin
      if ss = IO.select(@listeners, nil, nil, 2.0)
        ss[0].each { |svr|
          new_con(svr)
        }
      end
    rescue Errno::EBADF, Errno::ENOTSOCK, IOError => e # closed
    rescue StandardError => e
      log_exception(e)
    end
  end
end

#stopObject


39
40
41
42
43
# File 'lib/plum/rack/server.rb', line 39

def stop
  @state = :stop
  @listeners.map(&:stop)
  # TODO: gracefully shutdown connections
end