Class: Rack::Handler::Libevent
- Inherits:
-
Object
- Object
- Rack::Handler::Libevent
- Defined in:
- lib/rack/handler/libevent.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(app, options) ⇒ Libevent
constructor
A new instance of Libevent.
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(app, options) ⇒ Libevent
Returns a new instance of Libevent.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/rack/handler/libevent.rb', line 19 def initialize(app, ) @app = app [:Host] or raise ArgumentError, "Host option required" [:Port] or raise ArgumentError, "Port option required" @host = [:Host] @port = [:Port].to_i @base = ::Libevent::Base.new @http = ::Libevent::Http.new(@base) @http.set_timeout([:timeout].to_i) if [:timeout] end |
Class Method Details
.run(app, options) ⇒ Object
8 9 10 11 |
# File 'lib/rack/handler/libevent.rb', line 8 def self.run(app, ) server = new(app, ) server.start end |
.valid_options ⇒ Object
13 14 15 16 17 |
# File 'lib/rack/handler/libevent.rb', line 13 def self. { "timeout=TIMEOUT" => "Set the timeout for an HTTP request" } end |
Instance Method Details
#start ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/rack/handler/libevent.rb', line 34 def start @http.bind_socket(@host, @port) or raise RuntimeError, "Can't bind to #{@host}:#{@port}" @http.set_request_handler(self.method(:process)) @base.trap_signal("INT") { self.stop } @base.trap_signal("TERM") { self.stop } @base.dispatch end |
#stop ⇒ Object
44 45 46 |
# File 'lib/rack/handler/libevent.rb', line 44 def stop @base.exit_loop end |