drb-websocket 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/drb/websocket.rb +27 -23
- data/lib/drb/websocket/rack_app.rb +9 -14
- data/lib/drb/websocket/server.rb +9 -5
- data/lib/drb/websocket/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f5f989e53a1e77689135c986a7e50e88d7624df6
|
4
|
+
data.tar.gz: d1b5c5e1ff6c7a835652e8ce69abf98337eb6a2b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7dfee7db6bd60abfa61a095a75b2a9c8546ccd4b1cf28d0e4fb01fe75ad9b62a341e534d5c44eb5ad51d39f82616f3fe5bd38e37d163c4561ad6b76805f8b8e0
|
7
|
+
data.tar.gz: d71444cee9c8b450555d8bbaac5342e3efbafc5bc63e2cd1093466ff24b55fd9de8d05cc3d3a378a36a1ec313ca9d4312e96075c8298dbe830678697fdc1f59a
|
data/lib/drb/websocket.rb
CHANGED
@@ -35,16 +35,14 @@ module DRb
|
|
35
35
|
raise(DRbBadURI, 'can\'t parse uri: ' + uri)
|
36
36
|
end
|
37
37
|
|
38
|
-
path = $4
|
38
|
+
path, uuid = $4.split('/')
|
39
39
|
|
40
|
-
|
41
|
-
if path == 'callback'
|
42
|
-
callback_handler = CallbackHandler.new(uri)
|
43
|
-
RackApp.register(uri, callback_handler)
|
44
|
-
elsif path != nil
|
40
|
+
unless path.nil? || path == 'callback'
|
45
41
|
raise(DRbBadURI, 'can\'t parse uri: ' + uri)
|
46
42
|
end
|
47
43
|
|
44
|
+
handler = RackApp.handler(uri)
|
45
|
+
callback_handler = handler if CallbackHandler === handler
|
48
46
|
ClientSide.new(uri, config, callback_handler)
|
49
47
|
end
|
50
48
|
|
@@ -58,15 +56,18 @@ module DRb
|
|
58
56
|
sio = StrStream.new
|
59
57
|
sio.write(data.pack('C*'))
|
60
58
|
@queue.push sio
|
61
|
-
nil
|
62
59
|
end
|
63
60
|
|
64
|
-
def
|
61
|
+
def on_session_start(ws)
|
62
|
+
@ws = ws
|
63
|
+
end
|
64
|
+
|
65
|
+
def stream
|
65
66
|
@queue.pop
|
66
67
|
end
|
67
68
|
|
68
|
-
def send(data)
|
69
|
-
|
69
|
+
def send(url, data)
|
70
|
+
@ws.send(data.bytes)
|
70
71
|
end
|
71
72
|
end
|
72
73
|
|
@@ -78,6 +79,7 @@ module DRb
|
|
78
79
|
@msg = DRbMessage.new(config)
|
79
80
|
@proxy = ENV['HTTP_PROXY']
|
80
81
|
@handler = handler
|
82
|
+
@queue = Thread::Queue.new
|
81
83
|
end
|
82
84
|
|
83
85
|
def close
|
@@ -91,19 +93,22 @@ module DRb
|
|
91
93
|
stream = StrStream.new
|
92
94
|
@msg.send_request(stream, ref, msg_id, *arg, &b)
|
93
95
|
if @handler
|
94
|
-
@handler.send(stream.buf)
|
96
|
+
@handler.send(@uri, stream.buf)
|
95
97
|
else
|
96
98
|
send(@uri, stream.buf)
|
97
99
|
end
|
98
100
|
end
|
99
101
|
|
100
102
|
def recv_reply
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
103
|
+
Thread.start do
|
104
|
+
@reply_stream = @handler.stream if @handler
|
105
|
+
|
106
|
+
begin
|
107
|
+
@msg.recv_reply(@reply_stream)
|
108
|
+
rescue
|
109
|
+
close
|
110
|
+
raise $!
|
111
|
+
end
|
107
112
|
end
|
108
113
|
end
|
109
114
|
|
@@ -113,23 +118,22 @@ module DRb
|
|
113
118
|
path = [(it.path=='' ? '/' : it.path), it.query].compact.join('?')
|
114
119
|
|
115
120
|
EM.run do
|
116
|
-
|
117
|
-
@ws = Faye::WebSocket::Client.new(uri + path)
|
121
|
+
ws = Faye::WebSocket::Client.new(uri + path)
|
118
122
|
|
119
|
-
|
123
|
+
ws.on :message do |event|
|
124
|
+
sio = StrStream.new
|
120
125
|
sio.write(event.data.pack('C*'))
|
121
126
|
|
122
127
|
if @config[:load_limit] < sio.buf.size
|
123
128
|
raise TypeError, 'too large packet'
|
124
129
|
end
|
125
130
|
|
126
|
-
|
127
|
-
@ws.close
|
131
|
+
ws.close
|
128
132
|
|
129
133
|
EM.stop
|
130
134
|
end
|
131
135
|
|
132
|
-
|
136
|
+
ws.send(data.bytes)
|
133
137
|
end
|
134
138
|
end
|
135
139
|
end
|
@@ -7,20 +7,14 @@ module DRb
|
|
7
7
|
end
|
8
8
|
|
9
9
|
@handlers = {}
|
10
|
-
@sockets = {}
|
11
10
|
|
12
11
|
def self.handler(key)
|
13
12
|
@handlers[key]
|
14
13
|
end
|
15
14
|
|
16
|
-
def self.sockets
|
17
|
-
@sockets
|
18
|
-
end
|
19
|
-
|
20
15
|
def self.close(key)
|
21
|
-
if @
|
22
|
-
@
|
23
|
-
@sockets.delete(key)
|
16
|
+
if @handlers.has_key?(key)
|
17
|
+
@handlers.delete(key)
|
24
18
|
end
|
25
19
|
end
|
26
20
|
|
@@ -33,17 +27,18 @@ module DRb
|
|
33
27
|
ws = Faye::WebSocket.new(env)
|
34
28
|
req = Rack::Request.new(env)
|
35
29
|
uri = "ws://#{req.host}:#{req.port}#{req.path == '/' ? nil : req.path}"
|
36
|
-
|
30
|
+
|
31
|
+
handler = req.path.start_with?('/callback') ? RackApp.register(uri, CallbackHandler.new(uri)) : RackApp.handler(uri)
|
32
|
+
handler.on_session_start(ws)
|
37
33
|
|
38
34
|
ws.on :message do |event|
|
39
|
-
|
40
|
-
res = RackApp.handler(uri).on_message(event.data)
|
41
|
-
ws.send(res.bytes) if res
|
42
|
-
end.run
|
35
|
+
handler.on_message(event.data)
|
43
36
|
end
|
44
37
|
|
45
38
|
ws.on :close do |event|
|
46
|
-
|
39
|
+
if CallbackHandler === handler
|
40
|
+
RackApp.close(uri)
|
41
|
+
end
|
47
42
|
ws = nil
|
48
43
|
end
|
49
44
|
|
data/lib/drb/websocket/server.rb
CHANGED
@@ -63,8 +63,7 @@ module DRb
|
|
63
63
|
end
|
64
64
|
|
65
65
|
def close
|
66
|
-
|
67
|
-
RackApp.close("#{u.host}:#{u.port}")
|
66
|
+
RackApp.close(@uri)
|
68
67
|
end
|
69
68
|
|
70
69
|
def push(callback)
|
@@ -72,13 +71,18 @@ module DRb
|
|
72
71
|
end
|
73
72
|
|
74
73
|
def accept
|
75
|
-
|
76
|
-
ServerSide.new(
|
74
|
+
callback = @queue.pop
|
75
|
+
ServerSide.new(callback, @config, uri)
|
77
76
|
end
|
78
77
|
|
79
78
|
def on_message(data)
|
80
79
|
callback = Callback.new(self)
|
81
|
-
callback.recv_mesg(data.pack('C*'))
|
80
|
+
res = callback.recv_mesg(data.pack('C*'))
|
81
|
+
@ws.send(res.bytes)
|
82
|
+
end
|
83
|
+
|
84
|
+
def on_session_start(ws)
|
85
|
+
@ws = ws
|
82
86
|
end
|
83
87
|
end
|
84
88
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: drb-websocket
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- youchan
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-09-
|
11
|
+
date: 2017-09-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faye-websocket
|