rakie 0.0.7 → 0.0.12
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 +15 -5
- data/lib/rakie/version.rb +1 -1
- data/lib/rakie/websocket.rb +59 -39
- data/lib/rakie/websocket_server.rb +6 -3
- 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: 00b8c6d360d53843cc4a28aa5e80bb8f94f1e53998bf3b12a5046460cd44bbd0
|
4
|
+
data.tar.gz: 237700881bef3c7d7036c76ab206e54f46b48b795631d20241bfeeca8ed382a4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b485134bc665bfbccf116fe0978d6e7689cd334585c5d511f485dcbf2820c7cfd131e224c9b238024ea6e575ec76dffbde6aab9ea21bddfdd6a1a6cfb416a54d
|
7
|
+
data.tar.gz: 4a76980dc7f5229dc428facbb72ee8c719b4d6e815b2418135731f1d87658ccec4bef90e3989dfab2cbd5d1626689b9a96f793d2f394a1ef0c3e84c9267783ea
|
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)
|
@@ -104,15 +107,20 @@ module Rakie
|
|
104
107
|
end
|
105
108
|
|
106
109
|
def on_detach(io)
|
110
|
+
if io.closed?
|
111
|
+
return
|
112
|
+
end
|
113
|
+
|
107
114
|
begin
|
108
115
|
io.close
|
109
116
|
|
110
|
-
if @delegate
|
111
|
-
@delegate.on_close(self)
|
112
|
-
end
|
113
|
-
|
114
117
|
rescue
|
115
118
|
Log.debug("Channel is already closed")
|
119
|
+
return
|
120
|
+
end
|
121
|
+
|
122
|
+
if @delegate
|
123
|
+
@delegate.on_close(self)
|
116
124
|
end
|
117
125
|
|
118
126
|
Log.debug("Channel close ok")
|
@@ -141,6 +149,8 @@ module Rakie
|
|
141
149
|
@write_buffer << data
|
142
150
|
@write_task << data.length
|
143
151
|
|
152
|
+
Log.debug("write buffer append size: #{data.length}")
|
153
|
+
|
144
154
|
Event.modify(@io, self, (Event::READ_EVENT | Event::WRITE_EVENT))
|
145
155
|
|
146
156
|
return 0
|
data/lib/rakie/version.rb
CHANGED
data/lib/rakie/websocket.rb
CHANGED
@@ -21,58 +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
|
-
|
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 = "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
|
-
|
54
|
-
|
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"
|
55
56
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
57
|
+
elsif message.op_code == WebsocketMessage::OP_CLOSE
|
58
|
+
channel.close
|
59
|
+
|
60
|
+
Log.debug("Rakie::Websocket: op close")
|
61
|
+
return 0
|
62
|
+
|
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
|
63
73
|
|
64
|
-
|
74
|
+
# Log.debug("Rakie::Websocket response: #{response_data}")
|
65
75
|
|
66
|
-
|
76
|
+
# channel.write(response_data) # Response data
|
67
77
|
|
68
|
-
|
69
|
-
|
78
|
+
elsif message.parse_status == ParseStatus::CONTINUE
|
79
|
+
break
|
80
|
+
|
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
|
70
91
|
|
71
|
-
|
72
|
-
return len
|
92
|
+
data = data[len .. -1]
|
73
93
|
end
|
74
94
|
|
75
|
-
return
|
95
|
+
return total_parsed
|
76
96
|
end
|
77
97
|
|
78
98
|
def on_send(channel)
|
@@ -109,9 +129,9 @@ module Rakie
|
|
109
129
|
end
|
110
130
|
|
111
131
|
send_message = ws_message.to_s
|
112
|
-
@send_messages <<
|
132
|
+
@send_messages << ws_message
|
113
133
|
|
114
|
-
Log.debug("Rakie::Websocket send: #{send_message}")
|
134
|
+
Log.debug("Rakie::Websocket send: #{send_message} with #{send_message.length}")
|
115
135
|
|
116
136
|
@channel.write(send_message) # Response data
|
117
137
|
end
|
@@ -135,4 +155,4 @@ module Rakie
|
|
135
155
|
@channel.write(send_message) # Response data
|
136
156
|
end
|
137
157
|
end
|
138
|
-
end
|
158
|
+
end
|
@@ -5,7 +5,7 @@ module Rakie
|
|
5
5
|
@delegate = delegate
|
6
6
|
|
7
7
|
if http_server == nil
|
8
|
-
http_server = HttpServer.new(host, port)
|
8
|
+
http_server = HttpServer.new(host: host, port: port)
|
9
9
|
end
|
10
10
|
|
11
11
|
@host = http_server.host
|
@@ -26,7 +26,6 @@ module Rakie
|
|
26
26
|
|
27
27
|
if @delegate
|
28
28
|
@delegate.on_connect(ws_client)
|
29
|
-
return
|
30
29
|
end
|
31
30
|
|
32
31
|
@clients[channel] = ws_client
|
@@ -52,8 +51,10 @@ module Rakie
|
|
52
51
|
client = @clients[channel]
|
53
52
|
|
54
53
|
if client
|
55
|
-
client.on_recv(channel, data)
|
54
|
+
return client.on_recv(channel, data)
|
56
55
|
end
|
56
|
+
|
57
|
+
return data.length
|
57
58
|
end
|
58
59
|
|
59
60
|
def on_send(channel)
|
@@ -70,6 +71,8 @@ module Rakie
|
|
70
71
|
if client
|
71
72
|
client.on_close(channel)
|
72
73
|
end
|
74
|
+
|
75
|
+
@clients.delete(channel)
|
73
76
|
end
|
74
77
|
|
75
78
|
def send(message, is_binary=false); 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.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jakit Liang
|
@@ -52,7 +52,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
52
52
|
- !ruby/object:Gem::Version
|
53
53
|
version: '0'
|
54
54
|
requirements: []
|
55
|
-
rubygems_version: 3.
|
55
|
+
rubygems_version: 3.0.9
|
56
56
|
signing_key:
|
57
57
|
specification_version: 4
|
58
58
|
summary: Rakie!
|