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)
-
- (Libevent) initialize(app, options)
constructor
A new instance of Libevent.
- - (Object) start
- - (Object) stop
Constructor Details
- (Libevent) initialize(app, options)
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
+ (Object) run(app, options)
8 9 10 11 |
# File 'lib/rack/handler/libevent.rb', line 8 def self.run(app, ) server = new(app, ) server.start end |
+ (Object) valid_options
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
- (Object) start
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 |
- (Object) stop
44 45 46 |
# File 'lib/rack/handler/libevent.rb', line 44 def stop @base.exit_loop end |