Class: Rlyeh::Server
- Inherits:
-
Object
- Object
- Rlyeh::Server
- Includes:
- Celluloid::IO, Logger
- Defined in:
- lib/rlyeh/server.rb
Instance Attribute Summary collapse
-
#app_class ⇒ Object
readonly
Returns the value of attribute app_class.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#server ⇒ Object
readonly
Returns the value of attribute server.
-
#sessions ⇒ Object
readonly
Returns the value of attribute sessions.
Instance Method Summary collapse
- #finalize ⇒ Object
- #handle_connection(socket) ⇒ Object
-
#initialize(app_class, options = {}) ⇒ Server
constructor
A new instance of Server.
- #load_session(session_id) ⇒ Object
- #run ⇒ Object
Methods included from Logger
Constructor Details
#initialize(app_class, options = {}) ⇒ Server
Returns a new instance of Server.
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/rlyeh/server.rb', line 13 def initialize(app_class, = {}) @app_class = app_class @options = .dup @host = @options.delete(:host) { '127.0.0.1' } @port = @options.delete(:port) { 46667 } @sessions = {} @server = Celluloid::IO::TCPServer.new @host, @port info "Rlyeh has emerged on #{@host}:#{@port}" async.run end |
Instance Attribute Details
#app_class ⇒ Object (readonly)
Returns the value of attribute app_class.
11 12 13 |
# File 'lib/rlyeh/server.rb', line 11 def app_class @app_class end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
10 11 12 |
# File 'lib/rlyeh/server.rb', line 10 def host @host end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
10 11 12 |
# File 'lib/rlyeh/server.rb', line 10 def @options end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
10 11 12 |
# File 'lib/rlyeh/server.rb', line 10 def port @port end |
#server ⇒ Object (readonly)
Returns the value of attribute server.
11 12 13 |
# File 'lib/rlyeh/server.rb', line 11 def server @server end |
#sessions ⇒ Object (readonly)
Returns the value of attribute sessions.
11 12 13 |
# File 'lib/rlyeh/server.rb', line 11 def sessions @sessions end |
Instance Method Details
#finalize ⇒ Object
25 26 27 28 |
# File 'lib/rlyeh/server.rb', line 25 def finalize @server.close info 'Rlyeh has sunk...' end |
#handle_connection(socket) ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/rlyeh/server.rb', line 37 def handle_connection(socket) connection = Connection.new(self, socket) connection.run rescue Exception => e crash e ensure connection.close rescue nil end |
#load_session(session_id) ⇒ Object
46 47 48 |
# File 'lib/rlyeh/server.rb', line 46 def load_session(session_id) @sessions[session_id] ||= Rlyeh::Session.new(session_id) end |
#run ⇒ Object
30 31 32 33 34 35 |
# File 'lib/rlyeh/server.rb', line 30 def run loop do socket = @server.accept async.handle_connection socket end end |