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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a5a31bd0b3175723b6dfd21d67647b4f1078b98a
|
4
|
+
data.tar.gz: 311d9c3394d5f516847f3dbb72e555ee2770fa41
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
14
|
-
@conn
|
15
|
-
@routes
|
16
|
-
@frames_sender
|
17
|
-
@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
|
-
|
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
|
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.
|
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-
|
11
|
+
date: 2016-09-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|