Sha256: 7601b277e4ec30855fca2b4535e4c01dfbe2d662f47f59de4b6fc9c4e162452d
Contents?: true
Size: 1.65 KB
Versions: 3
Compression:
Stored size: 1.65 KB
Contents
## # Abstract runner class to control instance of Midori Server # @attr [String] bind the address to bind # @attr [Integer] port the port to bind class Midori::Runner attr_reader :bind, :port # Define status of a runner # @param [Class] api inherited from [Midori::API] # @param [Class] configure inherited from [Midori::Configure] def initialize(api, configure = Midori::Configure) @logger = configure.logger @bind = configure.bind @port = configure.port @api = ((api.is_a?Midori::APIEngine) ? api : Midori::APIEngine.new(api, configure.route_type)) end # Get Midori server whether running # @return [Boolean] [true] running # @return [Boolean] [false] not running def running? !!@server end # Start the Midori server # @note This is an async method, but no callback def start return false if running? || EventLoop.running? @logger.info "Midori #{Midori::VERSION} is now running on #{bind}:#{port}".blue @server = TCPServer.new(@bind, @port) EventLoop.register(@server, :r) do |monitor| socket = monitor.io.accept_nonblock connection = Midori::Connection.new(socket) connection.server_initialize(@api, @logger) end EventLoop.start nil end # Stop the Midori server # @note This is an async method, but no callback # @return [Boolean] [true] stop successfully # @return [Boolean] [false] nothing to stop def stop if running? @logger.info 'Stopping Midori'.blue EventLoop.unregister @server @server.close @server = nil EventLoop.stop true else @logger.error 'Midori Server has NOT been started'.red false end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
em-midori-0.1.11 | lib/midori/runner.rb |
em-midori-0.1.10 | lib/midori/runner.rb |
em-midori-0.1.9 | lib/midori/runner.rb |