Class: Stenohttp2::Server::Handler
- Inherits:
-
Object
- Object
- Stenohttp2::Server::Handler
- Extended by:
- Forwardable
- Defined in:
- lib/stenohttp2/server/handler.rb
Constant Summary collapse
- SERVER_PING_DELAY =
0.05
Instance Method Summary collapse
-
#initialize(socket) ⇒ Handler
constructor
A new instance of Handler.
- #setup ⇒ Object
Constructor Details
#initialize(socket) ⇒ Handler
Returns a new instance of Handler.
12 13 14 15 |
# File 'lib/stenohttp2/server/handler.rb', line 12 def initialize(socket) @socket = socket @connection = ::HTTP2::Server.new end |
Instance Method Details
#setup ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/stenohttp2/server/handler.rb', line 17 def setup connection.on(:frame) do |bytes| socket.is_a?(TCPSocket) ? socket.sendmsg(bytes) : socket.write(bytes) end # Here is where the magic happens: we treat PING frames a bit # differently than in a usual flow, where those would be used only to # check stream/connection latency connection.on(:frame_received) do |frame| ping_handler.handle(frame) if ping_handler.responding? sender(connection).call ping_handler.done end end # We still want to handle streaming for regular communication, like # sending html content connection.on(:stream) { |s| ::Stenohttp2::Server::StreamHandler.new(s).setup } connection end |