ffi-rzmq 1.0.3 → 2.0.1
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.
- checksums.yaml +7 -0
- data/.travis.yml +1 -1
- data/AUTHORS.txt +5 -1
- data/History.txt +24 -0
- data/README.rdoc +2 -4
- data/examples/README.rdoc +1 -3
- data/examples/{v3api/latency_measurement.rb → latency_measurement.rb} +1 -2
- data/examples/{v3api/local_lat.rb → local_lat.rb} +1 -1
- data/examples/{v3api/local_lat_poll.rb → local_lat_poll.rb} +4 -4
- data/examples/{v3api/local_throughput.rb → local_throughput.rb} +1 -1
- data/examples/{v3api/pub.rb → pub.rb} +1 -1
- data/examples/{v2api/publish_subscribe.rb → publish_subscribe.rb} +2 -2
- data/examples/{v2api/remote_lat.rb → remote_lat.rb} +1 -1
- data/examples/{v3api/remote_throughput.rb → remote_throughput.rb} +4 -3
- data/examples/repreq_over_curve.rb +60 -0
- data/examples/{v2api/reqrep_poll.rb → reqrep_poll.rb} +3 -4
- data/examples/{v2api/request_response.rb → request_response.rb} +1 -2
- data/examples/{v3api/sub.rb → sub.rb} +1 -2
- data/examples/{v3api/throughput_measurement.rb → throughput_measurement.rb} +1 -1
- data/examples/{v3api/xreqxrep_poll.rb → xreqxrep_poll.rb} +6 -7
- data/ffi-rzmq.gemspec +4 -4
- data/lib/ffi-rzmq/context.rb +25 -53
- data/lib/ffi-rzmq/device.rb +8 -4
- data/lib/ffi-rzmq/exceptions.rb +3 -0
- data/lib/ffi-rzmq/message.rb +24 -30
- data/lib/ffi-rzmq/poll.rb +5 -16
- data/lib/ffi-rzmq/socket.rb +132 -282
- data/lib/ffi-rzmq/util.rb +28 -36
- data/lib/ffi-rzmq/version.rb +1 -1
- data/lib/ffi-rzmq.rb +2 -3
- data/spec/context_spec.rb +3 -8
- data/spec/device_spec.rb +10 -9
- data/spec/nonblocking_recv_spec.rb +7 -7
- data/spec/pushpull_spec.rb +8 -7
- data/spec/reqrep_spec.rb +6 -6
- data/spec/socket_spec.rb +43 -130
- data/spec/spec_helper.rb +3 -11
- data/spec/util_spec.rb +28 -0
- metadata +80 -104
- data/examples/v2api/latency_measurement.rb +0 -139
- data/examples/v2api/local_lat.rb +0 -58
- data/examples/v2api/local_lat_poll.rb +0 -66
- data/examples/v2api/local_throughput.rb +0 -58
- data/examples/v2api/pub.rb +0 -46
- data/examples/v2api/remote_throughput.rb +0 -39
- data/examples/v2api/sub.rb +0 -74
- data/examples/v2api/throughput_measurement.rb +0 -138
- data/examples/v2api/xreqxrep_poll.rb +0 -93
- data/examples/v3api/publish_subscribe.rb +0 -82
- data/examples/v3api/remote_lat.rb +0 -71
- data/examples/v3api/reqrep_poll.rb +0 -62
- data/examples/v3api/request_response.rb +0 -40
- data/lib/ffi-rzmq/constants.rb +0 -187
- data/lib/ffi-rzmq/libc.rb +0 -19
- data/lib/ffi-rzmq/libzmq.rb +0 -283
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d4e271f6dc0fcbad07111b4b23c969f192eb6d57
|
4
|
+
data.tar.gz: d5a508626d471997f3568646cd05a95a70ad19f1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 72b0886538590486c2e8c64e4e03eeab7259c39a9720b0ae763f7c4d0e149cda5926ddbc1710b39ecbf4cfeee0f348d1c85e1816c437764ac99becb7be784286
|
7
|
+
data.tar.gz: 0ca81c180fb1a7a8c7dd7767f7200589ec91fb42553c49eac03a2b91c5e51a95f002c64503e2d79fe77cee74adb0331a9adda1107ffd498effaa10ce2b471f01
|
data/.travis.yml
CHANGED
data/AUTHORS.txt
CHANGED
data/History.txt
CHANGED
@@ -1,3 +1,27 @@
|
|
1
|
+
== 2.0.1 / 20140122
|
2
|
+
* Fix setsockopt with string parameters for options that have very strict
|
3
|
+
requirements (like CURVE_SECRETKEY) (37aed3c)
|
4
|
+
|
5
|
+
* Provide a wrapper for zmq_curve_keypair for ZeroMQ4
|
6
|
+
|
7
|
+
== 2.0.0 / 20140108
|
8
|
+
* Split out all of the FFI code to its own gem so other projects can use
|
9
|
+
it without the effort of duplication.
|
10
|
+
|
11
|
+
* Support libzmq 4 API and its new security API . Thanks to Devin
|
12
|
+
Christensen (devin-c) and Jason Roelofs (jasonroelofs) for related
|
13
|
+
patches.
|
14
|
+
|
15
|
+
* Minor documentation fixes. Thanks to Michael Zaccari (mzaccari) for
|
16
|
+
the fix.
|
17
|
+
|
18
|
+
* Improved the readability of any FFI code (now moved to ffi-rzmq-core
|
19
|
+
project). Thanks to Stephen von Takach (stakach) for the patch.
|
20
|
+
|
21
|
+
* Updated AUTHORS.txt
|
22
|
+
|
23
|
+
|
24
|
+
|
1
25
|
== 1.0.3 / 20131003
|
2
26
|
* Fixes for issues #96 and #97. Thanks to Paul Chechetin (paulche) for
|
3
27
|
the issues and patches.
|
data/README.rdoc
CHANGED
@@ -122,17 +122,15 @@ I highly recommend visiting the Learn Ruby 0mq project for a bunch of good code
|
|
122
122
|
|
123
123
|
== REQUIREMENTS:
|
124
124
|
|
125
|
-
* 0mq
|
125
|
+
* 0mq 3.2.x, 4.x or later; 2.x, 3.0.x and 3.1.x are no longer supported
|
126
126
|
|
127
127
|
The ZeroMQ library must be installed on your system in a well-known location
|
128
128
|
like /usr/local/lib. This is the default for new ZeroMQ installs.
|
129
129
|
|
130
130
|
If you have installed ZeroMQ using brew, you need to `brew link zeromq` before installing this gem.
|
131
131
|
|
132
|
-
Future releases may include the library as a C extension built at
|
133
|
-
time of installation.
|
134
|
-
|
135
132
|
* ffi (>= 1.0.0)
|
133
|
+
* ffi-rzmq-core
|
136
134
|
|
137
135
|
This is a requirement for MRI and Rubinius. JRuby has FFI support built
|
138
136
|
in as a standard component. Do *not* run this gem under MRI with an old 'ffi' gem.
|
data/examples/README.rdoc
CHANGED
@@ -4,14 +4,12 @@
|
|
4
4
|
|
5
5
|
1. lib dir
|
6
6
|
|
7
|
-
All of the examples assume the lib directory containing the gem sources is
|
7
|
+
All of the examples assume the lib directory containing the gem sources is one directory up from the location of the example.
|
8
8
|
|
9
9
|
2. Installed libzmq library
|
10
10
|
|
11
11
|
The ZeroMQ C libraries need to be downloaded, compiled and installed separately from the gem. Please see http://www.zeromq.org/area:download for links to the downloadable files along with some simple installation instructions. Also, be sure to check the FAQ if you run into problems with compiling.
|
12
12
|
|
13
|
-
This gem auto-configures itself to conform to the API for 0mq 2.1.x and 3.1.x. The 0mq project started making backward-incompatible changes with the 3.x branch. Rather than create separate gems, this one handles all of them.
|
14
|
-
|
15
13
|
It is possible to install the libzmq* files directly into the gem in the ext/ directory. This directory is checked for loadable libraries first before it falls back to checking the system paths.
|
16
14
|
|
17
15
|
3. One terminal window
|
@@ -1,6 +1,5 @@
|
|
1
1
|
|
2
|
-
require File.join(File.dirname(__FILE__), '..', '
|
3
|
-
|
2
|
+
require File.join(File.dirname(__FILE__), '..', 'lib', 'ffi-rzmq')
|
4
3
|
|
5
4
|
# Within a single process, we start up two threads. One thread has a REQ (request)
|
6
5
|
# socket and the second thread has a REP (reply) socket. We measure the
|
@@ -16,7 +16,7 @@
|
|
16
16
|
# You should have received a copy of the Lesser GNU General Public License
|
17
17
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
18
18
|
|
19
|
-
require File.join(File.dirname(__FILE__), '..', '
|
19
|
+
require File.join(File.dirname(__FILE__), '..', 'lib', 'ffi-rzmq')
|
20
20
|
|
21
21
|
if ARGV.length < 3
|
22
22
|
puts "usage: ruby local_lat.rb <connect-to> <message-size> <roundtrip-count>"
|
@@ -1,5 +1,5 @@
|
|
1
1
|
|
2
|
-
require File.join(File.dirname(__FILE__), '..', '
|
2
|
+
require File.join(File.dirname(__FILE__), '..', 'lib', 'ffi-rzmq')
|
3
3
|
|
4
4
|
if ARGV.length < 3
|
5
5
|
puts "usage: ruby local_lat.rb <connect-to> <message-size> <roundtrip-count>"
|
@@ -38,7 +38,7 @@ start_time = Time.now
|
|
38
38
|
|
39
39
|
# kick it off
|
40
40
|
message = ZMQ::Message.new("a" * message_size)
|
41
|
-
assert(s1.sendmsg(message, ZMQ::
|
41
|
+
assert(s1.sendmsg(message, ZMQ::DONTWAIT))
|
42
42
|
|
43
43
|
i = roundtrip_count
|
44
44
|
|
@@ -49,8 +49,8 @@ until i.zero?
|
|
49
49
|
|
50
50
|
poller.readables.each do |socket|
|
51
51
|
received_message = ''
|
52
|
-
assert(socket.recv_string(received_message, ZMQ::
|
53
|
-
assert(socket.sendmsg(ZMQ::Message.new(received_message), ZMQ::
|
52
|
+
assert(socket.recv_string(received_message, ZMQ::DONTWAIT))
|
53
|
+
assert(socket.sendmsg(ZMQ::Message.new(received_message), ZMQ::DONTWAIT))
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), '..', '
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'lib', 'ffi-rzmq')
|
2
2
|
|
3
3
|
|
4
4
|
def assert(rc)
|
@@ -71,7 +71,7 @@ assert(s4.recv_string(body)) if s4.more_parts?
|
|
71
71
|
puts "s4 received topic [#{topic}], body [#{body}]"
|
72
72
|
|
73
73
|
s5_string = ''
|
74
|
-
rc = s5.recv_string(s5_string, ZMQ::
|
74
|
+
rc = s5.recv_string(s5_string, ZMQ::DONTWAIT)
|
75
75
|
eagain = (rc == -1 && ZMQ::Util.errno == ZMQ::EAGAIN)
|
76
76
|
puts(eagain ? "s5 received no messages" : "s5 FAILED")
|
77
77
|
|
@@ -17,7 +17,7 @@
|
|
17
17
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
18
18
|
|
19
19
|
|
20
|
-
require File.join(File.dirname(__FILE__), '..', '
|
20
|
+
require File.join(File.dirname(__FILE__), '..', 'lib', 'ffi-rzmq')
|
21
21
|
|
22
22
|
if ARGV.length < 3
|
23
23
|
puts "usage: ruby remote_lat.rb <connect-to> <message-size> <roundtrip-count>"
|
@@ -1,5 +1,5 @@
|
|
1
1
|
|
2
|
-
require File.join(File.dirname(__FILE__), '..', '
|
2
|
+
require File.join(File.dirname(__FILE__), '..', 'lib', 'ffi-rzmq')
|
3
3
|
|
4
4
|
if ARGV.length != 3
|
5
5
|
puts "usage: ruby remote_throughput.rb <connect-to> <message-size> <message-count>"
|
@@ -27,9 +27,10 @@ end
|
|
27
27
|
#assert(s.setsockopt(ZMQ::SNDHWM, 0))
|
28
28
|
assert(s.connect(connect_to))
|
29
29
|
|
30
|
-
#
|
30
|
+
# give the downstream SUB socket a chance to register its
|
31
31
|
# subscription filters with this PUB socket
|
32
|
-
|
32
|
+
puts "Hit any key to start publishing"
|
33
|
+
STDIN.gets
|
33
34
|
|
34
35
|
contents = "#{'0'*message_size}"
|
35
36
|
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'lib', 'ffi-rzmq')
|
2
|
+
|
3
|
+
# This example shows the basics of a CURVE-secured REP/REQ setup between
|
4
|
+
# a Server and Client. This is the minimal required setup for authenticating
|
5
|
+
# a connection between a Client and a Server. For validating the Client's authentication
|
6
|
+
# once the initial connection has succeeded, you'll need a ZAP handler on the Server.
|
7
|
+
|
8
|
+
# Build the Server's keys
|
9
|
+
server_public_key, server_private_key = ZMQ::Util.curve_keypair
|
10
|
+
|
11
|
+
# Build the Client's keys
|
12
|
+
client_public_key, client_private_key = ZMQ::Util.curve_keypair
|
13
|
+
|
14
|
+
context = ZMQ::Context.new
|
15
|
+
bind_point = "tcp://127.0.0.1:4455"
|
16
|
+
|
17
|
+
##
|
18
|
+
# Configure the Server
|
19
|
+
##
|
20
|
+
server = context.socket ZMQ::REP
|
21
|
+
|
22
|
+
server.setsockopt(ZMQ::CURVE_SERVER, 1)
|
23
|
+
server.setsockopt(ZMQ::CURVE_SECRETKEY, server_private_key)
|
24
|
+
|
25
|
+
server.bind(bind_point)
|
26
|
+
|
27
|
+
##
|
28
|
+
# Configure the Client to talk to the Server
|
29
|
+
##
|
30
|
+
client = context.socket ZMQ::REQ
|
31
|
+
|
32
|
+
client.setsockopt(ZMQ::CURVE_SERVERKEY, server_public_key)
|
33
|
+
client.setsockopt(ZMQ::CURVE_PUBLICKEY, client_public_key)
|
34
|
+
client.setsockopt(ZMQ::CURVE_SECRETKEY, client_private_key)
|
35
|
+
|
36
|
+
client.connect(bind_point)
|
37
|
+
|
38
|
+
##
|
39
|
+
# Show that communication still works
|
40
|
+
##
|
41
|
+
|
42
|
+
client_message = "Hello Server!"
|
43
|
+
server_response = "Hello Client!"
|
44
|
+
|
45
|
+
puts "Client sending: #{client_message}"
|
46
|
+
client.send_string client_message
|
47
|
+
|
48
|
+
server.recv_string(server_message = '')
|
49
|
+
puts "Server received: #{server_message}, replying with #{server_response}"
|
50
|
+
|
51
|
+
server.send_string(server_response)
|
52
|
+
|
53
|
+
client.recv_string(response = '')
|
54
|
+
puts "Client has received: #{response}"
|
55
|
+
|
56
|
+
puts "Finished"
|
57
|
+
|
58
|
+
client.close
|
59
|
+
server.close
|
60
|
+
context.terminate
|
@@ -1,6 +1,5 @@
|
|
1
1
|
|
2
|
-
require File.join(File.dirname(__FILE__), '..', '
|
3
|
-
|
2
|
+
require File.join(File.dirname(__FILE__), '..', 'lib', 'ffi-rzmq')
|
4
3
|
|
5
4
|
def assert(rc)
|
6
5
|
raise "Last API call failed at #{caller(1)}" unless rc >= 0
|
@@ -38,7 +37,7 @@ until @done do
|
|
38
37
|
payload = "#{ '3' * 1024 }"
|
39
38
|
|
40
39
|
puts "sending payload nonblocking"
|
41
|
-
assert(s1.send_string(payload, ZMQ::
|
40
|
+
assert(s1.send_string(payload, ZMQ::DONTWAIT))
|
42
41
|
@unsent = false
|
43
42
|
end
|
44
43
|
|
@@ -46,7 +45,7 @@ until @done do
|
|
46
45
|
if Time.now - start_time > 1
|
47
46
|
poller.readables.each do |sock|
|
48
47
|
received_msg = ''
|
49
|
-
assert(sock.recv_string(received_msg, ZMQ::
|
48
|
+
assert(sock.recv_string(received_msg, ZMQ::DONTWAIT))
|
50
49
|
|
51
50
|
puts "message received [#{received_msg}]"
|
52
51
|
@done = true
|
@@ -1,11 +1,10 @@
|
|
1
1
|
|
2
|
-
require File.join(File.dirname(__FILE__), '..', '
|
2
|
+
require File.join(File.dirname(__FILE__), '..', 'lib', 'ffi-rzmq')
|
3
3
|
|
4
4
|
#if ARGV.length != 3
|
5
5
|
# puts "usage: ruby local_throughtput.rb <bind-to> <message-size> <message-count>"
|
6
6
|
# Process.exit
|
7
7
|
#end
|
8
|
-
p ZMQ::Util.version
|
9
8
|
|
10
9
|
def assert(rc)
|
11
10
|
raise "Last API call failed at #{caller(1)}" unless rc >= 0
|
@@ -1,6 +1,5 @@
|
|
1
1
|
|
2
|
-
require File.join(File.dirname(__FILE__), '..', '
|
3
|
-
|
2
|
+
require File.join(File.dirname(__FILE__), '..', 'lib', 'ffi-rzmq')
|
4
3
|
|
5
4
|
def assert(rc)
|
6
5
|
raise "Last API call failed at #{caller(1)}" unless rc >= 0
|
@@ -43,7 +42,7 @@ until @done do
|
|
43
42
|
|
44
43
|
5.times do |i|
|
45
44
|
payload = "#{ i.to_s * 40 }"
|
46
|
-
assert(s1.send_string(payload, ZMQ::
|
45
|
+
assert(s1.send_string(payload, ZMQ::DONTWAIT))
|
47
46
|
end
|
48
47
|
@unsent = false
|
49
48
|
end
|
@@ -54,12 +53,12 @@ until @done do
|
|
54
53
|
|
55
54
|
if sock.identity =~ /xrep/
|
56
55
|
routing_info = ''
|
57
|
-
assert(sock.recv_string(routing_info, ZMQ::
|
56
|
+
assert(sock.recv_string(routing_info, ZMQ::DONTWAIT))
|
58
57
|
puts "routing_info received [#{routing_info}] on socket.identity [#{sock.identity}]"
|
59
58
|
else
|
60
59
|
routing_info = nil
|
61
60
|
received_msg = ''
|
62
|
-
assert(sock.recv_string(received_msg, ZMQ::
|
61
|
+
assert(sock.recv_string(received_msg, ZMQ::DONTWAIT))
|
63
62
|
|
64
63
|
# skip to the next iteration if received_msg is nil; that means we got an EAGAIN
|
65
64
|
next unless received_msg
|
@@ -68,13 +67,13 @@ until @done do
|
|
68
67
|
|
69
68
|
while sock.more_parts? do
|
70
69
|
received_msg = ''
|
71
|
-
assert(sock.recv_string(received_msg, ZMQ::
|
70
|
+
assert(sock.recv_string(received_msg, ZMQ::DONTWAIT))
|
72
71
|
|
73
72
|
puts "message received [#{received_msg}]"
|
74
73
|
end
|
75
74
|
|
76
75
|
puts "kick back a reply"
|
77
|
-
assert(sock.send_string(routing_info, ZMQ::SNDMORE | ZMQ::
|
76
|
+
assert(sock.send_string(routing_info, ZMQ::SNDMORE | ZMQ::DONTWAIT)) if routing_info
|
78
77
|
time = Time.now.strftime "%Y-%m-%dT%H:%M:%S.#{Time.now.usec}"
|
79
78
|
reply = "reply " + sock.identity.upcase + " #{time}"
|
80
79
|
puts "sent reply [#{reply}], #{time}"
|
data/ffi-rzmq.gemspec
CHANGED
@@ -11,9 +11,9 @@ Gem::Specification.new do |s|
|
|
11
11
|
s.summary = %q{This gem wraps the ZeroMQ (0mq) networking library using Ruby FFI (foreign function interface).}
|
12
12
|
s.description = %q{This gem wraps the ZeroMQ networking library using the ruby FFI (foreign
|
13
13
|
function interface). It's a pure ruby wrapper so this gem can be loaded
|
14
|
-
and run by any ruby runtime that supports FFI. That's all of the major ones -
|
15
|
-
MRI, Rubinius and JRuby.}
|
14
|
+
and run by any ruby runtime that supports FFI. That's all of the major ones - MRI, Rubinius and JRuby.}
|
16
15
|
|
16
|
+
s.license = 'MIT'
|
17
17
|
s.rubyforge_project = "ffi-rzmq"
|
18
18
|
|
19
19
|
s.files = `git ls-files`.split("\n")
|
@@ -21,7 +21,7 @@ MRI, Rubinius and JRuby.}
|
|
21
21
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
22
22
|
s.require_paths = ["lib"]
|
23
23
|
|
24
|
-
s.add_runtime_dependency "ffi"
|
25
|
-
s.add_development_dependency "rspec", ["~> 2.
|
24
|
+
s.add_runtime_dependency "ffi-rzmq-core", [">= 1.0.1"]
|
25
|
+
s.add_development_dependency "rspec", ["~> 2.14"]
|
26
26
|
s.add_development_dependency "rake"
|
27
27
|
end
|
data/lib/ffi-rzmq/context.rb
CHANGED
@@ -47,44 +47,29 @@ module ZMQ
|
|
47
47
|
|
48
48
|
# Use the factory method Context#create to make contexts.
|
49
49
|
#
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
end
|
54
|
-
|
55
|
-
def initialize io_threads = 1
|
56
|
-
@io_threads = io_threads
|
57
|
-
@context = LibZMQ.zmq_init io_threads
|
58
|
-
ZMQ::Util.error_check 'zmq_init', (@context.nil? || @context.null?) ? -1 : 0
|
59
|
-
|
60
|
-
define_finalizer
|
61
|
-
end
|
62
|
-
elsif LibZMQ.version3?
|
50
|
+
def self.create(opts = {})
|
51
|
+
new(opts) rescue nil
|
52
|
+
end
|
63
53
|
|
64
|
-
|
65
|
-
|
54
|
+
def initialize(opts = {})
|
55
|
+
if opts.respond_to?(:empty?)
|
56
|
+
@io_threads = opts[:io_threads] || IO_THREADS_DFLT
|
57
|
+
@max_sockets = opts[:max_sockets] || MAX_SOCKETS_DFLT
|
58
|
+
else
|
59
|
+
@io_threads = opts || 1
|
60
|
+
@max_sockets = MAX_SOCKETS_DFLT
|
66
61
|
end
|
67
62
|
|
68
|
-
|
69
|
-
|
70
|
-
@io_threads = opts[:io_threads] || IO_THREADS_DFLT
|
71
|
-
@max_sockets = opts[:max_sockets] || MAX_SOCKETS_DFLT
|
72
|
-
else
|
73
|
-
@io_threads = opts || 1
|
74
|
-
@max_sockets = MAX_SOCKETS_DFLT
|
75
|
-
end
|
76
|
-
|
77
|
-
@context = LibZMQ.zmq_ctx_new
|
78
|
-
ZMQ::Util.error_check 'zmq_ctx_new', (@context.nil? || @context.null?) ? -1 : 0
|
63
|
+
@context = LibZMQ.zmq_ctx_new
|
64
|
+
ZMQ::Util.error_check 'zmq_ctx_new', (@context.nil? || @context.null?) ? -1 : 0
|
79
65
|
|
80
|
-
|
81
|
-
|
66
|
+
rc = LibZMQ.zmq_ctx_set(@context, ZMQ::IO_THREADS, @io_threads)
|
67
|
+
ZMQ::Util.error_check 'zmq_ctx_set', rc
|
82
68
|
|
83
|
-
|
84
|
-
|
69
|
+
rc = LibZMQ.zmq_ctx_set(@context, ZMQ::MAX_SOCKETS, @max_sockets)
|
70
|
+
ZMQ::Util.error_check 'zmq_ctx_set', rc
|
85
71
|
|
86
|
-
|
87
|
-
end
|
72
|
+
define_finalizer
|
88
73
|
end
|
89
74
|
|
90
75
|
# Call to release the context and any remaining data associated
|
@@ -94,27 +79,14 @@ module ZMQ
|
|
94
79
|
#
|
95
80
|
# Returns 0 for success, -1 for failure.
|
96
81
|
#
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
0
|
106
|
-
end
|
107
|
-
end
|
108
|
-
elsif LibZMQ.version3?
|
109
|
-
def terminate
|
110
|
-
unless @context.nil? || @context.null?
|
111
|
-
remove_finalizer
|
112
|
-
rc = LibZMQ.zmq_ctx_destroy(@context)
|
113
|
-
@context = nil
|
114
|
-
rc
|
115
|
-
else
|
116
|
-
0
|
117
|
-
end
|
82
|
+
def terminate
|
83
|
+
unless @context.nil? || @context.null?
|
84
|
+
remove_finalizer
|
85
|
+
rc = LibZMQ.zmq_ctx_destroy(@context)
|
86
|
+
@context = nil
|
87
|
+
rc
|
88
|
+
else
|
89
|
+
0
|
118
90
|
end
|
119
91
|
end
|
120
92
|
|
data/lib/ffi-rzmq/device.rb
CHANGED
@@ -3,10 +3,10 @@ module ZMQ
|
|
3
3
|
class Device
|
4
4
|
attr_reader :device
|
5
5
|
|
6
|
-
def self.create(
|
6
|
+
def self.create(frontend, backend, capture=nil)
|
7
7
|
dev = nil
|
8
8
|
begin
|
9
|
-
dev = new(
|
9
|
+
dev = new(frontend, backend, capture)
|
10
10
|
rescue ArgumentError
|
11
11
|
dev = nil
|
12
12
|
end
|
@@ -14,15 +14,19 @@ module ZMQ
|
|
14
14
|
dev
|
15
15
|
end
|
16
16
|
|
17
|
-
def initialize(
|
17
|
+
def initialize(frontend, backend, capture=nil)
|
18
18
|
[["frontend", frontend], ["backend", backend]].each do |name, socket|
|
19
19
|
unless socket.is_a?(ZMQ::Socket)
|
20
20
|
raise ArgumentError, "Expected a ZMQ::Socket, not a #{socket.class} as the #{name}"
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
-
LibZMQ.
|
24
|
+
LibZMQ.zmq_proxy(frontend.socket, backend.socket, capture ? capture.socket : nil)
|
25
25
|
end
|
26
26
|
end
|
27
|
+
|
28
|
+
# Alias for Device
|
29
|
+
#
|
30
|
+
class Proxy < Device; end
|
27
31
|
|
28
32
|
end
|
data/lib/ffi-rzmq/exceptions.rb
CHANGED
data/lib/ffi-rzmq/message.rb
CHANGED
@@ -84,8 +84,8 @@ module ZMQ
|
|
84
84
|
# puts "value1 is #{message.value1}"
|
85
85
|
#
|
86
86
|
class Message
|
87
|
-
|
88
|
-
# Recommended way to create a standard message. A Message object is
|
87
|
+
|
88
|
+
# Recommended way to create a standard message. A Message object is
|
89
89
|
# returned upon success, nil when allocation fails.
|
90
90
|
#
|
91
91
|
def self.create message = nil
|
@@ -129,7 +129,7 @@ module ZMQ
|
|
129
129
|
data_buffer.write_string bytes, len
|
130
130
|
|
131
131
|
# use libC to call free on the data buffer; earlier versions used an
|
132
|
-
# FFI::Function here that called back into Ruby, but Rubinius won't
|
132
|
+
# FFI::Function here that called back into Ruby, but Rubinius won't
|
133
133
|
# support that and there are issues with the other runtimes too
|
134
134
|
LibZMQ.zmq_msg_init_data @pointer, data_buffer, len, LibC::Free, nil
|
135
135
|
end
|
@@ -182,42 +182,36 @@ module ZMQ
|
|
182
182
|
#
|
183
183
|
def close
|
184
184
|
rc = 0
|
185
|
-
|
185
|
+
|
186
186
|
if @pointer
|
187
187
|
rc = LibZMQ.zmq_msg_close @pointer
|
188
188
|
@pointer = nil
|
189
189
|
end
|
190
|
-
|
190
|
+
|
191
191
|
rc
|
192
192
|
end
|
193
|
-
|
193
|
+
|
194
194
|
# cache the msg size so we don't have to recalculate it when creating
|
195
195
|
# each new instance
|
196
|
-
@msg_size = LibZMQ::
|
197
|
-
|
196
|
+
@msg_size = LibZMQ::Message.size
|
197
|
+
|
198
198
|
def self.msg_size() @msg_size; end
|
199
199
|
|
200
200
|
end # class Message
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
Util.resultcode_ok?(get(MORE))
|
216
|
-
end
|
217
|
-
|
218
|
-
def set(property, value)
|
219
|
-
LibZMQ.zmq_msg_set(@pointer, property, value)
|
220
|
-
end
|
201
|
+
|
202
|
+
class Message
|
203
|
+
def get(property)
|
204
|
+
LibZMQ.zmq_msg_get(@pointer, property)
|
205
|
+
end
|
206
|
+
|
207
|
+
# Returns true if this message has additional parts coming.
|
208
|
+
#
|
209
|
+
def more?
|
210
|
+
Util.resultcode_ok?(get(MORE))
|
211
|
+
end
|
212
|
+
|
213
|
+
def set(property, value)
|
214
|
+
LibZMQ.zmq_msg_set(@pointer, property, value)
|
221
215
|
end
|
222
216
|
end
|
223
217
|
|
@@ -254,7 +248,7 @@ module ZMQ
|
|
254
248
|
#
|
255
249
|
def copy_in_bytes bytes, len
|
256
250
|
rc = super(bytes, len)
|
257
|
-
|
251
|
+
|
258
252
|
# make sure we have a way to deallocate this memory if the object goes
|
259
253
|
# out of scope
|
260
254
|
define_finalizer
|
@@ -296,7 +290,7 @@ module ZMQ
|
|
296
290
|
# cache the msg size so we don't have to recalculate it when creating
|
297
291
|
# each new instance
|
298
292
|
# need to do this again because ivars are not inheritable
|
299
|
-
@msg_size = LibZMQ::
|
293
|
+
@msg_size = LibZMQ::Message.size
|
300
294
|
|
301
295
|
end # class ManagedMessage
|
302
296
|
|
data/lib/ffi-rzmq/poll.rb
CHANGED
@@ -150,22 +150,11 @@ module ZMQ
|
|
150
150
|
# milliseconds, so we need to convert that value to
|
151
151
|
# microseconds for the library.
|
152
152
|
#
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
(timeout * 1000).to_i
|
159
|
-
end
|
160
|
-
end
|
161
|
-
else
|
162
|
-
# version3 changed units from microseconds to milliseconds
|
163
|
-
def adjust timeout
|
164
|
-
if :blocking == timeout || -1 == timeout
|
165
|
-
-1
|
166
|
-
else
|
167
|
-
timeout.to_i
|
168
|
-
end
|
153
|
+
def adjust timeout
|
154
|
+
if :blocking == timeout || -1 == timeout
|
155
|
+
-1
|
156
|
+
else
|
157
|
+
timeout.to_i
|
169
158
|
end
|
170
159
|
end
|
171
160
|
|