rakie 0.0.9 → 0.0.13

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: 23af26094d9055fb8b5fab629f98da38db5d8c131839ba9bc895985bf8c7fee1
4
+ data.tar.gz: ae7faaa4fb5169c9c94734dc19120e3c0048fbefccfca9910cf42dfe92ce0986
5
5
  SHA512:
6
- metadata.gz: 047cf559ae5bd1a4bb90f1ad04c83f9635d2d0368606612917a8a78d1799138167666d768ebd62c84998153a478281c3adc24bcc3071af8146190649e31c3141
7
- data.tar.gz: c2c07ca6562b9631521e4482653a7af948f8f39c20a001f2220dea1a0dfca808473b0b9ffe53b76976aa1962e81a1a1ce2bd1216377ee737acb367a27109c7c7
6
+ metadata.gz: db445b01be6bc431e9763727063ebc2d2af4dbd034e49fa88cd7cd75c308accebbb6396de5fa922f591ae3b1c415b20ffbaf57d99cfd5249135fc0e77d454730
7
+ data.tar.gz: 894d32ec5f179daefc28a377391cff7bd72321d73fa974f95227c07908d498009504fa0e1a24171e70b3daaa4bfc5f9e2df8f020e307a134b94876805ba7b50a
data/lib/rakie/channel.rb CHANGED
@@ -56,6 +56,7 @@ module Rakie
56
56
  while len > 0
57
57
  if len < task
58
58
  @write_task[0] = task - len
59
+ return
59
60
  end
60
61
 
61
62
  len -= task
@@ -65,6 +66,8 @@ module Rakie
65
66
  @delegate.on_send(self)
66
67
  Log.debug("Channel handle on_send")
67
68
  end
69
+
70
+ task = @write_task[0]
68
71
  end
69
72
  end
70
73
 
@@ -79,7 +82,7 @@ module Rakie
79
82
  @write_buffer = @write_buffer[len .. -1]
80
83
  end
81
84
 
82
- Log.debug("Channel write finished")
85
+ Log.debug("Channel write #{len} bytes finished")
83
86
 
84
87
  rescue IO::EAGAINWaitWritable
85
88
  self.handle_write(offset)
@@ -146,6 +149,8 @@ module Rakie
146
149
  @write_buffer << data
147
150
  @write_task << data.length
148
151
 
152
+ Log.debug("write buffer append size: #{data.length}")
153
+
149
154
  Event.modify(@io, self, (Event::READ_EVENT | Event::WRITE_EVENT))
150
155
 
151
156
  return 0
data/lib/rakie/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Rakie
2
- VERSION = [0, 0, 9]
2
+ VERSION = [0, 0, 13]
3
3
 
4
4
  def self.version_s
5
5
  VERSION.join('.')
@@ -8,4 +8,4 @@ module Rakie
8
8
  def self.full_version_s
9
9
  "#{NAME} v#{self.version_s}"
10
10
  end
11
- end
11
+ end
@@ -21,64 +21,78 @@ module Rakie
21
21
  @client_side = true
22
22
  end
23
23
 
24
+ # @param [String] data
24
25
  def on_recv(channel, data)
25
- Log.debug("Rakie::Websocket recv: #{data}")
26
+ Log.debug("Rakie::Websocket recv len: #{data.length}")
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.payload} 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
73
+
74
+ # Log.debug("Rakie::Websocket response: #{response_data}")
69
75
 
70
- Log.debug("Rakie::Websocket response: #{response_data}")
76
+ # channel.write(response_data) # Response data
71
77
 
72
- channel.write(response_data) # Response data
78
+ elsif message.parse_status == ParseStatus::CONTINUE
79
+ break
73
80
 
74
- elsif message.parse_status == ParseStatus::ERROR
75
- channel.close
81
+ elsif message.parse_status == ParseStatus::ERROR
82
+ channel.close
83
+
84
+ Log.debug("Rakie::Websocket: Illegal message")
85
+ return 0
86
+ end
87
+
88
+ if len >= data.length
89
+ break
90
+ end
76
91
 
77
- Log.debug("Rakie::Websocket: Illegal message")
78
- return 0
92
+ data = data[len .. -1]
79
93
  end
80
94
 
81
- return len
95
+ return total_parsed
82
96
  end
83
97
 
84
98
  def on_send(channel)
@@ -117,7 +131,7 @@ module Rakie
117
131
  send_message = ws_message.to_s
118
132
  @send_messages << ws_message
119
133
 
120
- Log.debug("Rakie::Websocket send: #{send_message}")
134
+ Log.debug("Rakie::Websocket send: #{send_message} with #{send_message.length}")
121
135
 
122
136
  @channel.write(send_message) # Response data
123
137
  end
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.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jakit Liang
@@ -45,7 +45,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
45
45
  requirements:
46
46
  - - ">"
47
47
  - !ruby/object:Gem::Version
48
- version: '2.5'
48
+ version: 2.4.9
49
49
  required_rubygems_version: !ruby/object:Gem::Requirement
50
50
  requirements:
51
51
  - - ">="