Class: Librevox::Server
- Inherits:
-
Object
- Object
- Librevox::Server
- Defined in:
- lib/librevox/server.rb
Instance Attribute Summary collapse
-
#endpoint ⇒ Object
readonly
Returns the value of attribute endpoint.
Instance Method Summary collapse
- #accept(socket, _address) ⇒ Object
-
#initialize(handler, endpoint) ⇒ Server
constructor
A new instance of Server.
- #run ⇒ Object
Constructor Details
#initialize(handler, endpoint) ⇒ Server
Returns a new instance of Server.
7 8 9 10 |
# File 'lib/librevox/server.rb', line 7 def initialize(handler, endpoint) @handler = handler @endpoint = endpoint end |
Instance Attribute Details
#endpoint ⇒ Object (readonly)
Returns the value of attribute endpoint.
12 13 14 |
# File 'lib/librevox/server.rb', line 12 def endpoint @endpoint end |
Instance Method Details
#accept(socket, _address) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/librevox/server.rb', line 14 def accept(socket, _address) stream = IO::Stream(socket) connection = Protocol::Connection.new(stream) listener = @handler.new(connection) session_task = Async { listener.run_session } connection.read_loop { |msg| listener.(msg) } rescue => e Librevox.logger.error "Session error: #{e.full_message}" ensure session_task&.stop connection&.close end |
#run ⇒ Object
29 30 31 32 33 34 |
# File 'lib/librevox/server.rb', line 29 def run Async do |task| @endpoint.accept(&method(:accept)) task.children.each(&:wait) end end |