rakie 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1e8894b95a11cbe14455b61e0df6fbbd6e9e8ded9e6a723ca2a36e9d6d05256d
4
- data.tar.gz: 52d125bf806aacbde166336054a14ddbbc7f2bf5dab097a5050c5339e94e3a86
3
+ metadata.gz: 196e26c710b29918f06ee04e5303caf7f08a1ab989cd6614e36cb469dd3e24b3
4
+ data.tar.gz: 15d0459b668f44c3fe8e9b323a24f8f1c19c647e29ec7a7cd9477615063a6961
5
5
  SHA512:
6
- metadata.gz: 047cf559ae5bd1a4bb90f1ad04c83f9635d2d0368606612917a8a78d1799138167666d768ebd62c84998153a478281c3adc24bcc3071af8146190649e31c3141
7
- data.tar.gz: c2c07ca6562b9631521e4482653a7af948f8f39c20a001f2220dea1a0dfca808473b0b9ffe53b76976aa1962e81a1a1ce2bd1216377ee737acb367a27109c7c7
6
+ metadata.gz: 8f1ac0ed83237b1c57c3c1a58d4b9415602804d92d035ac89238435927efa7f8eb7c29166f0e174bb91bf92b47d63ec47a159c6b8a427b2a280509908acb06cb
7
+ data.tar.gz: 6ebde9c958b93c395b88c30c6ac53eb8418eeb8c9571043d66364b508df148d97456a5b10948993b4b42422324618f1568632287e2e0cf3468d37e53a1b2799a
data/lib/rakie/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Rakie
2
- VERSION = [0, 0, 9]
2
+ VERSION = [0, 0, 10]
3
3
 
4
4
  def self.version_s
5
5
  VERSION.join('.')
@@ -21,64 +21,75 @@ module Rakie
21
21
  @client_side = true
22
22
  end
23
23
 
24
+ # @param [String] data
24
25
  def on_recv(channel, data)
25
26
  Log.debug("Rakie::Websocket recv: #{data}")
26
27
 
27
- # @type [WebsocketMessage] request
28
- message = @recv_message
28
+ total_parsed = 0
29
29
 
30
- if message.parse_status == ParseStatus::COMPLETE
31
- message = WebsocketMessage.new
32
- @recv_message = message
33
- end
30
+ while data.length > 0
31
+ # @type [WebsocketMessage] request
32
+ message = @recv_message
34
33
 
35
- len = message.parse(data)
34
+ if message.parse_status == ParseStatus::COMPLETE
35
+ message = WebsocketMessage.new
36
+ @recv_message = message
37
+ end
36
38
 
37
- Log.debug("Rakie::Websocket receive message: #{message.to_s} parse with #{len}")
39
+ len = message.parse(data)
40
+ total_parsed += len
38
41
 
39
- if message.parse_status == ParseStatus::COMPLETE
40
- response = WebsocketMessage.new
42
+ Log.debug("Rakie::Websocket receive message: #{message.to_s} parse with #{len}")
41
43
 
42
- if message.op_code == WebsocketMessage::OP_PING
43
- response.fin = true
44
- response.op_code = WebsocketMessage::OP_PONG
45
- response.payload = "Rakie::Websocket: op pong"
44
+ if message.parse_status == ParseStatus::COMPLETE
45
+ response = WebsocketMessage.new
46
46
 
47
- elsif message.op_code == WebsocketMessage::OP_PONG
48
- response.fin = true
49
- response.op_code = WebsocketMessage::OP_PING
50
- response.payload = "Rakie::Websocket: op ping"
47
+ if message.op_code == WebsocketMessage::OP_PING
48
+ response.fin = true
49
+ response.op_code = WebsocketMessage::OP_PONG
50
+ response.payload = "Rakie::Websocket: op pong"
51
51
 
52
- elsif message.op_code == WebsocketMessage::OP_CLOSE
53
- channel.close
52
+ elsif message.op_code == WebsocketMessage::OP_PONG
53
+ response.fin = true
54
+ response.op_code = WebsocketMessage::OP_PING
55
+ response.payload = "Rakie::Websocket: op ping"
54
56
 
55
- Log.debug("Rakie::Websocket: op close")
56
- return 0
57
+ elsif message.op_code == WebsocketMessage::OP_CLOSE
58
+ channel.close
57
59
 
58
- elsif @delegate
59
- @delegate.on_message(self, message.payload)
60
- return len
60
+ Log.debug("Rakie::Websocket: op close")
61
+ return 0
61
62
 
62
- else
63
- response.fin = true
64
- response.op_code = WebsocketMessage::OP_TEXT
65
- response.payload = "Rakie!"
66
- end
67
-
68
- response_data = response.to_s
63
+ elsif @delegate
64
+ @delegate.on_message(self, message.payload)
65
+
66
+ else
67
+ response.fin = true
68
+ response.op_code = WebsocketMessage::OP_TEXT
69
+ response.payload = "Rakie!"
70
+ end
71
+
72
+ response_data = response.to_s
69
73
 
70
- Log.debug("Rakie::Websocket response: #{response_data}")
74
+ Log.debug("Rakie::Websocket response: #{response_data}")
71
75
 
72
- channel.write(response_data) # Response data
76
+ channel.write(response_data) # Response data
73
77
 
74
- elsif message.parse_status == ParseStatus::ERROR
75
- channel.close
78
+ elsif message.parse_status == ParseStatus::ERROR
79
+ channel.close
80
+
81
+ Log.debug("Rakie::Websocket: Illegal message")
82
+ return 0
83
+ end
84
+
85
+ if len >= data.length
86
+ break
87
+ end
76
88
 
77
- Log.debug("Rakie::Websocket: Illegal message")
78
- return 0
89
+ data = data[len .. -1]
79
90
  end
80
91
 
81
- return len
92
+ return total_parsed
82
93
  end
83
94
 
84
95
  def on_send(channel)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rakie
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jakit Liang