ffi-rzmq 1.0.3 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +7 -0
  2. data/.travis.yml +1 -1
  3. data/AUTHORS.txt +5 -1
  4. data/History.txt +24 -0
  5. data/README.rdoc +2 -4
  6. data/examples/README.rdoc +1 -3
  7. data/examples/{v3api/latency_measurement.rb → latency_measurement.rb} +1 -2
  8. data/examples/{v3api/local_lat.rb → local_lat.rb} +1 -1
  9. data/examples/{v3api/local_lat_poll.rb → local_lat_poll.rb} +4 -4
  10. data/examples/{v3api/local_throughput.rb → local_throughput.rb} +1 -1
  11. data/examples/{v3api/pub.rb → pub.rb} +1 -1
  12. data/examples/{v2api/publish_subscribe.rb → publish_subscribe.rb} +2 -2
  13. data/examples/{v2api/remote_lat.rb → remote_lat.rb} +1 -1
  14. data/examples/{v3api/remote_throughput.rb → remote_throughput.rb} +4 -3
  15. data/examples/repreq_over_curve.rb +60 -0
  16. data/examples/{v2api/reqrep_poll.rb → reqrep_poll.rb} +3 -4
  17. data/examples/{v2api/request_response.rb → request_response.rb} +1 -2
  18. data/examples/{v3api/sub.rb → sub.rb} +1 -2
  19. data/examples/{v3api/throughput_measurement.rb → throughput_measurement.rb} +1 -1
  20. data/examples/{v3api/xreqxrep_poll.rb → xreqxrep_poll.rb} +6 -7
  21. data/ffi-rzmq.gemspec +4 -4
  22. data/lib/ffi-rzmq/context.rb +25 -53
  23. data/lib/ffi-rzmq/device.rb +8 -4
  24. data/lib/ffi-rzmq/exceptions.rb +3 -0
  25. data/lib/ffi-rzmq/message.rb +24 -30
  26. data/lib/ffi-rzmq/poll.rb +5 -16
  27. data/lib/ffi-rzmq/socket.rb +132 -282
  28. data/lib/ffi-rzmq/util.rb +28 -36
  29. data/lib/ffi-rzmq/version.rb +1 -1
  30. data/lib/ffi-rzmq.rb +2 -3
  31. data/spec/context_spec.rb +3 -8
  32. data/spec/device_spec.rb +10 -9
  33. data/spec/nonblocking_recv_spec.rb +7 -7
  34. data/spec/pushpull_spec.rb +8 -7
  35. data/spec/reqrep_spec.rb +6 -6
  36. data/spec/socket_spec.rb +43 -130
  37. data/spec/spec_helper.rb +3 -11
  38. data/spec/util_spec.rb +28 -0
  39. metadata +80 -104
  40. data/examples/v2api/latency_measurement.rb +0 -139
  41. data/examples/v2api/local_lat.rb +0 -58
  42. data/examples/v2api/local_lat_poll.rb +0 -66
  43. data/examples/v2api/local_throughput.rb +0 -58
  44. data/examples/v2api/pub.rb +0 -46
  45. data/examples/v2api/remote_throughput.rb +0 -39
  46. data/examples/v2api/sub.rb +0 -74
  47. data/examples/v2api/throughput_measurement.rb +0 -138
  48. data/examples/v2api/xreqxrep_poll.rb +0 -93
  49. data/examples/v3api/publish_subscribe.rb +0 -82
  50. data/examples/v3api/remote_lat.rb +0 -71
  51. data/examples/v3api/reqrep_poll.rb +0 -62
  52. data/examples/v3api/request_response.rb +0 -40
  53. data/lib/ffi-rzmq/constants.rb +0 -187
  54. data/lib/ffi-rzmq/libc.rb +0 -19
  55. data/lib/ffi-rzmq/libzmq.rb +0 -283
data/lib/ffi-rzmq/util.rb CHANGED
@@ -5,6 +5,23 @@ module ZMQ
5
5
  #
6
6
  class Util
7
7
 
8
+ # Generate and return a CURVE public/private keypair
9
+ #
10
+ # Raises an error if ZeroMQ is not configured for CURVE connections.
11
+ # Install libsodium if this is the case.
12
+ def self.curve_keypair
13
+ public_key = FFI::MemoryPointer.from_string(' ' * 41)
14
+ private_key = FFI::MemoryPointer.from_string(' ' * 41)
15
+ rc = LibZMQ.zmq_curve_keypair public_key, private_key
16
+
17
+ if rc < 0
18
+ raise NotSupportedError.new "zmq_curve_keypair" , rc, ZMQ::Util.errno,
19
+ "Rebuild zeromq with libsodium to enable CURVE security options."
20
+ end
21
+
22
+ [public_key.read_string, private_key.read_string]
23
+ end
24
+
8
25
  # Returns true when +rc+ is greater than or equal to 0, false otherwise.
9
26
  #
10
27
  # We use the >= test because zmq_poll() returns the number of sockets
@@ -28,19 +45,6 @@ module ZMQ
28
45
  LibZMQ.zmq_strerror(errno).read_string
29
46
  end
30
47
 
31
- # Returns an array of the form [major, minor, patch] to represent the
32
- # version of libzmq.
33
- #
34
- # Class method! Invoke as: ZMQ::Util.version
35
- #
36
- def self.version
37
- major = FFI::MemoryPointer.new :int
38
- minor = FFI::MemoryPointer.new :int
39
- patch = FFI::MemoryPointer.new :int
40
- LibZMQ.zmq_version major, minor, patch
41
- [major.read_int, minor.read_int, patch.read_int]
42
- end
43
-
44
48
  # Attempts to bind to a random tcp port on +host+ up to +max_tries+
45
49
  # times. Returns the port number upon success or nil upon failure.
46
50
  #
@@ -56,7 +60,7 @@ module ZMQ
56
60
 
57
61
  resultcode_ok?(rc) ? random : nil
58
62
  end
59
-
63
+
60
64
  # :doc:
61
65
  # Called to verify whether there were any errors during
62
66
  # operation. If any are found, raise the appropriate #ZeroMQError.
@@ -90,38 +94,26 @@ module ZMQ
90
94
 
91
95
  else
92
96
  raise ZeroMQError.new source, result_code, -1,
93
- "Source [#{source}] does not match any zmq_* strings, rc [#{result_code}], errno [#{ZMQ::Util.errno}], error_string [#{ZMQ::Util.error_string}]"
97
+ "Source [#{source}] does not match any zmq_* strings, rc [#{result_code}], errno [#{ZMQ::Util.errno}], error_string [#{ZMQ::Util.error_string}]"
94
98
  end
95
99
  end
96
100
 
97
101
  def self.eagain?
98
102
  EAGAIN == ZMQ::Util.errno
99
103
  end
100
-
101
- if LibZMQ.version2?
102
- def self.context_error?(source)
103
- 'zmq_init' == source ||
104
- 'zmq_socket' == source
105
- end
106
-
107
- def self.message_error?(source)
108
- ['zmq_msg_init', 'zmq_msg_init_data', 'zmq_msg_copy', 'zmq_msg_move'].include?(source)
109
- end
110
-
111
- elsif LibZMQ.version3?
112
- def self.context_error?(source)
113
- 'zmq_ctx_new' == source ||
104
+
105
+ def self.context_error?(source)
106
+ 'zmq_ctx_new' == source ||
114
107
  'zmq_ctx_set' == source ||
115
108
  'zmq_ctx_get' == source ||
116
109
  'zmq_ctx_destory' == source ||
117
110
  'zmq_ctx_set_monitor' == source
118
- end
119
-
120
- def self.message_error?(source)
121
- ['zmq_msg_init', 'zmq_msg_init_data', 'zmq_msg_copy', 'zmq_msg_move', 'zmq_msg_close', 'zmq_msg_get',
122
- 'zmq_msg_more', 'zmq_msg_recv', 'zmq_msg_send', 'zmq_msg_set'].include?(source)
123
- end
124
- end # if LibZMQ.version...?
111
+ end
112
+
113
+ def self.message_error?(source)
114
+ ['zmq_msg_init', 'zmq_msg_init_data', 'zmq_msg_copy', 'zmq_msg_move', 'zmq_msg_close', 'zmq_msg_get',
115
+ 'zmq_msg_more', 'zmq_msg_recv', 'zmq_msg_send', 'zmq_msg_set'].include?(source)
116
+ end
125
117
 
126
118
  end # module Util
127
119
 
@@ -1,3 +1,3 @@
1
1
  module ZMQ
2
- VERSION = "1.0.3"
2
+ VERSION = "2.0.1"
3
3
  end
data/lib/ffi-rzmq.rb CHANGED
@@ -63,10 +63,9 @@ end # module ZMQ
63
63
  # some code is conditionalized based upon what ruby engine we are
64
64
  # executing
65
65
 
66
- require 'ffi'
66
+ require 'ffi-rzmq-core'
67
67
 
68
68
  # the order of files is important
69
- #%w(wrapper zmq exceptions context message socket poll_items poll device).each do |file|
70
- %w(libc libzmq constants util exceptions context message socket poll_items poll_item poll device).each do |file|
69
+ %w(util exceptions context message socket poll_items poll_item poll device).each do |file|
71
70
  require ZMQ.libpath(['ffi-rzmq', file])
72
71
  end
data/spec/context_spec.rb CHANGED
@@ -84,14 +84,9 @@ module ZMQ
84
84
 
85
85
  it "should call the correct library function to terminate the context" do
86
86
  ctx = Context.new
87
-
88
- if LibZMQ.version2?
89
- LibZMQ.should_receive(:zmq_term).and_return(0)
90
- ctx.terminate
91
- else
92
- LibZMQ.should_receive(:zmq_ctx_destroy).with(ctx.pointer).and_return(0)
93
- ctx.terminate
94
- end
87
+
88
+ LibZMQ.should_receive(:zmq_ctx_destroy).with(ctx.pointer).and_return(0)
89
+ ctx.terminate
95
90
  end
96
91
  end # context terminate
97
92
 
data/spec/device_spec.rb CHANGED
@@ -5,7 +5,7 @@ module ZMQ
5
5
  describe Device do
6
6
  include APIHelper
7
7
 
8
- before(:all) do
8
+ before(:each) do
9
9
  @ctx = Context.new
10
10
  poller_setup
11
11
  @front_endpoint = "inproc://device_front_test"
@@ -13,7 +13,7 @@ module ZMQ
13
13
  @mutex = Mutex.new
14
14
  end
15
15
 
16
- after(:all) do
16
+ after(:each) do
17
17
  @ctx.terminate
18
18
  end
19
19
 
@@ -26,7 +26,9 @@ module ZMQ
26
26
  front = @ctx.socket(ZMQ::PUSH)
27
27
  front.bind(@front_endpoint)
28
28
  @mutex.synchronize { @device_thread = true }
29
- Device.new(ZMQ::STREAMER, back, front)
29
+ puts "create streamer device and running..."
30
+ Device.new(back, front)
31
+ puts "device exited"
30
32
  back.close
31
33
  front.close
32
34
  end
@@ -34,12 +36,11 @@ module ZMQ
34
36
 
35
37
  def wait_for_device
36
38
  loop do
37
- can_break = false
38
- @mutex.synchronize do
39
- can_break = true if @device_thread
40
- end
39
+ can_break = @mutex.synchronize { @device_thread }
40
+
41
41
  break if can_break
42
42
  end
43
+ puts "broke out of wait_for_device loop"
43
44
  end
44
45
 
45
46
  it "should create a device without error given valid opts" do
@@ -61,7 +62,7 @@ module ZMQ
61
62
  end
62
63
 
63
64
  res = ''
64
- rc = puller.recv_string(res, ZMQ::NonBlocking)
65
+ rc = puller.recv_string(res, ZMQ::DONTWAIT)
65
66
  res.should == "hello"
66
67
 
67
68
  pusher.close
@@ -70,7 +71,7 @@ module ZMQ
70
71
 
71
72
  it "should raise an ArgumentError when trying to pass non-socket objects into the device" do
72
73
  lambda {
73
- Device.new(ZMQ::STREAMER, 1,2)
74
+ Device.new(1,2)
74
75
  }.should raise_exception(ArgumentError)
75
76
  end
76
77
  end
@@ -12,19 +12,19 @@ module ZMQ
12
12
 
13
13
  it "returns -1 when there are no messages to read" do
14
14
  array = []
15
- rc = @receiver.recvmsgs(array, ZMQ::NonBlocking)
15
+ rc = @receiver.recvmsgs(array, ZMQ::DONTWAIT)
16
16
  Util.resultcode_ok?(rc).should be_false
17
17
  end
18
18
 
19
19
  it "gets EAGAIN when there are no messages to read" do
20
20
  array = []
21
- rc = @receiver.recvmsgs(array, ZMQ::NonBlocking)
21
+ rc = @receiver.recvmsgs(array, ZMQ::DONTWAIT)
22
22
  ZMQ::Util.errno.should == ZMQ::EAGAIN
23
23
  end
24
24
 
25
25
  it "returns the given array unmodified when there are no messages to read" do
26
26
  array = []
27
- rc = @receiver.recvmsgs(array, ZMQ::NonBlocking)
27
+ rc = @receiver.recvmsgs(array, ZMQ::DONTWAIT)
28
28
  array.size.should be_zero
29
29
  end
30
30
 
@@ -39,7 +39,7 @@ module ZMQ
39
39
  end
40
40
 
41
41
  array = []
42
- rc = @receiver.recvmsgs(array, ZMQ::NonBlocking)
42
+ rc = @receiver.recvmsgs(array, ZMQ::DONTWAIT)
43
43
  Util.resultcode_ok?(rc).should be_true
44
44
  array.size.should == 1
45
45
  end
@@ -52,7 +52,7 @@ module ZMQ
52
52
  end
53
53
 
54
54
  array = []
55
- rc = @receiver.recvmsgs(array, ZMQ::NonBlocking)
55
+ rc = @receiver.recvmsgs(array, ZMQ::DONTWAIT)
56
56
  Util.resultcode_ok?(rc).should be_true
57
57
  array.size.should == 10
58
58
  end
@@ -68,7 +68,7 @@ module ZMQ
68
68
  end
69
69
 
70
70
  array = []
71
- rc = @receiver.recvmsgs(array, ZMQ::NonBlocking)
71
+ rc = @receiver.recvmsgs(array, ZMQ::DONTWAIT)
72
72
  Util.resultcode_ok?(rc).should be_true
73
73
  array.size.should == 1 + 1 # extra 1 for envelope
74
74
  end
@@ -81,7 +81,7 @@ module ZMQ
81
81
  end
82
82
 
83
83
  array = []
84
- rc = @receiver.recvmsgs(array, ZMQ::NonBlocking)
84
+ rc = @receiver.recvmsgs(array, ZMQ::DONTWAIT)
85
85
  Util.resultcode_ok?(rc).should be_true
86
86
  array.size.should == 10 + 1 # add 1 for the envelope
87
87
  end
@@ -44,11 +44,11 @@ module ZMQ
44
44
 
45
45
  poll_it_for_read(@pull) do
46
46
  rc = @push.sendmsg sent_message
47
- LibZMQ.version2? ? rc.should == 0 : rc.should == string.size
47
+ rc.should == string.size
48
48
  end
49
49
 
50
- rc = @pull.recvmsg received_message, ZMQ::NonBlocking
51
- LibZMQ.version2? ? rc.should == 0 : rc.should == string.size
50
+ rc = @pull.recvmsg received_message, ZMQ::DONTWAIT
51
+ rc.should == string.size
52
52
  received_message.copy_out_string.should == string
53
53
  end
54
54
 
@@ -71,15 +71,16 @@ module ZMQ
71
71
  sockets << @pull
72
72
 
73
73
  sockets.each do |socket|
74
- threads << Thread.new do
74
+ thr = Thread.new do
75
75
  buffer = ''
76
76
  rc = socket.recv_string buffer
77
- version2? ? (rc.should == 0) : (rc.should == buffer.size)
77
+ rc.should == buffer.size
78
78
  mutex.synchronize { received << buffer }
79
79
  socket.close
80
80
  end
81
+ threads << thr
81
82
  end
82
-
83
+
83
84
  count.times { @push.send_string(string) }
84
85
 
85
86
  threads.each {|t| t.join}
@@ -98,7 +99,7 @@ module ZMQ
98
99
  buffer = ''
99
100
  rc = 0
100
101
  mutex.synchronize { rc = @pull.recv_string buffer }
101
- version2? ? (rc.should == 0) : (rc.should == buffer.size)
102
+ rc.should == buffer.size
102
103
  mutex.synchronize { received << buffer }
103
104
  end
104
105
  end
data/spec/reqrep_spec.rb CHANGED
@@ -54,9 +54,9 @@ module ZMQ
54
54
  received_message = Message.new
55
55
 
56
56
  rc = @ping.sendmsg(Message.new(string))
57
- LibZMQ.version2? ? rc.should == 0 : rc.should == string.size
57
+ rc.should == string.size
58
58
  rc = @pong.recvmsg received_message
59
- LibZMQ.version2? ? rc.should == 0 : rc.should == string.size
59
+ rc.should == string.size
60
60
 
61
61
  received_message.copy_out_string.should == string
62
62
  end
@@ -66,12 +66,12 @@ module ZMQ
66
66
  received_message = Message.new
67
67
 
68
68
  poll_it_for_read(@pong) do
69
- rc = @ping.sendmsg(Message.new(string), ZMQ::NonBlocking)
70
- LibZMQ.version2? ? rc.should == 0 : rc.should == string.size
69
+ rc = @ping.sendmsg(Message.new(string), ZMQ::DONTWAIT)
70
+ rc.should == string.size
71
71
  end
72
72
 
73
- rc = @pong.recvmsg received_message, ZMQ::NonBlocking
74
- LibZMQ.version2? ? rc.should == 0 : rc.should == string.size
73
+ rc = @pong.recvmsg received_message, ZMQ::DONTWAIT
74
+ rc.should == string.size
75
75
 
76
76
  received_message.copy_out_string.should == string
77
77
  end
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 = if LibZMQ.version2?
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 }
@@ -173,123 +170,48 @@ module ZMQ
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
+ rc.should == 0
180
+ array[0].should == value
181
+ end
176
182
 
177
- if version2?
178
-
179
- context "using option ZMQ::HWM" do
180
- it "should set the high water mark given a positive value" do
181
- hwm = 4
182
- socket.setsockopt ZMQ::HWM, hwm
183
- array = []
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
+ rc.should == 0
188
+ array[0].should == value
189
+ end
272
190
 
273
- it "returns -1 given a value > 1" do
274
- value = 2
275
- rc = socket.setsockopt ZMQ::IPV4ONLY, value
276
- rc.should == -1
277
- end
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
+ rc.should == -1
195
+ end
279
196
 
280
- context "using option ZMQ::LAST_ENDPOINT" do
281
- it "should return last enpoint" do
282
- random_port = bind_to_random_tcp_port(socket, max_tries = 500)
283
- array = []
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
+ rc.should == -1
290
201
  end
291
- end # version2? if/else block
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
+ ZMQ::Util.resultcode_ok?(rc).should == true
210
+ endpoint_regex = %r{\Atcp://(.*):(\d+)\0\z}
211
+ array[0].should =~ endpoint_regex
212
+ Integer(array[0][endpoint_regex, 2]).should == random_port
213
+ end
214
+ end
293
215
 
294
216
  context "using option ZMQ::SUBSCRIBE" do
295
217
  if ZMQ::SUB == socket_type
@@ -414,23 +336,13 @@ module ZMQ
414
336
  array[0].should == 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
340
+ value = [SUB, XSUB].include?(socket_type) ? 0 : -1
420
341
  array = []
421
342
  rc = socket.getsockopt(ZMQ::LINGER, array)
422
343
  rc.should == 0
423
344
  array[0].should == value
424
345
  end
425
- else
426
- it "should default to a value of -1" do
427
- value = -1
428
- array = []
429
- rc = socket.getsockopt(ZMQ::LINGER, array)
430
- rc.should == 0
431
- array[0].should == value
432
- end
433
- end
434
346
  end # context using option ZMQ::LINGER
435
347
 
436
348
 
@@ -457,7 +369,8 @@ 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
+ rc.should == 0
461
374
  array = []
462
375
  rc = socket.getsockopt(ZMQ::BACKLOG, array)
463
376
  rc.should == 0
@@ -514,8 +427,8 @@ module ZMQ
514
427
 
515
428
  class PollFD < FFI::Struct
516
429
  layout :fd, :int,
517
- :events, :short,
518
- :revents, :short
430
+ :events, :short,
431
+ :revents, :short
519
432
  end
520
433
  end # module LibSocket
521
434
 
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 version2?
18
- ZMQ::LibZMQ.version2?
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 ||= ZMQ::Poller.new
30
+ @helper_poller = ZMQ::Poller.new
39
31
  end
40
32
 
41
33
  def poller_register_socket(socket)
data/spec/util_spec.rb ADDED
@@ -0,0 +1,28 @@
1
+ require File.join(File.dirname(__FILE__), %w[spec_helper])
2
+
3
+ module ZMQ
4
+ describe Util do
5
+
6
+ if LibZMQ.version4?
7
+ describe "curve_keypair" do
8
+
9
+ it "returns a set of public and private keys" do
10
+ public_key, private_key = ZMQ::Util.curve_keypair
11
+
12
+ public_key.should_not == private_key
13
+ public_key.should_not be_nil
14
+ private_key.should_not be_nil
15
+ end
16
+
17
+ it "raises if zmq does not support CURVE (libsodium not linked)" do
18
+ lambda {
19
+ LibZMQ.should_receive(:zmq_curve_keypair).and_return(-1)
20
+ ZMQ::Util.curve_keypair
21
+ }.should raise_exception(ZMQ::NotSupportedError)
22
+ end
23
+
24
+ end
25
+ end
26
+
27
+ end
28
+ end