xmlrpcs 0.1.1 → 0.1.3
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/README +26 -0
- data/Rakefile +3 -6
- data/examples/tcp.rb +74 -0
- data/examples/unix.rb +74 -0
- metadata +7 -4
data/README
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
= xmlrpcs
|
2
|
+
|
3
|
+
This gems allow to easily change the transport layer in XMLRPC::Client class.
|
4
|
+
It adds a new class called XMLRPC::ClientS, subclass of the Client class. This
|
5
|
+
class must be subclassed to put your own transport code in it.
|
6
|
+
|
7
|
+
There are 3 private method that can be changed.
|
8
|
+
|
9
|
+
*new_socket* (info,async)
|
10
|
+
This method is called to create a new socket. Info is the parameter you passed
|
11
|
+
to the constructor and async is a boolean value that tells you if the socket
|
12
|
+
should be asyncrhonous.
|
13
|
+
The object returned must answer to read and write methods.
|
14
|
+
|
15
|
+
*read_response* (socket)
|
16
|
+
Must read the response from the socket and return the data. You may leave this
|
17
|
+
the default, but it will wait until the socket is closed.
|
18
|
+
|
19
|
+
*write_request* (socket,request)
|
20
|
+
Writes the request in the socket, this may be left as it is.
|
21
|
+
|
22
|
+
|
23
|
+
write_request and read_response have to be changed to use a specific protocol if you don't want the socket to be closed.
|
24
|
+
In the test i use a very simple one for instance which needs no explanation.
|
25
|
+
|
26
|
+
Author: Dario Meloni <mellon85@gmail.com>
|
data/Rakefile
CHANGED
@@ -7,14 +7,15 @@ require 'rake/rdoctask'
|
|
7
7
|
|
8
8
|
spec = Gem::Specification.new do |s|
|
9
9
|
s.name = "xmlrpcs"
|
10
|
-
s.version = "0.1.
|
10
|
+
s.version = "0.1.3"
|
11
11
|
s.author = "Dario Meloni"
|
12
12
|
s.email = "mellon85@gmail.com"
|
13
13
|
s.homepage = "http://rubyforge.org/projects/xmlrpcs/"
|
14
14
|
s.rubyforge_project = "xmlrpcs"
|
15
15
|
s.platform = Gem::Platform::RUBY
|
16
|
+
s.extra_rdoc_files = ["README"]
|
16
17
|
s.summary = "Changes sockets for the XMLRPC Library"
|
17
|
-
s.files = FileList['lib/**/*.rb', 'test/**/*.rb', 'Rakefile'].to_a
|
18
|
+
s.files = FileList['examples/*', 'lib/**/*.rb', 'test/**/*.rb', 'Rakefile'].to_a
|
18
19
|
s.require_path = "lib"
|
19
20
|
s.test_files = Dir.glob('test/**/tc_*.rb')
|
20
21
|
s.has_rdoc = true
|
@@ -37,7 +38,3 @@ task :dist => [:repackage, :gem, :rdoc]
|
|
37
38
|
task :clean => [:distclean]
|
38
39
|
task :default => [ :test, :dist ]
|
39
40
|
|
40
|
-
#task :default => "pkg/#{spec.name}-#{spec.version}.gem" do
|
41
|
-
# puts "generated latest version"
|
42
|
-
#end
|
43
|
-
|
data/examples/tcp.rb
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
#! /usr/bin/ruby
|
2
|
+
# Author: Dario Meloni <mellon85@gmail.com>
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
require 'xmlrpc/xmlrpcs'
|
6
|
+
require 'xmlrpc/server'
|
7
|
+
require 'socket'
|
8
|
+
|
9
|
+
$test_port="20000"
|
10
|
+
$test_host="localhost"
|
11
|
+
|
12
|
+
class TCPXMLClient < XMLRPC::ClientS
|
13
|
+
def new_socket(info,async)
|
14
|
+
TCPSocket.new(info["host"],info["port"])
|
15
|
+
end
|
16
|
+
|
17
|
+
def write_request(socket,request)
|
18
|
+
socket.write("#{request.length}\n")
|
19
|
+
socket.write(request)
|
20
|
+
end
|
21
|
+
|
22
|
+
def read_response(socket)
|
23
|
+
l = socket.readline
|
24
|
+
return socket.read(l.to_i)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
class TCPXMLServer < XMLRPC::BasicServer
|
29
|
+
|
30
|
+
attr_reader :host
|
31
|
+
attr_reader :port
|
32
|
+
|
33
|
+
def initialize( host, port )
|
34
|
+
@host = host
|
35
|
+
@port = port
|
36
|
+
@server = TCPServer.new(@host,@port)
|
37
|
+
super()
|
38
|
+
end
|
39
|
+
|
40
|
+
def serve()
|
41
|
+
catch (:exit_serve) {
|
42
|
+
while(true)
|
43
|
+
@server.listen(5)
|
44
|
+
client, client_addr = @server.accept
|
45
|
+
l = client.readline
|
46
|
+
data = client.read(l.to_i)
|
47
|
+
pdata = process(data)
|
48
|
+
client.write("#{pdata.length}\n")
|
49
|
+
client.write(pdata)
|
50
|
+
client.close
|
51
|
+
end
|
52
|
+
}
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
@s = TCPXMLServer.new($test_host,$test_port)
|
57
|
+
@s.add_introspection
|
58
|
+
@s.add_multicall
|
59
|
+
@s.add_handler("add") do |a,b|
|
60
|
+
a+b
|
61
|
+
end
|
62
|
+
@t = Thread.new do
|
63
|
+
@s.serve
|
64
|
+
end
|
65
|
+
|
66
|
+
client = TCPXMLClient.new({"host" => $test_host, "port" => "#{$test_port}"})
|
67
|
+
puts "2+3 = #{client.call("add",2,3)}"
|
68
|
+
proxy = client.proxy
|
69
|
+
puts "1+4 = #{proxy.add(1,4)}"
|
70
|
+
a, b = client.multicall(["add",3,2],["add",4,1])
|
71
|
+
puts "3+2 = #{a}"
|
72
|
+
puts "4+1 = #{b}"
|
73
|
+
|
74
|
+
Thread.kill(@t)
|
data/examples/unix.rb
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
#! /usr/bin/ruby
|
2
|
+
# Author: Dario Meloni <mellon85@gmail.com>
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
require 'xmlrpc/xmlrpcs'
|
6
|
+
require 'xmlrpc/server'
|
7
|
+
require 'socket'
|
8
|
+
|
9
|
+
$socket_path="/tmp/test.sock"
|
10
|
+
|
11
|
+
class UnixXMLClient < XMLRPC::ClientS
|
12
|
+
def new_socket(info,async)
|
13
|
+
UNIXSocket.new(info)
|
14
|
+
end
|
15
|
+
|
16
|
+
def write_request(socket,request)
|
17
|
+
socket.write("#{request.length}\n")
|
18
|
+
socket.write(request)
|
19
|
+
end
|
20
|
+
|
21
|
+
def read_response(socket)
|
22
|
+
l = socket.readline
|
23
|
+
return socket.read(l.to_i)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
class UnixXMLServer < XMLRPC::BasicServer
|
28
|
+
|
29
|
+
attr_reader :path
|
30
|
+
|
31
|
+
def initialize( path )
|
32
|
+
super()
|
33
|
+
@path = path
|
34
|
+
@server = UNIXServer.new(@path)
|
35
|
+
end
|
36
|
+
|
37
|
+
def serve()
|
38
|
+
catch (:exit_serve) {
|
39
|
+
while(true)
|
40
|
+
@server.listen(5)
|
41
|
+
client, client_addr = @server.accept
|
42
|
+
l = client.readline
|
43
|
+
data = client.read(l.to_i)
|
44
|
+
pdata = process(data)
|
45
|
+
client.write("#{pdata.length}\n")
|
46
|
+
client.write(pdata)
|
47
|
+
client.close
|
48
|
+
end
|
49
|
+
}
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
@s = UnixXMLServer.new($socket_path)
|
54
|
+
@s.add_introspection
|
55
|
+
@s.add_multicall
|
56
|
+
@s.add_handler("test.add") do |a,b|
|
57
|
+
a+b
|
58
|
+
end
|
59
|
+
@t = Thread.new do
|
60
|
+
@s.serve
|
61
|
+
end
|
62
|
+
|
63
|
+
client = UnixXMLClient.new($socket_path)
|
64
|
+
puts "2+3 = #{client.call("test.add",2,3)}"
|
65
|
+
proxy = client.proxy "test"
|
66
|
+
puts "1+4 = #{proxy.add(1,4)}"
|
67
|
+
a, b = client.multicall(["test.add",3,2],["test.add",4,1])
|
68
|
+
puts "3+2 = #{a}"
|
69
|
+
puts "4+1 = #{b}"
|
70
|
+
|
71
|
+
Thread.kill(@t)
|
72
|
+
File.unlink($socket_path)
|
73
|
+
|
74
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xmlrpcs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dario Meloni
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-06-
|
12
|
+
date: 2008-06-28 00:00:00 +02:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -19,13 +19,16 @@ executables: []
|
|
19
19
|
|
20
20
|
extensions: []
|
21
21
|
|
22
|
-
extra_rdoc_files:
|
23
|
-
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README
|
24
24
|
files:
|
25
|
+
- examples/tcp.rb
|
26
|
+
- examples/unix.rb
|
25
27
|
- lib/xmlrpc/xmlrpcs.rb
|
26
28
|
- test/xmlrpc/tc_tcp.rb
|
27
29
|
- test/xmlrpc/tc_unix.rb
|
28
30
|
- Rakefile
|
31
|
+
- README
|
29
32
|
has_rdoc: true
|
30
33
|
homepage: http://rubyforge.org/projects/xmlrpcs/
|
31
34
|
post_install_message:
|