Class: Plum::Rack::Server
- Inherits:
-
Object
- Object
- Plum::Rack::Server
- Defined in:
- lib/plum/rack/server.rb
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#threadpool ⇒ Object
readonly
Returns the value of attribute threadpool.
Instance Method Summary collapse
-
#initialize(app, config) ⇒ Server
constructor
A new instance of Server.
- #log_exception(e) ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
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 21 |
# 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) } @threadpool = ThreadPool.new(@config[:threadpool_size]) if @config[:threadpool_size] > 1 @logger.info("Plum #{::Plum::VERSION}") @logger.info("Config: #{config}") if @config[:user] drop_privileges end end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
5 6 7 |
# File 'lib/plum/rack/server.rb', line 5 def app @app end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
5 6 7 |
# File 'lib/plum/rack/server.rb', line 5 def config @config end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
5 6 7 |
# File 'lib/plum/rack/server.rb', line 5 def logger @logger end |
#threadpool ⇒ Object (readonly)
Returns the value of attribute threadpool.
5 6 7 |
# File 'lib/plum/rack/server.rb', line 5 def threadpool @threadpool end |
Instance Method Details
#log_exception(e) ⇒ Object
54 55 56 |
# File 'lib/plum/rack/server.rb', line 54 def log_exception(e) @logger.error("#{e.class}: #{e.}\n#{e.backtrace.map { |b| "\t#{b}" }.join("\n")}") end |
#start ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/plum/rack/server.rb', line 23 def start #trap(:INT) { @state = :ee } #require "lineprof" #Lineprof.profile(//){ @state = :running while @state == :running && !@listeners.empty? begin if ss = IO.select(@listeners, nil, nil, 2.0) ss[0].each { |svr| begin svr.accept(self) rescue Errno::ECONNRESET, Errno::ECONNABORTED # closed rescue => e log_exception(e) end } end rescue Errno::EBADF # closed rescue => e log_exception(e) end end #} end |
#stop ⇒ Object
48 49 50 51 52 |
# File 'lib/plum/rack/server.rb', line 48 def stop @state = :stop @listeners.map(&:stop) # TODO: gracefully shutdown connections (wait threadpool?) end |