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/spec/socket_spec.rb
CHANGED
@@ -7,11 +7,8 @@ module ZMQ
|
|
7
7
|
describe Socket do
|
8
8
|
include APIHelper
|
9
9
|
|
10
|
-
socket_types =
|
11
|
-
[ZMQ::REQ, ZMQ::REP, ZMQ::DEALER, ZMQ::ROUTER, ZMQ::PUB, ZMQ::SUB, ZMQ::PUSH, ZMQ::PULL, ZMQ::PAIR]
|
12
|
-
elsif LibZMQ.version3?
|
10
|
+
socket_types =
|
13
11
|
[ZMQ::REQ, ZMQ::REP, ZMQ::DEALER, ZMQ::ROUTER, ZMQ::PUB, ZMQ::SUB, ZMQ::PUSH, ZMQ::PULL, ZMQ::PAIR, ZMQ::XPUB, ZMQ::XSUB]
|
14
|
-
end
|
15
12
|
|
16
13
|
context "when initializing" do
|
17
14
|
before(:all) { @ctx = Context.new }
|
@@ -19,21 +16,21 @@ module ZMQ
|
|
19
16
|
|
20
17
|
|
21
18
|
it "should raise an error for a nil context" do
|
22
|
-
|
19
|
+
expect { Socket.new(FFI::Pointer.new(0), ZMQ::REQ) }.to raise_exception(ZMQ::ContextError)
|
23
20
|
end
|
24
21
|
|
25
22
|
it "works with a Context#pointer as the context_ptr" do
|
26
|
-
|
23
|
+
expect do
|
27
24
|
s = Socket.new(@ctx.pointer, ZMQ::REQ)
|
28
25
|
s.close
|
29
|
-
end.
|
26
|
+
end.not_to raise_exception
|
30
27
|
end
|
31
28
|
|
32
29
|
it "works with a Context instance as the context_ptr" do
|
33
|
-
|
30
|
+
expect do
|
34
31
|
s = Socket.new(@ctx, ZMQ::SUB)
|
35
32
|
s.close
|
36
|
-
end.
|
33
|
+
end.not_to raise_exception
|
37
34
|
end
|
38
35
|
|
39
36
|
|
@@ -41,22 +38,22 @@ module ZMQ
|
|
41
38
|
|
42
39
|
it "should not raise an error for a [#{ZMQ::SocketTypeNameMap[socket_type]}] socket type" do
|
43
40
|
sock = nil
|
44
|
-
|
41
|
+
expect { sock = Socket.new(@ctx.pointer, socket_type) }.not_to raise_error
|
45
42
|
sock.close
|
46
43
|
end
|
47
44
|
end # each socket_type
|
48
45
|
|
49
46
|
it "should set the :socket accessor to the raw socket allocated by libzmq" do
|
50
47
|
socket = double('socket')
|
51
|
-
socket.
|
52
|
-
LibZMQ.
|
48
|
+
allow(socket).to receive(:null?).and_return(false)
|
49
|
+
expect(LibZMQ).to receive(:zmq_socket).and_return(socket)
|
53
50
|
|
54
51
|
sock = Socket.new(@ctx.pointer, ZMQ::REQ)
|
55
|
-
sock.socket.
|
52
|
+
expect(sock.socket).to eq(socket)
|
56
53
|
end
|
57
54
|
|
58
55
|
it "should define a finalizer on this object" do
|
59
|
-
ObjectSpace.
|
56
|
+
expect(ObjectSpace).to receive(:define_finalizer).at_least(1)
|
60
57
|
sock = Socket.new(@ctx.pointer, ZMQ::REQ)
|
61
58
|
sock.close
|
62
59
|
end
|
@@ -80,7 +77,7 @@ module ZMQ
|
|
80
77
|
sock = Socket.new @ctx.pointer, ZMQ::REQ
|
81
78
|
raw_socket = sock.socket
|
82
79
|
|
83
|
-
LibZMQ.
|
80
|
+
expect(LibZMQ).to receive(:close).with(raw_socket)
|
84
81
|
sock.close
|
85
82
|
sock.close
|
86
83
|
LibZMQ.close raw_socket # *really close it otherwise the context will block indefinitely
|
@@ -97,7 +94,7 @@ module ZMQ
|
|
97
94
|
sock = Socket.new @ctx.pointer, ZMQ::REQ
|
98
95
|
|
99
96
|
sock.identity = ('a' * 256)
|
100
|
-
sock.identity.
|
97
|
+
expect(sock.identity).to eq('')
|
101
98
|
sock.close
|
102
99
|
end
|
103
100
|
|
@@ -105,7 +102,7 @@ module ZMQ
|
|
105
102
|
sock = Socket.new @ctx.pointer, ZMQ::REQ
|
106
103
|
|
107
104
|
sock.identity = ''
|
108
|
-
sock.identity.
|
105
|
+
expect(sock.identity).to eq('')
|
109
106
|
sock.close
|
110
107
|
end
|
111
108
|
|
@@ -113,7 +110,7 @@ module ZMQ
|
|
113
110
|
sock = Socket.new @ctx.pointer, ZMQ::REQ
|
114
111
|
|
115
112
|
sock.identity = 'a'
|
116
|
-
sock.identity.
|
113
|
+
expect(sock.identity).to eq('a')
|
117
114
|
sock.close
|
118
115
|
end
|
119
116
|
|
@@ -121,7 +118,7 @@ module ZMQ
|
|
121
118
|
sock = Socket.new @ctx.pointer, ZMQ::REQ
|
122
119
|
|
123
120
|
sock.identity = ('a' * 255)
|
124
|
-
sock.identity.
|
121
|
+
expect(sock.identity).to eq('a' * 255)
|
125
122
|
sock.close
|
126
123
|
end
|
127
124
|
|
@@ -129,7 +126,7 @@ module ZMQ
|
|
129
126
|
sock = Socket.new @ctx.pointer, ZMQ::REQ
|
130
127
|
|
131
128
|
sock.identity = 7
|
132
|
-
sock.identity.
|
129
|
+
expect(sock.identity).to eq('7')
|
133
130
|
sock.close
|
134
131
|
end
|
135
132
|
end # context identity=
|
@@ -160,8 +157,8 @@ module ZMQ
|
|
160
157
|
|
161
158
|
array = []
|
162
159
|
rc = socket.getsockopt(ZMQ::IDENTITY, array)
|
163
|
-
rc.
|
164
|
-
array[0].
|
160
|
+
expect(rc).to eq(0)
|
161
|
+
expect(array[0]).to eq(identity)
|
165
162
|
end
|
166
163
|
end
|
167
164
|
|
@@ -169,138 +166,63 @@ module ZMQ
|
|
169
166
|
identity = 'a' * 256
|
170
167
|
array = []
|
171
168
|
rc = socket.setsockopt(ZMQ::IDENTITY, identity)
|
172
|
-
rc.
|
169
|
+
expect(rc).to eq(-1)
|
173
170
|
end
|
174
171
|
end # context using option ZMQ::IDENTITY
|
175
172
|
|
173
|
+
context "using option ZMQ::IPV4ONLY" do
|
174
|
+
it "should enable use of IPV6 sockets when set to 0" do
|
175
|
+
value = 0
|
176
|
+
socket.setsockopt ZMQ::IPV4ONLY, value
|
177
|
+
array = []
|
178
|
+
rc = socket.getsockopt(ZMQ::IPV4ONLY, array)
|
179
|
+
expect(rc).to eq(0)
|
180
|
+
expect(array[0]).to eq(value)
|
181
|
+
end
|
176
182
|
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
rc = socket.getsockopt(ZMQ::HWM, array)
|
185
|
-
rc.should == 0
|
186
|
-
array[0].should == hwm
|
187
|
-
end
|
188
|
-
end # context using option ZMQ::HWM
|
189
|
-
|
190
|
-
|
191
|
-
context "using option ZMQ::SWAP" do
|
192
|
-
it "should set the swap value given a positive value" do
|
193
|
-
swap = 10_000
|
194
|
-
socket.setsockopt ZMQ::SWAP, swap
|
195
|
-
array = []
|
196
|
-
rc = socket.getsockopt(ZMQ::SWAP, array)
|
197
|
-
rc.should == 0
|
198
|
-
array[0].should == swap
|
199
|
-
end
|
200
|
-
|
201
|
-
it "returns -1 given a negative value" do
|
202
|
-
swap = -10_000
|
203
|
-
rc = socket.setsockopt(ZMQ::SWAP, swap)
|
204
|
-
rc.should == -1
|
205
|
-
end
|
206
|
-
end # context using option ZMQ::SWP
|
207
|
-
|
208
|
-
|
209
|
-
context "using option ZMQ::MCAST_LOOP" do
|
210
|
-
it "should enable the multicast loopback given a 1 (true) value" do
|
211
|
-
socket.setsockopt ZMQ::MCAST_LOOP, 1
|
212
|
-
array = []
|
213
|
-
rc = socket.getsockopt(ZMQ::MCAST_LOOP, array)
|
214
|
-
rc.should == 0
|
215
|
-
array[0].should be_true
|
216
|
-
end
|
217
|
-
|
218
|
-
it "should disable the multicast loopback given a 0 (false) value" do
|
219
|
-
socket.setsockopt ZMQ::MCAST_LOOP, 0
|
220
|
-
array = []
|
221
|
-
rc = socket.getsockopt(ZMQ::MCAST_LOOP, array)
|
222
|
-
rc.should == 0
|
223
|
-
array[0].should be_false
|
224
|
-
end
|
225
|
-
end # context using option ZMQ::MCAST_LOOP
|
226
|
-
|
227
|
-
|
228
|
-
context "using option ZMQ::RECOVERY_IVL_MSEC" do
|
229
|
-
it "should set the time interval for saving messages measured in milliseconds given a positive value" do
|
230
|
-
value = 200
|
231
|
-
socket.setsockopt ZMQ::RECOVERY_IVL_MSEC, value
|
232
|
-
array = []
|
233
|
-
rc = socket.getsockopt(ZMQ::RECOVERY_IVL_MSEC, array)
|
234
|
-
rc.should == 0
|
235
|
-
array[0].should == value
|
236
|
-
end
|
237
|
-
|
238
|
-
it "should default to a value of -1" do
|
239
|
-
value = -1
|
240
|
-
array = []
|
241
|
-
rc = socket.getsockopt(ZMQ::RECOVERY_IVL_MSEC, array)
|
242
|
-
rc.should == 0
|
243
|
-
array[0].should == value
|
244
|
-
end
|
245
|
-
end # context using option ZMQ::RECOVERY_IVL_MSEC
|
246
|
-
|
247
|
-
else # version3 or higher
|
248
|
-
|
249
|
-
context "using option ZMQ::IPV4ONLY" do
|
250
|
-
it "should enable use of IPV6 sockets when set to 0" do
|
251
|
-
value = 0
|
252
|
-
socket.setsockopt ZMQ::IPV4ONLY, value
|
253
|
-
array = []
|
254
|
-
rc = socket.getsockopt(ZMQ::IPV4ONLY, array)
|
255
|
-
rc.should == 0
|
256
|
-
array[0].should == value
|
257
|
-
end
|
258
|
-
|
259
|
-
it "should default to a value of 1" do
|
260
|
-
value = 1
|
261
|
-
array = []
|
262
|
-
rc = socket.getsockopt(ZMQ::IPV4ONLY, array)
|
263
|
-
rc.should == 0
|
264
|
-
array[0].should == value
|
265
|
-
end
|
266
|
-
|
267
|
-
it "returns -1 given a negative value" do
|
268
|
-
value = -1
|
269
|
-
rc = socket.setsockopt ZMQ::IPV4ONLY, value
|
270
|
-
rc.should == -1
|
271
|
-
end
|
183
|
+
it "should default to a value of 1" do
|
184
|
+
value = 1
|
185
|
+
array = []
|
186
|
+
rc = socket.getsockopt(ZMQ::IPV4ONLY, array)
|
187
|
+
expect(rc).to eq(0)
|
188
|
+
expect(array[0]).to eq(value)
|
189
|
+
end
|
272
190
|
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
end # context using option ZMQ::IPV4ONLY
|
191
|
+
it "returns -1 given a negative value" do
|
192
|
+
value = -1
|
193
|
+
rc = socket.setsockopt ZMQ::IPV4ONLY, value
|
194
|
+
expect(rc).to eq(-1)
|
195
|
+
end
|
279
196
|
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
rc = socket.getsockopt(ZMQ::LAST_ENDPOINT, array)
|
285
|
-
ZMQ::Util.resultcode_ok?(rc).should == true
|
286
|
-
endpoint_regex = %r{\Atcp://(.*):(\d+)\0\z}
|
287
|
-
array[0].should =~ endpoint_regex
|
288
|
-
Integer(array[0][endpoint_regex, 2]).should == random_port
|
289
|
-
end
|
197
|
+
it "returns -1 given a value > 1" do
|
198
|
+
value = 2
|
199
|
+
rc = socket.setsockopt ZMQ::IPV4ONLY, value
|
200
|
+
expect(rc).to eq(-1)
|
290
201
|
end
|
291
|
-
end #
|
202
|
+
end # context using option ZMQ::IPV4ONLY
|
292
203
|
|
204
|
+
context "using option ZMQ::LAST_ENDPOINT" do
|
205
|
+
it "should return last enpoint" do
|
206
|
+
random_port = bind_to_random_tcp_port(socket, max_tries = 500)
|
207
|
+
array = []
|
208
|
+
rc = socket.getsockopt(ZMQ::LAST_ENDPOINT, array)
|
209
|
+
expect(ZMQ::Util.resultcode_ok?(rc)).to eq(true)
|
210
|
+
endpoint_regex = %r{\Atcp://(.*):(\d+)\0\z}
|
211
|
+
expect(array[0]).to match(endpoint_regex)
|
212
|
+
expect(Integer(array[0][endpoint_regex, 2])).to eq(random_port)
|
213
|
+
end
|
214
|
+
end
|
293
215
|
|
294
216
|
context "using option ZMQ::SUBSCRIBE" do
|
295
217
|
if ZMQ::SUB == socket_type
|
296
218
|
it "returns 0 for a SUB socket" do
|
297
219
|
rc = socket.setsockopt(ZMQ::SUBSCRIBE, "topic.string")
|
298
|
-
rc.
|
220
|
+
expect(rc).to eq(0)
|
299
221
|
end
|
300
222
|
else
|
301
223
|
it "returns -1 for non-SUB sockets" do
|
302
224
|
rc = socket.setsockopt(ZMQ::SUBSCRIBE, "topic.string")
|
303
|
-
rc.
|
225
|
+
expect(rc).to eq(-1)
|
304
226
|
end
|
305
227
|
end
|
306
228
|
end # context using option ZMQ::SUBSCRIBE
|
@@ -311,13 +233,13 @@ module ZMQ
|
|
311
233
|
it "returns 0 given a topic string that was previously subscribed" do
|
312
234
|
socket.setsockopt ZMQ::SUBSCRIBE, "topic.string"
|
313
235
|
rc = socket.setsockopt(ZMQ::UNSUBSCRIBE, "topic.string")
|
314
|
-
rc.
|
236
|
+
expect(rc).to eq(0)
|
315
237
|
end
|
316
238
|
|
317
239
|
else
|
318
240
|
it "returns -1 for non-SUB sockets" do
|
319
241
|
rc = socket.setsockopt(ZMQ::UNSUBSCRIBE, "topic.string")
|
320
|
-
rc.
|
242
|
+
expect(rc).to eq(-1)
|
321
243
|
end
|
322
244
|
end
|
323
245
|
end # context using option ZMQ::UNSUBSCRIBE
|
@@ -329,8 +251,8 @@ module ZMQ
|
|
329
251
|
socket.setsockopt ZMQ::AFFINITY, affinity
|
330
252
|
array = []
|
331
253
|
rc = socket.getsockopt(ZMQ::AFFINITY, array)
|
332
|
-
rc.
|
333
|
-
array[0].
|
254
|
+
expect(rc).to eq(0)
|
255
|
+
expect(array[0]).to eq(affinity)
|
334
256
|
end
|
335
257
|
end # context using option ZMQ::AFFINITY
|
336
258
|
|
@@ -341,14 +263,14 @@ module ZMQ
|
|
341
263
|
socket.setsockopt ZMQ::RATE, rate
|
342
264
|
array = []
|
343
265
|
rc = socket.getsockopt(ZMQ::RATE, array)
|
344
|
-
rc.
|
345
|
-
array[0].
|
266
|
+
expect(rc).to eq(0)
|
267
|
+
expect(array[0]).to eq(rate)
|
346
268
|
end
|
347
269
|
|
348
270
|
it "returns -1 given a negative value" do
|
349
271
|
rate = -200
|
350
272
|
rc = socket.setsockopt ZMQ::RATE, rate
|
351
|
-
rc.
|
273
|
+
expect(rc).to eq(-1)
|
352
274
|
end
|
353
275
|
end # context using option ZMQ::RATE
|
354
276
|
|
@@ -359,14 +281,14 @@ module ZMQ
|
|
359
281
|
socket.setsockopt ZMQ::RECOVERY_IVL, rate
|
360
282
|
array = []
|
361
283
|
rc = socket.getsockopt(ZMQ::RECOVERY_IVL, array)
|
362
|
-
rc.
|
363
|
-
array[0].
|
284
|
+
expect(rc).to eq(0)
|
285
|
+
expect(array[0]).to eq(rate)
|
364
286
|
end
|
365
287
|
|
366
288
|
it "returns -1 given a negative value" do
|
367
289
|
rate = -200
|
368
290
|
rc = socket.setsockopt ZMQ::RECOVERY_IVL, rate
|
369
|
-
rc.
|
291
|
+
expect(rc).to eq(-1)
|
370
292
|
end
|
371
293
|
end # context using option ZMQ::RECOVERY_IVL
|
372
294
|
|
@@ -377,8 +299,8 @@ module ZMQ
|
|
377
299
|
socket.setsockopt ZMQ::SNDBUF, size
|
378
300
|
array = []
|
379
301
|
rc = socket.getsockopt(ZMQ::SNDBUF, array)
|
380
|
-
rc.
|
381
|
-
array[0].
|
302
|
+
expect(rc).to eq(0)
|
303
|
+
expect(array[0]).to eq(size)
|
382
304
|
end
|
383
305
|
end # context using option ZMQ::SNDBUF
|
384
306
|
|
@@ -389,8 +311,8 @@ module ZMQ
|
|
389
311
|
socket.setsockopt ZMQ::RCVBUF, size
|
390
312
|
array = []
|
391
313
|
rc = socket.getsockopt(ZMQ::RCVBUF, array)
|
392
|
-
rc.
|
393
|
-
array[0].
|
314
|
+
expect(rc).to eq(0)
|
315
|
+
expect(array[0]).to eq(size)
|
394
316
|
end
|
395
317
|
end # context using option ZMQ::RCVBUF
|
396
318
|
|
@@ -401,8 +323,8 @@ module ZMQ
|
|
401
323
|
socket.setsockopt ZMQ::LINGER, value
|
402
324
|
array = []
|
403
325
|
rc = socket.getsockopt(ZMQ::LINGER, array)
|
404
|
-
rc.
|
405
|
-
array[0].
|
326
|
+
expect(rc).to eq(0)
|
327
|
+
expect(array[0]).to eq(value)
|
406
328
|
end
|
407
329
|
|
408
330
|
it "should set the socket message linger option to 0 for dropping packets" do
|
@@ -410,27 +332,17 @@ module ZMQ
|
|
410
332
|
socket.setsockopt ZMQ::LINGER, value
|
411
333
|
array = []
|
412
334
|
rc = socket.getsockopt(ZMQ::LINGER, array)
|
413
|
-
rc.
|
414
|
-
array[0].
|
335
|
+
expect(rc).to eq(0)
|
336
|
+
expect(array[0]).to eq(value)
|
415
337
|
end
|
416
338
|
|
417
|
-
if (ZMQ::SUB == socket_type) && version3? || (defined?(ZMQ::XSUB) && ZMQ::XSUB == socket_type)
|
418
339
|
it "should default to a value of 0" do
|
419
|
-
value = 0
|
420
|
-
array = []
|
421
|
-
rc = socket.getsockopt(ZMQ::LINGER, array)
|
422
|
-
rc.should == 0
|
423
|
-
array[0].should == value
|
424
|
-
end
|
425
|
-
else
|
426
|
-
it "should default to a value of -1" do
|
427
|
-
value = -1
|
340
|
+
value = [SUB, XSUB].include?(socket_type) ? 0 : -1
|
428
341
|
array = []
|
429
342
|
rc = socket.getsockopt(ZMQ::LINGER, array)
|
430
|
-
rc.
|
431
|
-
array[0].
|
343
|
+
expect(rc).to eq(0)
|
344
|
+
expect(array[0]).to eq(value)
|
432
345
|
end
|
433
|
-
end
|
434
346
|
end # context using option ZMQ::LINGER
|
435
347
|
|
436
348
|
|
@@ -440,16 +352,16 @@ module ZMQ
|
|
440
352
|
socket.setsockopt ZMQ::RECONNECT_IVL, value
|
441
353
|
array = []
|
442
354
|
rc = socket.getsockopt(ZMQ::RECONNECT_IVL, array)
|
443
|
-
rc.
|
444
|
-
array[0].
|
355
|
+
expect(rc).to eq(0)
|
356
|
+
expect(array[0]).to eq(value)
|
445
357
|
end
|
446
358
|
|
447
359
|
it "should default to a value of 100" do
|
448
360
|
value = 100
|
449
361
|
array = []
|
450
362
|
rc = socket.getsockopt(ZMQ::RECONNECT_IVL, array)
|
451
|
-
rc.
|
452
|
-
array[0].
|
363
|
+
expect(rc).to eq(0)
|
364
|
+
expect(array[0]).to eq(value)
|
453
365
|
end
|
454
366
|
end # context using option ZMQ::RECONNECT_IVL
|
455
367
|
|
@@ -457,19 +369,20 @@ module ZMQ
|
|
457
369
|
context "using option ZMQ::BACKLOG" do
|
458
370
|
it "should set the maximum number of pending socket connections given a positive value" do
|
459
371
|
value = 200
|
460
|
-
socket.setsockopt ZMQ::BACKLOG, value
|
372
|
+
rc = socket.setsockopt ZMQ::BACKLOG, value
|
373
|
+
expect(rc).to eq(0)
|
461
374
|
array = []
|
462
375
|
rc = socket.getsockopt(ZMQ::BACKLOG, array)
|
463
|
-
rc.
|
464
|
-
array[0].
|
376
|
+
expect(rc).to eq(0)
|
377
|
+
expect(array[0]).to eq(value)
|
465
378
|
end
|
466
379
|
|
467
380
|
it "should default to a value of 100" do
|
468
381
|
value = 100
|
469
382
|
array = []
|
470
383
|
rc = socket.getsockopt(ZMQ::BACKLOG, array)
|
471
|
-
rc.
|
472
|
-
array[0].
|
384
|
+
expect(rc).to eq(0)
|
385
|
+
expect(array[0]).to eq(value)
|
473
386
|
end
|
474
387
|
end # context using option ZMQ::BACKLOG
|
475
388
|
|
@@ -495,8 +408,8 @@ module ZMQ
|
|
495
408
|
it "should return an FD as a positive integer" do
|
496
409
|
array = []
|
497
410
|
rc = socket.getsockopt(ZMQ::FD, array)
|
498
|
-
rc.
|
499
|
-
array[0].
|
411
|
+
expect(rc).to eq(0)
|
412
|
+
expect(array[0]).to be > 0
|
500
413
|
end
|
501
414
|
|
502
415
|
it "returns a valid FD that is accepted by the system poll() function" do
|
@@ -514,14 +427,14 @@ module ZMQ
|
|
514
427
|
|
515
428
|
class PollFD < FFI::Struct
|
516
429
|
layout :fd, :int,
|
517
|
-
|
518
|
-
|
430
|
+
:events, :short,
|
431
|
+
:revents, :short
|
519
432
|
end
|
520
433
|
end # module LibSocket
|
521
434
|
|
522
435
|
array = []
|
523
436
|
rc = socket.getsockopt(ZMQ::FD, array)
|
524
|
-
rc.
|
437
|
+
expect(rc).to eq(0)
|
525
438
|
fd = array[0]
|
526
439
|
|
527
440
|
# setup the BSD poll_fd struct
|
@@ -531,18 +444,18 @@ module ZMQ
|
|
531
444
|
pollfd[:revents] = 0
|
532
445
|
|
533
446
|
rc = LibSocket.poll(pollfd, 1, 0)
|
534
|
-
rc.
|
447
|
+
expect(rc).to eq(0)
|
535
448
|
end
|
536
449
|
end
|
537
450
|
|
538
451
|
end # posix platform
|
539
452
|
|
540
453
|
context "using option ZMQ::EVENTS" do
|
541
|
-
it "should return a mask of events as
|
454
|
+
it "should return a mask of events as an Integer" do
|
542
455
|
array = []
|
543
456
|
rc = socket.getsockopt(ZMQ::EVENTS, array)
|
544
|
-
rc.
|
545
|
-
array[0].
|
457
|
+
expect(rc).to eq(0)
|
458
|
+
expect(array[0]).to be_a(Integer)
|
546
459
|
end
|
547
460
|
end
|
548
461
|
|
@@ -550,8 +463,8 @@ module ZMQ
|
|
550
463
|
it "should return the socket type" do
|
551
464
|
array = []
|
552
465
|
rc = socket.getsockopt(ZMQ::TYPE, array)
|
553
|
-
rc.
|
554
|
-
array[0].
|
466
|
+
expect(rc).to eq(0)
|
467
|
+
expect(array[0]).to eq(socket_type)
|
555
468
|
end
|
556
469
|
end
|
557
470
|
end # context #getsockopt
|
@@ -566,29 +479,29 @@ module ZMQ
|
|
566
479
|
it "SUB socket that received a message always has POLLIN set" do
|
567
480
|
events = []
|
568
481
|
rc = @sub.getsockopt(ZMQ::EVENTS, events)
|
569
|
-
rc.
|
570
|
-
events[0].
|
482
|
+
expect(rc).to eq(0)
|
483
|
+
expect(events[0]).to eq ZMQ::POLLIN
|
571
484
|
end
|
572
485
|
|
573
486
|
it "PUB socket always has POLLOUT set" do
|
574
487
|
events = []
|
575
488
|
rc = @pub.getsockopt(ZMQ::EVENTS, events)
|
576
|
-
rc.
|
577
|
-
events[0].
|
489
|
+
expect(rc).to eq(0)
|
490
|
+
expect(events[0]).to eq ZMQ::POLLOUT
|
578
491
|
end
|
579
492
|
|
580
493
|
it "PUB socket never has POLLIN set" do
|
581
494
|
events = []
|
582
495
|
rc = @pub.getsockopt(ZMQ::EVENTS, events)
|
583
|
-
rc.
|
584
|
-
events[0].
|
496
|
+
expect(rc).to eq(0)
|
497
|
+
expect(events[0]).not_to eq ZMQ::POLLIN
|
585
498
|
end
|
586
499
|
|
587
500
|
it "SUB socket never has POLLOUT set" do
|
588
501
|
events = []
|
589
502
|
rc = @sub.getsockopt(ZMQ::EVENTS, events)
|
590
|
-
rc.
|
591
|
-
events[0].
|
503
|
+
expect(rc).to eq(0)
|
504
|
+
expect(events[0]).not_to eq ZMQ::POLLOUT
|
592
505
|
end
|
593
506
|
end # shared example for pubsub
|
594
507
|
|
@@ -601,7 +514,7 @@ module ZMQ
|
|
601
514
|
endpoint = "inproc://socket_test"
|
602
515
|
@sub = @ctx.socket ZMQ::SUB
|
603
516
|
rc = @sub.setsockopt ZMQ::SUBSCRIBE, ''
|
604
|
-
rc.
|
517
|
+
expect(rc).to eq(0)
|
605
518
|
|
606
519
|
@pub = @ctx.socket ZMQ::PUB
|
607
520
|
@sub.bind(endpoint)
|
data/spec/spec_helper.rb
CHANGED
@@ -1,11 +1,7 @@
|
|
1
|
-
# To run these specs using rake, make sure the 'bones' and 'bones-extras'
|
2
|
-
# gems are installed. Then execute 'rake spec' from the main directory
|
3
|
-
# to run all specs.
|
4
1
|
|
5
2
|
require File.expand_path(
|
6
3
|
File.join(File.dirname(__FILE__), %w[.. lib ffi-rzmq]))
|
7
4
|
|
8
|
-
require 'thread' # necessary when testing in MRI 1.8 mode
|
9
5
|
Thread.abort_on_exception = true
|
10
6
|
|
11
7
|
require 'openssl'
|
@@ -14,12 +10,8 @@ require 'securerandom'
|
|
14
10
|
|
15
11
|
# define some version guards so we can turn on/off specs based upon
|
16
12
|
# the version of the 0mq library that is loaded
|
17
|
-
def
|
18
|
-
ZMQ::LibZMQ.
|
19
|
-
end
|
20
|
-
|
21
|
-
def version3?
|
22
|
-
ZMQ::LibZMQ.version3?
|
13
|
+
def version4?
|
14
|
+
ZMQ::LibZMQ.version4?
|
23
15
|
end
|
24
16
|
|
25
17
|
def jruby?
|
@@ -35,7 +27,7 @@ end
|
|
35
27
|
|
36
28
|
module APIHelper
|
37
29
|
def poller_setup
|
38
|
-
@helper_poller
|
30
|
+
@helper_poller = ZMQ::Poller.new
|
39
31
|
end
|
40
32
|
|
41
33
|
def poller_register_socket(socket)
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# Copied from Debian:
|
2
|
+
# https://salsa.debian.org/ruby-team/ruby-ffi-rzmq/commit/15ad9dd6f4c3358acbd7db2c7e288aae2d5efcf8
|
3
|
+
#
|
4
|
+
# Script should be run from the spec/support directory.
|
5
|
+
#
|
6
|
+
|
7
|
+
require "openssl"
|
8
|
+
|
9
|
+
key = OpenSSL::PKey::RSA.new 4096
|
10
|
+
|
11
|
+
open 'private_key.pem', 'w' do |io| io.write key.to_pem end
|
12
|
+
open 'public_key.pem', 'w' do |io| io.write key.public_key.to_pem end
|
13
|
+
|
14
|
+
|
15
|
+
name = OpenSSL::X509::Name.parse 'CN=nobody/DC=example'
|
16
|
+
|
17
|
+
cert = OpenSSL::X509::Certificate.new
|
18
|
+
cert.version = 2
|
19
|
+
cert.serial = 0
|
20
|
+
cert.not_before = Time.now
|
21
|
+
cert.not_after = Time.now + 3600*24*365*10
|
22
|
+
|
23
|
+
cert.public_key = key.public_key
|
24
|
+
cert.subject = name
|
25
|
+
cert.issuer = name
|
26
|
+
|
27
|
+
extension_factory = OpenSSL::X509::ExtensionFactory.new
|
28
|
+
extension_factory.subject_certificate = cert
|
29
|
+
extension_factory.issuer_certificate = cert
|
30
|
+
|
31
|
+
cert.add_extension \
|
32
|
+
extension_factory.create_extension('subjectKeyIdentifier', 'hash')
|
33
|
+
cert.sign key, OpenSSL::Digest::SHA1.new
|
34
|
+
open 'ca.pem', 'w' do |io|
|
35
|
+
io.write cert.to_pem
|
36
|
+
end
|
37
|
+
|
38
|
+
require 'fileutils'
|
39
|
+
|
40
|
+
FileUtils.cp 'ca.pem', 'test.crt'
|
41
|
+
FileUtils.cp 'private_key.pem', 'test.key'
|