Class: Pronghorn::Server
- Inherits:
-
Object
- Object
- Pronghorn::Server
- Defined in:
- lib/pronghorn/server.rb
Instance Attribute Summary collapse
-
#app ⇒ Object
Returns the value of attribute app.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
Instance Method Summary collapse
- #finish_connection(connection) ⇒ Object
-
#initialize(app, &block) ⇒ Server
constructor
A new instance of Server.
- #start(host, port) ⇒ Object
- #stop ⇒ Object
Constructor Details
Instance Attribute Details
#app ⇒ Object
Returns the value of attribute app.
4 5 6 |
# File 'lib/pronghorn/server.rb', line 4 def app @app end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
6 7 8 |
# File 'lib/pronghorn/server.rb', line 6 def host @host end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
8 9 10 |
# File 'lib/pronghorn/server.rb', line 8 def port @port end |
Instance Method Details
#finish_connection(connection) ⇒ Object
49 50 51 |
# File 'lib/pronghorn/server.rb', line 49 def finish_connection(connection) @connections.delete(connection) end |
#start(host, port) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/pronghorn/server.rb', line 16 def start(host, port) @host = host @port = port starter = proc do @signature = EventMachine.start_server @host, @port, Connection, &method(:initialize_connection) @running = true end Signal.trap("INT") { stop } Signal.trap("TERM") { stop } puts "Proghorn #{::Pronghorn::VERSION} starting..." puts "* Listening on http://#{@host}:#{@port} *" EventMachine.error_handler{ |error| puts error. } if EventMachine.reactor_running? starter.call else EventMachine.run(&starter) end end |
#stop ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/pronghorn/server.rb', line 41 def stop puts "* Stopping server *" return unless @running @running = false EventMachine.stop_server(@signature) EventMachine.stop if EventMachine.reactor_running? end |