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 +4 -4
- data/lib/rakie/channel.rb +6 -1
- data/lib/rakie/version.rb +2 -2
- data/lib/rakie/websocket.rb +55 -41
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 23af26094d9055fb8b5fab629f98da38db5d8c131839ba9bc895985bf8c7fee1
|
4
|
+
data.tar.gz: ae7faaa4fb5169c9c94734dc19120e3c0048fbefccfca9910cf42dfe92ce0986
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
data/lib/rakie/websocket.rb
CHANGED
@@ -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
|
-
|
28
|
-
message = @recv_message
|
28
|
+
total_parsed = 0
|
29
29
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
end
|
30
|
+
while data.length > 0
|
31
|
+
# @type [WebsocketMessage] request
|
32
|
+
message = @recv_message
|
34
33
|
|
35
|
-
|
34
|
+
if message.parse_status == ParseStatus::COMPLETE
|
35
|
+
message = WebsocketMessage.new
|
36
|
+
@recv_message = message
|
37
|
+
end
|
36
38
|
|
37
|
-
|
39
|
+
len = message.parse(data)
|
40
|
+
total_parsed += len
|
38
41
|
|
39
|
-
|
40
|
-
response = WebsocketMessage.new
|
42
|
+
Log.debug("Rakie::Websocket receive message: #{message.payload} parse with #{len}")
|
41
43
|
|
42
|
-
if message.
|
43
|
-
response
|
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
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
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
|
-
|
53
|
-
|
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
|
-
|
56
|
-
|
57
|
+
elsif message.op_code == WebsocketMessage::OP_CLOSE
|
58
|
+
channel.close
|
57
59
|
|
58
|
-
|
59
|
-
|
60
|
-
return len
|
60
|
+
Log.debug("Rakie::Websocket: op close")
|
61
|
+
return 0
|
61
62
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
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
|
-
|
76
|
+
# channel.write(response_data) # Response data
|
71
77
|
|
72
|
-
|
78
|
+
elsif message.parse_status == ParseStatus::CONTINUE
|
79
|
+
break
|
73
80
|
|
74
|
-
|
75
|
-
|
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
|
-
|
78
|
-
return 0
|
92
|
+
data = data[len .. -1]
|
79
93
|
end
|
80
94
|
|
81
|
-
return
|
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.
|
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:
|
48
|
+
version: 2.4.9
|
49
49
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
50
|
requirements:
|
51
51
|
- - ">="
|