simple-rpc 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +63 -0
- data/lib/local_socket.rb +2 -2
- data/simple-ruby-rpc.gemspec +1 -1
- data/test.rb +33 -8
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 246d858c384634c022eef0af7832715625c8d856d468cfd6859a86edc274e9c6
|
4
|
+
data.tar.gz: 95fb02cf24ff9e7ec9c70b6af9c82808ad3e1c6480059d8a77a47ed3c147abc4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 65012f9e1aa8034b883296f0a4024231770aaf9e3b6264f7e2aebd6b7c4e5275776b6aa2b87d80e55990e683c11eed7a129f563660815e9f6fd59bfdfe21a84d
|
7
|
+
data.tar.gz: fc272be526497255e5e6e456ae73a19a687902e5b0ab61292e00fe7867105c2fbd66e03cbbf0b27c9bab6fcfcce7b94ffebfa4f449271b7eb8a1abc8c065704e
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -33,6 +33,69 @@ Console 2
|
|
33
33
|
|
34
34
|
The `CHILD=1` env var flips the channels in the second process so that they the two processes can send and receive on two local unix sockets as defined by the `CHANNEL` env var.
|
35
35
|
|
36
|
+
|
37
|
+
Here's the contents of ./test.rb
|
38
|
+
|
39
|
+
```
|
40
|
+
|
41
|
+
#! /usr/bin/env ruby
|
42
|
+
|
43
|
+
$:.unshift(File.join(File.dirname(__FILE__), '/lib'))
|
44
|
+
|
45
|
+
require 'simple-rpc'
|
46
|
+
|
47
|
+
class Client
|
48
|
+
|
49
|
+
def say_hello(adjective, sender)
|
50
|
+
puts "hello #{adjective} #{sender}"
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_hash(some_hash)
|
54
|
+
puts "hash = #{some_hash}"
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_class(test_class)
|
58
|
+
puts "test_class = #{test_class}"
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
class TestClass
|
64
|
+
def initialize(a, b)
|
65
|
+
@a = a
|
66
|
+
@b = b
|
67
|
+
end
|
68
|
+
|
69
|
+
def to_json(options = {})
|
70
|
+
{'a' => @a, 'b' => @b}.to_json
|
71
|
+
end
|
72
|
+
|
73
|
+
def self.from_json string
|
74
|
+
data = JSON.load string
|
75
|
+
self.new data['a'], data['b']
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
client = Client.new
|
80
|
+
@rpc = SimpleRPC.new(client)
|
81
|
+
|
82
|
+
loop do
|
83
|
+
puts "Press enter to test strings"
|
84
|
+
$stdin.gets.chomp
|
85
|
+
@rpc.send_msg("say_hello", "awesome", "dude")
|
86
|
+
|
87
|
+
puts "Press enter to test hashes"
|
88
|
+
$stdin.gets.chomp
|
89
|
+
@rpc.send_msg("test_hash", {test:"asdf"})
|
90
|
+
|
91
|
+
puts "Press enter to test class instance"
|
92
|
+
$stdin.gets.chomp
|
93
|
+
@rpc.send_msg("test_class", TestClass.new('asdf1', 'asdf2'))
|
94
|
+
end
|
95
|
+
|
96
|
+
|
97
|
+
```
|
98
|
+
|
36
99
|
## Development
|
37
100
|
|
38
101
|
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/lib/local_socket.rb
CHANGED
@@ -22,7 +22,7 @@ class LocalSocket
|
|
22
22
|
@socket.sendmsg_nonblock(msg, 0, @snd_addrInfo)
|
23
23
|
flag = true
|
24
24
|
rescue => e
|
25
|
-
puts "Error: #{e}" unless "#{e}".include? "Connection refused"
|
25
|
+
puts "Error: #{e}" unless "#{e}".include? "Connection refused" or "#{e}".include? "No such file"
|
26
26
|
flag = false
|
27
27
|
end
|
28
28
|
return flag
|
@@ -32,7 +32,7 @@ class LocalSocket
|
|
32
32
|
begin
|
33
33
|
File.unlink @receive_channel
|
34
34
|
rescue => e
|
35
|
-
puts "#{e}"
|
35
|
+
puts "#{e}" unless "#{e}".include? "No such file"
|
36
36
|
end
|
37
37
|
@socket = Socket.new(:UNIX, :DGRAM, 0)
|
38
38
|
@snd_addrInfo = Addrinfo.unix(@send_channel)
|
data/simple-ruby-rpc.gemspec
CHANGED
data/test.rb
CHANGED
@@ -6,24 +6,49 @@ require 'simple-rpc'
|
|
6
6
|
|
7
7
|
class Client
|
8
8
|
|
9
|
-
def initialize
|
10
|
-
@rpc = SimpleRPC.new(self)
|
11
|
-
end
|
12
|
-
|
13
9
|
def say_hello(adjective, sender)
|
14
10
|
puts "hello #{adjective} #{sender}"
|
15
11
|
end
|
16
12
|
|
17
|
-
def
|
18
|
-
|
13
|
+
def test_hash(some_hash)
|
14
|
+
puts "hash = #{some_hash}"
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_class(test_class)
|
18
|
+
puts "test_class = #{test_class}"
|
19
19
|
end
|
20
20
|
|
21
21
|
end
|
22
22
|
|
23
|
+
class TestClass
|
24
|
+
def initialize(a, b)
|
25
|
+
@a = a
|
26
|
+
@b = b
|
27
|
+
end
|
28
|
+
|
29
|
+
def to_json(options = {})
|
30
|
+
{'a' => @a, 'b' => @b}.to_json
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.from_json string
|
34
|
+
data = JSON.load string
|
35
|
+
self.new data['a'], data['b']
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
23
39
|
client = Client.new
|
40
|
+
@rpc = SimpleRPC.new(client)
|
24
41
|
|
25
|
-
puts "Press enter to test"
|
26
42
|
loop do
|
43
|
+
puts "Press enter to test strings"
|
44
|
+
$stdin.gets.chomp
|
45
|
+
@rpc.send_msg("say_hello", "awesome", "dude")
|
46
|
+
|
47
|
+
puts "Press enter to test hashes"
|
48
|
+
$stdin.gets.chomp
|
49
|
+
@rpc.send_msg("test_hash", {test:"asdf"})
|
50
|
+
|
51
|
+
puts "Press enter to test class instance"
|
27
52
|
$stdin.gets.chomp
|
28
|
-
|
53
|
+
@rpc.send_msg("test_class", TestClass.new('asdf1', 'asdf2'))
|
29
54
|
end
|