ffi-rzmq 1.0.3 → 2.0.7
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 +5 -6
- data/AUTHORS.txt +7 -1
- data/History.txt +79 -0
- data/README.rdoc +67 -29
- data/Rakefile +15 -0
- 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 +26 -54
- 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/poll_item.rb +0 -1
- 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 +3 -3
- data/lib/io_extensions.rb +1 -1
- data/spec/context_spec.rb +18 -23
- data/spec/device_spec.rb +13 -12
- data/spec/message_spec.rb +13 -13
- data/spec/multipart_spec.rb +11 -11
- data/spec/nonblocking_recv_spec.rb +22 -22
- data/spec/poll_spec.rb +49 -49
- data/spec/pushpull_spec.rb +12 -11
- data/spec/reqrep_spec.rb +11 -11
- data/spec/socket_spec.rb +110 -197
- data/spec/spec_helper.rb +3 -11
- data/spec/support/generate_keys_and_certs.rb +41 -0
- data/spec/support/test.crt +26 -13
- data/spec/support/test.key +49 -13
- data/spec/util_spec.rb +29 -0
- data/travis_build_script.sh +27 -0
- metadata +83 -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
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.terminate_context(@context)
|
86
|
+
@context = nil
|
87
|
+
rc || 0
|
88
|
+
else
|
89
|
+
0
|
118
90
|
end
|
119
91
|
end
|
120
92
|
|
@@ -157,7 +129,7 @@ module ZMQ
|
|
157
129
|
end
|
158
130
|
|
159
131
|
def self.close context, pid
|
160
|
-
Proc.new { LibZMQ.
|
132
|
+
Proc.new { LibZMQ.zmq_ctx_term context if !context.null? && Process.pid == pid }
|
161
133
|
end
|
162
134
|
end
|
163
135
|
|
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
|
|