web_socket_rb 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: eb1f89b03d703f0ccb4d4993b3b291ea198c9ab1
4
- data.tar.gz: 55820c722b44c2a238fdea8c859df4804cf9859d
3
+ metadata.gz: a5a31bd0b3175723b6dfd21d67647b4f1078b98a
4
+ data.tar.gz: 311d9c3394d5f516847f3dbb72e555ee2770fa41
5
5
  SHA512:
6
- metadata.gz: 8703dd1ab0f52f1c2b58b5360f3a6a32675e761106fd3d99e5a04793a9da18482a751ecc34cf17e1b6ca433ae6886f4c115594b8de28531362208761b11e1a27
7
- data.tar.gz: 5ac78d00af0af664721ba5a11c5111aaa34176b386e1b4e41f3f0e8b38436f531ac7eb88eebcc534816af435ed6c22852692bcab37875ee44c032e004cfc9158
6
+ metadata.gz: 357c47fbe3a6cbc61e9aa427110c7ab586fabfde8cd4f7e98e4825c6a1089bfa7ed721530aba4c3e24e5016dae4e4a724038f96f9955ef55eda1dbf0ea7b24f7
7
+ data.tar.gz: 61ffed8eb50ad360b0ab5c1feafe006bd9b7eb8c6044d8c7f34044df1616671b364ea5e1fbcbcdf80c0dd93545ee7949fb0ef319636ee8c089d3129119d7c5e7
@@ -10,12 +10,14 @@ module WebSocketRb
10
10
  module Protocol
11
11
  class FramesHandler
12
12
  def initialize(connections, connection, routes, frames_sender, sandbox)
13
- @connections = connections
14
- @conn = connection
15
- @routes = routes
16
- @frames_sender = frames_sender
17
- @sandbox = sandbox
18
- @threads = []
13
+ @connections = connections
14
+ @conn = connection
15
+ @routes = routes
16
+ @frames_sender = frames_sender
17
+ @sandbox = sandbox
18
+ @threads = []
19
+ @pending_pings = []
20
+ @mutex = Mutex.new
19
21
  end
20
22
 
21
23
  # Run reading and sending frames
@@ -32,7 +34,9 @@ module WebSocketRb
32
34
  loop do
33
35
  frame = Service::BuildPingFrameService.new.run
34
36
  @frames_sender.frame_to_send(frame)
37
+ @mutex.synchronize { @pending_pings << frame }
35
38
  sleep(10)
39
+ @mutex.synchronize { @threads.reverse.each(&:kill) if @pending_pings.include?(frame) }
36
40
  end
37
41
  end
38
42
 
@@ -62,7 +66,16 @@ module WebSocketRb
62
66
  @threads.each(&:exit)
63
67
 
64
68
  elsif frame.pong?
65
- # Do nothing
69
+
70
+ # Verify pending PINGs and find one with the same payload data
71
+ App.logger.info('Frames handler') {'Verifying PINGS'}
72
+ @mutex.synchronize do
73
+ pending_ping = @pending_pings.reject! do |ping_frame|
74
+ frame.payload_data == ping_frame.payload_data
75
+ end
76
+ @threads.each(&:exit) if pending_ping.nil?
77
+ end
78
+
66
79
  elsif frame.text? || frame.binary?
67
80
 
68
81
  # Call subscribe block
@@ -44,7 +44,6 @@ module WebSocketRb
44
44
  @conn.puts('Upgrade: websocket')
45
45
  @conn.puts('Connection: Upgrade')
46
46
  @conn.puts("Sec-WebSocket-Accept: #{calculate_key(request.key)}")
47
- # @conn.puts("Sec-WebSocket-Protocol: #{Wrapper::HandshakeRequest::PROTOCOL}")
48
47
  @conn.puts('')
49
48
  App.logger.info('Handshake') { 'Finished sending accept response' }
50
49
  end
@@ -1,3 +1,3 @@
1
1
  module WebSocketRb
2
- VERSION = '0.1.1'.freeze
2
+ VERSION = '0.1.2'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: web_socket_rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Karol Bajko
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-09-27 00:00:00.000000000 Z
11
+ date: 2016-09-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler