Class: Stenohttp2::Server::Server
- Inherits:
-
Object
- Object
- Stenohttp2::Server::Server
- Extended by:
- T::Sig
- Defined in:
- lib/stenohttp2/server/server.rb
Constant Summary collapse
- BUFFER_SIZE =
1024
Instance Method Summary collapse
-
#initialize(url:) ⇒ Server
constructor
A new instance of Server.
-
#start ⇒ Object
rubocop:disable Metrics/AbcSize.
Constructor Details
#initialize(url:) ⇒ Server
Returns a new instance of Server.
15 16 17 18 19 |
# File 'lib/stenohttp2/server/server.rb', line 15 def initialize(url:) @url = url @port = @url.port @server = ServerFactory.new(@port).start end |
Instance Method Details
#start ⇒ Object
rubocop:disable Metrics/AbcSize
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/stenohttp2/server/server.rb', line 22 def start log.info "Server listening on #{url}" loop do client_connection = server.accept Thread.start(client_connection) do |connection| connection_handler = ::Stenohttp2::Server::Handler.new(connection).setup while !connection.closed? && !(begin connection.eof? rescue StandardError true end) data = connection.readpartial(BUFFER_SIZE) begin connection_handler.receive(data) rescue StandardError => e log.error "#{e.class} exception: #{e.} - closing connectionet." T.must(e.backtrace).each { |l| puts "\t#{l}" } connection.close end end end.join end end |