Class: Stenohttp2::Server::PingHandler
- Inherits:
-
Object
- Object
- Stenohttp2::Server::PingHandler
- Defined in:
- lib/stenohttp2/server/ping_handler.rb
Constant Summary collapse
- TIMESTAMP_FORMAT =
'%Y-%m-%d-%H-%M'.freeze
- IDENTIFIERS =
[ ENV.fetch('SERVER_IDENTIFIER'), ::Stenohttp2::Client::Client::CLIENT_IDENTIFIER ].freeze
Instance Attribute Summary collapse
-
#file ⇒ Object
Returns the value of attribute file.
-
#messages_left ⇒ Object
Returns the value of attribute messages_left.
-
#payload ⇒ Object
Returns the value of attribute payload.
-
#send_response ⇒ Object
Returns the value of attribute send_response.
Instance Method Summary collapse
-
#handle(frame) ⇒ Object
rubocop:disable Metrics/AbcSize.
-
#initialize(server: true) ⇒ PingHandler
constructor
A new instance of PingHandler.
-
#read_or_create_file ⇒ Object
rubocop:enable Metrics/AbcSize.
Constructor Details
#initialize(server: true) ⇒ PingHandler
Returns a new instance of PingHandler.
46 47 48 49 50 51 52 |
# File 'lib/stenohttp2/server/ping_handler.rb', line 46 def initialize(server: true) @server = server @messages_left = 0 @file = nil @payload = nil super() end |
Instance Attribute Details
#file ⇒ Object
Returns the value of attribute file.
12 13 14 |
# File 'lib/stenohttp2/server/ping_handler.rb', line 12 def file @file end |
#messages_left ⇒ Object
Returns the value of attribute messages_left.
12 13 14 |
# File 'lib/stenohttp2/server/ping_handler.rb', line 12 def @messages_left end |
#payload ⇒ Object
Returns the value of attribute payload.
12 13 14 |
# File 'lib/stenohttp2/server/ping_handler.rb', line 12 def payload @payload end |
#send_response ⇒ Object
Returns the value of attribute send_response.
12 13 14 |
# File 'lib/stenohttp2/server/ping_handler.rb', line 12 def send_response @send_response end |
Instance Method Details
#handle(frame) ⇒ Object
rubocop:disable Metrics/AbcSize
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/stenohttp2/server/ping_handler.rb', line 55 def handle(frame) # We are only interested in PING farmes without ACK flag # because the ones with ACK include just the repeated contend return unless frame[:type] == :ping && !frame[:flags].include?(:ack) self.payload = frame[:payload] start_reciving and return if IDENTIFIERS.include?(payload) return if waiting? consume_count and return unless count_consumed? if .positive? file.write(payload) end return unless .zero? file.close ready_to_respond end |
#read_or_create_file ⇒ Object
rubocop:enable Metrics/AbcSize
80 81 82 83 84 |
# File 'lib/stenohttp2/server/ping_handler.rb', line 80 def read_or_create_file return unless file.nil? self.file = File.open(file_name, 'a') end |