Class: Pixelflut::Server
- Inherits:
-
Object
- Object
- Pixelflut::Server
- Defined in:
- lib/pixelflut/server.rb,
lib/pixelflut/server/connection.rb,
lib/pixelflut/server/configuration.rb
Defined Under Namespace
Classes: Configuration
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
- #connection_count ⇒ Object
-
#initialize(canvas, config = Configuration.default) ⇒ Server
constructor
A new instance of Server.
- #run ⇒ Object
- #update ⇒ Object
Constructor Details
#initialize(canvas, config = Configuration.default) ⇒ Server
Returns a new instance of Server.
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/pixelflut/server.rb', line 11 def initialize(canvas, config = Configuration.default) @canvas, @config = canvas, config @socket, @connections = nil, {} @peers = Hash.new{ |h, k| h[k] = 0 } @ccfg = Connection::Configuration.new( keep_alive_time: config.keep_alive_time, read_buffer_size: config.read_buffer_size, command_limit: config.command_limit, canvas: canvas, size_result: "SIZE #{canvas.width} #{canvas.height}\n".freeze, on_end: ->(conn){ @peers[conn.peeraddr] -= 1 if @connections.delete(conn) } ).freeze end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
9 10 11 |
# File 'lib/pixelflut/server.rb', line 9 def config @config end |
Instance Method Details
#connection_count ⇒ Object
25 26 27 |
# File 'lib/pixelflut/server.rb', line 25 def connection_count @connections.size end |
#run ⇒ Object
36 37 38 39 40 |
# File 'lib/pixelflut/server.rb', line 36 def run Thread.new do loop{ update } end end |
#update ⇒ Object
29 30 31 32 33 34 |
# File 'lib/pixelflut/server.rb', line 29 def update return create_socket unless @socket incoming = @socket.accept_nonblock(exception: false) create_connection(incoming) unless Symbol === incoming @connections.keys.each(&:update) end |