stormy-cloud 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/transport.rb +3 -4
- data/lib/transports/tcp.rb +7 -1
- metadata +1 -1
data/lib/transport.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'base64'
|
2
1
|
require 'digest'
|
3
2
|
require 'msgpack'
|
4
3
|
require 'securerandom'
|
@@ -148,7 +147,7 @@ class StormyCloudTransport
|
|
148
147
|
def handle(string)
|
149
148
|
valid_commands = ["HELLO", "GET", "PUT"]
|
150
149
|
command = unserialize(string)
|
151
|
-
|
150
|
+
|
152
151
|
if not (command.kind_of?(Array) and valid_commands.include? command[0])
|
153
152
|
# The command is invalid.
|
154
153
|
return serialize("INVALID COMMAND")
|
@@ -214,13 +213,13 @@ class StormyCloudTransport
|
|
214
213
|
# This can be overridden by the specific transport if the protocol used is
|
215
214
|
# such that this mode of serialization is disadvantageous.
|
216
215
|
def serialize(object)
|
217
|
-
|
216
|
+
Marshal.dump(object)
|
218
217
|
end
|
219
218
|
|
220
219
|
# Unserialize an object which has been serialized using the `serialize`
|
221
220
|
# method.
|
222
221
|
def unserialize(string)
|
223
|
-
|
222
|
+
Marshal.load(string)
|
224
223
|
end
|
225
224
|
|
226
225
|
# Return all variables relevant to the job status.
|
data/lib/transports/tcp.rb
CHANGED
@@ -7,7 +7,12 @@ class StormyCloudTCPTransport < StormyCloudTransport
|
|
7
7
|
@server_thread = Thread.new do
|
8
8
|
loop do
|
9
9
|
Thread.start(@server.accept) do |client|
|
10
|
-
|
10
|
+
message = ''
|
11
|
+
while (t = client.gets).strip != "ENDOFTHEMESSAGE"
|
12
|
+
message += t
|
13
|
+
end
|
14
|
+
reply = handle(message)
|
15
|
+
client.puts reply
|
11
16
|
end
|
12
17
|
end
|
13
18
|
end
|
@@ -21,6 +26,7 @@ class StormyCloudTCPTransport < StormyCloudTransport
|
|
21
26
|
begin
|
22
27
|
s = TCPSocket.new(@stormy_cloud.server, @stormy_cloud.config(:port))
|
23
28
|
s.puts string
|
29
|
+
s.puts "ENDOFTHEMESSAGE"
|
24
30
|
res = s.gets
|
25
31
|
s.close
|
26
32
|
res
|