ffi-rzmq 1.0.3 → 2.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +7 -0
  2. data/.travis.yml +5 -6
  3. data/AUTHORS.txt +7 -1
  4. data/History.txt +79 -0
  5. data/README.rdoc +67 -29
  6. data/Rakefile +15 -0
  7. data/examples/README.rdoc +1 -3
  8. data/examples/{v3api/latency_measurement.rb → latency_measurement.rb} +1 -2
  9. data/examples/{v3api/local_lat.rb → local_lat.rb} +1 -1
  10. data/examples/{v3api/local_lat_poll.rb → local_lat_poll.rb} +4 -4
  11. data/examples/{v3api/local_throughput.rb → local_throughput.rb} +1 -1
  12. data/examples/{v3api/pub.rb → pub.rb} +1 -1
  13. data/examples/{v2api/publish_subscribe.rb → publish_subscribe.rb} +2 -2
  14. data/examples/{v2api/remote_lat.rb → remote_lat.rb} +1 -1
  15. data/examples/{v3api/remote_throughput.rb → remote_throughput.rb} +4 -3
  16. data/examples/repreq_over_curve.rb +60 -0
  17. data/examples/{v2api/reqrep_poll.rb → reqrep_poll.rb} +3 -4
  18. data/examples/{v2api/request_response.rb → request_response.rb} +1 -2
  19. data/examples/{v3api/sub.rb → sub.rb} +1 -2
  20. data/examples/{v3api/throughput_measurement.rb → throughput_measurement.rb} +1 -1
  21. data/examples/{v3api/xreqxrep_poll.rb → xreqxrep_poll.rb} +6 -7
  22. data/ffi-rzmq.gemspec +4 -4
  23. data/lib/ffi-rzmq/context.rb +26 -54
  24. data/lib/ffi-rzmq/device.rb +8 -4
  25. data/lib/ffi-rzmq/exceptions.rb +3 -0
  26. data/lib/ffi-rzmq/message.rb +24 -30
  27. data/lib/ffi-rzmq/poll.rb +5 -16
  28. data/lib/ffi-rzmq/poll_item.rb +0 -1
  29. data/lib/ffi-rzmq/socket.rb +132 -282
  30. data/lib/ffi-rzmq/util.rb +28 -36
  31. data/lib/ffi-rzmq/version.rb +1 -1
  32. data/lib/ffi-rzmq.rb +3 -3
  33. data/lib/io_extensions.rb +1 -1
  34. data/spec/context_spec.rb +18 -23
  35. data/spec/device_spec.rb +13 -12
  36. data/spec/message_spec.rb +13 -13
  37. data/spec/multipart_spec.rb +11 -11
  38. data/spec/nonblocking_recv_spec.rb +22 -22
  39. data/spec/poll_spec.rb +49 -49
  40. data/spec/pushpull_spec.rb +12 -11
  41. data/spec/reqrep_spec.rb +11 -11
  42. data/spec/socket_spec.rb +110 -197
  43. data/spec/spec_helper.rb +3 -11
  44. data/spec/support/generate_keys_and_certs.rb +41 -0
  45. data/spec/support/test.crt +26 -13
  46. data/spec/support/test.key +49 -13
  47. data/spec/util_spec.rb +29 -0
  48. data/travis_build_script.sh +27 -0
  49. metadata +83 -104
  50. data/examples/v2api/latency_measurement.rb +0 -139
  51. data/examples/v2api/local_lat.rb +0 -58
  52. data/examples/v2api/local_lat_poll.rb +0 -66
  53. data/examples/v2api/local_throughput.rb +0 -58
  54. data/examples/v2api/pub.rb +0 -46
  55. data/examples/v2api/remote_throughput.rb +0 -39
  56. data/examples/v2api/sub.rb +0 -74
  57. data/examples/v2api/throughput_measurement.rb +0 -138
  58. data/examples/v2api/xreqxrep_poll.rb +0 -93
  59. data/examples/v3api/publish_subscribe.rb +0 -82
  60. data/examples/v3api/remote_lat.rb +0 -71
  61. data/examples/v3api/reqrep_poll.rb +0 -62
  62. data/examples/v3api/request_response.rb +0 -40
  63. data/lib/ffi-rzmq/constants.rb +0 -187
  64. data/lib/ffi-rzmq/libc.rb +0 -19
  65. data/lib/ffi-rzmq/libzmq.rb +0 -283
data/spec/poll_spec.rb CHANGED
@@ -8,7 +8,7 @@ module ZMQ
8
8
  include APIHelper
9
9
 
10
10
  it "should allocate a PollItems instance" do
11
- PollItems.should_receive(:new)
11
+ expect(PollItems).to receive(:new)
12
12
  Poller.new
13
13
  end
14
14
 
@@ -23,30 +23,30 @@ module ZMQ
23
23
  let(:fd) { 1 }
24
24
 
25
25
  it "returns false when given a nil pollable" do
26
- poller.register(nil, ZMQ::POLLIN).should be_false
26
+ expect(poller.register(nil, ZMQ::POLLIN)).to be_falsy
27
27
  end
28
28
 
29
29
  it "returns false when given 0 for +events+ (e.g. no registration)" do
30
- poller.register(pollable, 0).should be_false
30
+ expect(poller.register(pollable, 0)).to be_falsy
31
31
  end
32
32
 
33
33
  it "returns the default registered event value when given a valid pollable" do
34
- poller.register(pollable).should == (ZMQ::POLLIN | ZMQ::POLLOUT)
34
+ expect(poller.register(pollable)).to eq(ZMQ::POLLIN | ZMQ::POLLOUT)
35
35
  end
36
36
 
37
37
  it "returns the registered event value when given a pollable responding to socket (ZMQ::Socket)" do
38
- pollable.should_receive(:socket).and_return(socket)
39
- poller.register(pollable, ZMQ::POLLIN).should == ZMQ::POLLIN
38
+ expect(pollable).to receive(:socket).and_return(socket)
39
+ expect(poller.register(pollable, ZMQ::POLLIN)).to eq ZMQ::POLLIN
40
40
  end
41
41
 
42
42
  it "returns the registered event value when given a pollable responding to file descriptor (IO, BasicSocket)" do
43
- pollable.should_receive(:posix_fileno).and_return(fd)
44
- poller.register(pollable, ZMQ::POLLIN).should == ZMQ::POLLIN
43
+ expect(pollable).to receive(:posix_fileno).and_return(fd)
44
+ expect(poller.register(pollable, ZMQ::POLLIN)).to eq(ZMQ::POLLIN)
45
45
  end
46
46
 
47
47
  it "returns the registered event value when given a pollable responding to io (SSLSocket)" do
48
- pollable.should_receive(:io).and_return(io)
49
- poller.register(pollable, ZMQ::POLLIN).should == ZMQ::POLLIN
48
+ expect(pollable).to receive(:io).and_return(io)
49
+ expect(poller.register(pollable, ZMQ::POLLIN)).to eq(ZMQ::POLLIN)
50
50
  end
51
51
 
52
52
  end
@@ -60,49 +60,49 @@ module ZMQ
60
60
  let(:fd) { 1 }
61
61
 
62
62
  it "returns true when deregistered pollable from event" do
63
- pollable.should_receive(:socket).at_least(:once).and_return(socket)
63
+ expect(pollable).to receive(:socket).at_least(:once).and_return(socket)
64
64
  poller.register(pollable)
65
- poller.deregister(pollable, ZMQ::POLLIN).should be_true
65
+ expect(poller.deregister(pollable, ZMQ::POLLIN)).to eq(true)
66
66
  end
67
67
 
68
68
  it "returns false when pollable not registered" do
69
- poller.deregister(pollable, ZMQ::POLLIN).should be_false
69
+ expect(poller.deregister(pollable, ZMQ::POLLIN)).to eq(false)
70
70
  end
71
71
 
72
72
  it "returns false when pollable not registered for deregistered event" do
73
- pollable.should_receive(:socket).at_least(:once).and_return(socket)
73
+ expect(pollable).to receive(:socket).at_least(:once).and_return(socket)
74
74
  poller.register(pollable, ZMQ::POLLOUT)
75
- poller.deregister(pollable, ZMQ::POLLIN).should be_false
75
+ expect(poller.deregister(pollable, ZMQ::POLLIN)).to eq(false)
76
76
  end
77
77
 
78
78
  it "deletes pollable when no events left" do
79
79
  poller.register(pollable, ZMQ::POLLIN)
80
- poller.deregister(pollable, ZMQ::POLLIN).should be_true
81
- poller.size.should == 0
80
+ expect(poller.deregister(pollable, ZMQ::POLLIN)).to eq(true)
81
+ expect(poller.size).to eq 0
82
82
  end
83
83
 
84
84
  it "deletes closed pollable responding to socket (ZMQ::Socket)" do
85
- pollable.should_receive(:socket).and_return(socket)
85
+ expect(pollable).to receive(:socket).and_return(socket)
86
86
  poller.register(pollable)
87
- pollable.should_receive(:socket).and_return(nil)
88
- poller.deregister(pollable, ZMQ::POLLIN).should be_true
89
- poller.size.should == 0
87
+ expect(pollable).to receive(:socket).and_return(nil)
88
+ expect(poller.deregister(pollable, ZMQ::POLLIN)).to eq(true)
89
+ expect(poller.size).to eq 0
90
90
  end
91
91
 
92
92
  it "deletes closed pollable responding to fileno (IO, BasicSocket)" do
93
- pollable.should_receive(:posix_fileno).and_return(fd)
93
+ expect(pollable).to receive(:posix_fileno).and_return(fd)
94
94
  poller.register(pollable)
95
- pollable.should_receive(:closed?).and_return(true)
96
- poller.deregister(pollable, ZMQ::POLLIN).should be_true
97
- poller.size.should == 0
95
+ expect(pollable).to receive(:closed?).and_return(true)
96
+ expect(poller.deregister(pollable, ZMQ::POLLIN)).to eq(true)
97
+ expect(poller.size).to eq 0
98
98
  end
99
99
 
100
100
  it "deletes closed pollable responding to io (SSLSocket)" do
101
- pollable.should_receive(:io).at_least(:once).and_return(io)
101
+ expect(pollable).to receive(:io).at_least(:once).and_return(io)
102
102
  poller.register(pollable)
103
- io.should_receive(:closed?).and_return(true)
104
- poller.deregister(pollable, ZMQ::POLLIN).should be_true
105
- poller.size.should == 0
103
+ expect(io).to receive(:closed?).and_return(true)
104
+ expect(poller.deregister(pollable, ZMQ::POLLIN)).to eq(true)
105
+ expect(poller.size).to eq 0
106
106
  end
107
107
 
108
108
  end
@@ -123,7 +123,7 @@ module ZMQ
123
123
  end
124
124
 
125
125
  it "should return false for an unregistered socket (i.e. not found)" do
126
- @poller.delete(@socket).should be_false
126
+ expect(@poller.delete(@socket)).to eq(false)
127
127
  end
128
128
 
129
129
  it "returns true for a sucessfully deleted socket when only 1 is registered" do
@@ -131,7 +131,7 @@ module ZMQ
131
131
  socket1.setsockopt(LINGER, 0)
132
132
 
133
133
  @poller.register socket1
134
- @poller.delete(socket1).should be_true
134
+ expect(@poller.delete(socket1)).to eq(true)
135
135
  socket1.close
136
136
  end
137
137
 
@@ -143,7 +143,7 @@ module ZMQ
143
143
 
144
144
  @poller.register socket1
145
145
  @poller.register socket2
146
- @poller.delete(socket2).should be_true
146
+ expect(@poller.delete(socket2)).to eq(true)
147
147
  socket1.close
148
148
  socket2.close
149
149
  end
@@ -154,7 +154,7 @@ module ZMQ
154
154
 
155
155
  @poller.register socket1
156
156
  socket1.close
157
- @poller.delete(socket1).should be_true
157
+ expect(@poller.delete(socket1)).to eq(true)
158
158
  end
159
159
 
160
160
  end
@@ -177,12 +177,12 @@ module ZMQ
177
177
  after(:each) { @sockets.each(&:close) }
178
178
 
179
179
  it "returns 0 when there are no sockets to poll" do
180
- @poller.poll(100).should be_zero
180
+ expect(@poller.poll(100)).to eq 0
181
181
  end
182
182
 
183
183
  it "returns 0 when there is a single socket to poll and no events" do
184
184
  @poller.register(@sockets.first, 0)
185
- @poller.poll(100).should be_zero
185
+ expect(@poller.poll(100)).to eq 0
186
186
  end
187
187
 
188
188
  it "returns 1 when there is a read event on a socket" do
@@ -190,7 +190,7 @@ module ZMQ
190
190
  @poller.register_readable(last)
191
191
 
192
192
  first.send_string('test')
193
- @poller.poll(1000).should == 1
193
+ expect(@poller.poll(1000)).to eq 1
194
194
  end
195
195
 
196
196
  it "returns 1 when there is a read event on one socket and the second socket has been removed from polling" do
@@ -200,7 +200,7 @@ module ZMQ
200
200
 
201
201
  first.send_string('test')
202
202
  @poller.deregister_writable(first)
203
- @poller.poll(1000).should == 1
203
+ expect(@poller.poll(1000)).to eq 1
204
204
  end
205
205
 
206
206
  it "works with BasiSocket" do
@@ -214,12 +214,12 @@ module ZMQ
214
214
 
215
215
  client.send("message", 0)
216
216
 
217
- @poller.poll.should == 2
218
- @poller.readables.should == [s]
219
- @poller.writables.should == [client]
217
+ expect(@poller.poll).to eq 2
218
+ expect(@poller.readables).to eq [s]
219
+ expect(@poller.writables).to eq [client]
220
220
 
221
221
  msg = s.read_nonblock(7)
222
- msg.should == "message"
222
+ expect(msg).to eq "message"
223
223
  end
224
224
 
225
225
  it "works with IO objects" do
@@ -229,12 +229,12 @@ module ZMQ
229
229
 
230
230
  w.write("message")
231
231
 
232
- @poller.poll.should == 2
233
- @poller.readables.should == [r]
234
- @poller.writables.should == [w]
232
+ expect(@poller.poll).to eq 2
233
+ expect(@poller.readables).to eq [r]
234
+ expect(@poller.writables).to eq [w]
235
235
 
236
236
  msg = r.read(7)
237
- msg.should == "message"
237
+ expect(msg).to eq "message"
238
238
  end
239
239
 
240
240
  it "works with SSLSocket" do
@@ -262,12 +262,12 @@ module ZMQ
262
262
 
263
263
  client.write("message")
264
264
 
265
- @poller.poll.should == 2
266
- @poller.readables.should == [s]
267
- @poller.writables.should == [client]
265
+ expect(@poller.poll).to eq 2
266
+ expect(@poller.readables).to eq [s]
267
+ expect(@poller.writables).to eq [client]
268
268
 
269
269
  msg = s.read(7)
270
- msg.should == "message"
270
+ expect(msg).to eq "message"
271
271
  end
272
272
  end
273
273
 
@@ -35,7 +35,7 @@ module ZMQ
35
35
  received = ''
36
36
  rc = @pull.recv_string received
37
37
  assert_ok(rc)
38
- received.should == string
38
+ expect(received).to eq(string)
39
39
  end
40
40
 
41
41
  it "should receive an exact string copy of the message sent when receiving in non-blocking mode and using Message objects directly" do
@@ -44,12 +44,12 @@ 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
+ expect(rc).to eq(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
52
- received_message.copy_out_string.should == string
50
+ rc = @pull.recvmsg received_message, ZMQ::DONTWAIT
51
+ expect(rc).to eq(string.size)
52
+ expect(received_message.copy_out_string).to eq(string)
53
53
  end
54
54
 
55
55
 
@@ -71,20 +71,21 @@ 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
+ expect(rc).to eq(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}
86
87
 
87
- received.find_all {|r| r == string}.length.should == count
88
+ expect(received.find_all {|r| r == string}.length).to eq(count)
88
89
  end
89
90
 
90
91
  it "should receive a single message for each message sent when using a single shared socket protected by a mutex" do
@@ -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
+ expect(rc).to eq(buffer.size)
102
103
  mutex.synchronize { received << buffer }
103
104
  end
104
105
  end
@@ -107,7 +108,7 @@ module ZMQ
107
108
 
108
109
  threads.each {|t| t.join}
109
110
 
110
- received.find_all {|r| r == string}.length.should == count
111
+ expect(received.find_all {|r| r == string}.length).to eq(count)
111
112
  end
112
113
 
113
114
  end # @context ping-pong
data/spec/reqrep_spec.rb CHANGED
@@ -40,25 +40,25 @@ module ZMQ
40
40
 
41
41
  it "should receive an exact string copy of the string message sent" do
42
42
  rc, received_message = send_ping(string)
43
- received_message.should == string
43
+ expect(received_message).to eq(string)
44
44
  end
45
45
 
46
46
  it "should generate a EFSM error when sending via the REQ socket twice in a row without an intervening receive operation" do
47
47
  send_ping(string)
48
48
  rc = @ping.send_string(string)
49
- rc.should == -1
50
- Util.errno.should == ZMQ::EFSM
49
+ expect(rc).to eq(-1)
50
+ expect(Util.errno).to eq(ZMQ::EFSM)
51
51
  end
52
52
 
53
53
  it "should receive an exact copy of the sent message using Message objects directly" do
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
+ expect(rc).to eq(string.size)
58
58
  rc = @pong.recvmsg received_message
59
- LibZMQ.version2? ? rc.should == 0 : rc.should == string.size
59
+ expect(rc).to eq(string.size)
60
60
 
61
- received_message.copy_out_string.should == string
61
+ expect(received_message.copy_out_string).to eq(string)
62
62
  end
63
63
 
64
64
  it "should receive an exact copy of the sent message using Message objects directly in non-blocking mode" do
@@ -66,14 +66,14 @@ 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
+ expect(rc).to eq(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
+ expect(rc).to eq(string.size)
75
75
 
76
- received_message.copy_out_string.should == string
76
+ expect(received_message.copy_out_string).to eq(string)
77
77
  end
78
78
 
79
79
  end # context ping-pong