ffi-rzmq 0.9.0 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,3 @@
1
+ module ZMQ
2
+ VERSION = "0.9.2"
3
+ end
@@ -16,14 +16,24 @@ module ZMQ
16
16
 
17
17
  shared_examples_for "any socket" do
18
18
 
19
- it "returns -1 and gets EAGAIN when there are no messages to read" do
19
+ it "returns -1 when there are no messages to read" do
20
20
  array = []
21
21
  rc = @receiver.recvmsgs(array, NonBlockingFlag)
22
22
  Util.resultcode_ok?(rc).should be_false
23
- array.size.should == 0
23
+ end
24
+
25
+ it "gets EAGAIN when there are no messages to read" do
26
+ array = []
27
+ rc = @receiver.recvmsgs(array, NonBlockingFlag)
24
28
  ZMQ::Util.errno.should == ZMQ::EAGAIN
25
29
  end
26
30
 
31
+ it "returns the given array unmodified when there are no messages to read" do
32
+ array = []
33
+ rc = @receiver.recvmsgs(array, NonBlockingFlag)
34
+ array.size.should be_zero
35
+ end
36
+
27
37
  end
28
38
 
29
39
  shared_examples_for "sockets without exposed envelopes" do
@@ -222,55 +232,51 @@ module ZMQ
222
232
  end # PUSH
223
233
 
224
234
 
225
- unless LibZMQ.version4?
226
-
227
- context "DEALER" do
228
-
229
- describe "non-blocking #recvmsgs where sender connects & receiver binds" do
230
- include APIHelper
235
+ context "DEALER" do
231
236
 
232
- before(:each) do
233
- @receiver = @ctx.socket ZMQ::ROUTER
234
- port = bind_to_random_tcp_port(@receiver)
235
- @sender = @ctx.socket ZMQ::DEALER
236
- assert_ok(@sender.connect("tcp://127.0.0.1:#{port}"))
237
- sleep 0.1
238
- end
237
+ describe "non-blocking #recvmsgs where sender connects & receiver binds" do
238
+ include APIHelper
239
239
 
240
- after(:each) do
241
- @receiver.close
242
- @sender.close
243
- end
240
+ before(:each) do
241
+ @receiver = @ctx.socket ZMQ::ROUTER
242
+ port = bind_to_random_tcp_port(@receiver)
243
+ @sender = @ctx.socket ZMQ::DEALER
244
+ assert_ok(@sender.connect("tcp://127.0.0.1:#{port}"))
245
+ sleep 0.1
246
+ end
244
247
 
245
- it_behaves_like "any socket"
246
- it_behaves_like "sockets with exposed envelopes"
248
+ after(:each) do
249
+ @receiver.close
250
+ @sender.close
251
+ end
247
252
 
248
- end # describe 'non-blocking recvmsgs'
253
+ it_behaves_like "any socket"
254
+ it_behaves_like "sockets with exposed envelopes"
249
255
 
250
- describe "non-blocking #recvmsgs where sender binds & receiver connects" do
251
- include APIHelper
256
+ end # describe 'non-blocking recvmsgs'
252
257
 
253
- before(:each) do
254
- @receiver = @ctx.socket ZMQ::ROUTER
255
- port = connect_to_random_tcp_port(@receiver)
256
- @sender = @ctx.socket ZMQ::DEALER
257
- assert_ok(@sender.bind("tcp://127.0.0.1:#{port}"))
258
- sleep 0.1
259
- end
258
+ describe "non-blocking #recvmsgs where sender binds & receiver connects" do
259
+ include APIHelper
260
260
 
261
- after(:each) do
262
- @receiver.close
263
- @sender.close
264
- end
261
+ before(:each) do
262
+ @receiver = @ctx.socket ZMQ::ROUTER
263
+ port = connect_to_random_tcp_port(@receiver)
264
+ @sender = @ctx.socket ZMQ::DEALER
265
+ assert_ok(@sender.bind("tcp://127.0.0.1:#{port}"))
266
+ sleep 0.1
267
+ end
265
268
 
266
- it_behaves_like "any socket"
267
- it_behaves_like "sockets with exposed envelopes"
269
+ after(:each) do
270
+ @receiver.close
271
+ @sender.close
272
+ end
268
273
 
269
- end # describe 'non-blocking recvmsgs'
274
+ it_behaves_like "any socket"
275
+ it_behaves_like "sockets with exposed envelopes"
270
276
 
271
- end # DEALER
277
+ end # describe 'non-blocking recvmsgs'
272
278
 
273
- end # unless version4?
279
+ end # DEALER
274
280
 
275
281
 
276
282
  context "XREQ" do
data/spec/poll_spec.rb ADDED
@@ -0,0 +1,84 @@
1
+ $: << "." # added for ruby 1.9.2 compatibilty; it doesn't include the current directory on the load path anymore
2
+
3
+ require File.join(File.dirname(__FILE__), %w[spec_helper])
4
+
5
+ module ZMQ
6
+
7
+
8
+ describe Poller do
9
+
10
+ context "when initializing" do
11
+ include APIHelper
12
+
13
+ it "should allocate a PollItems instance" do
14
+ PollItems.should_receive(:new)
15
+
16
+ Poller.new
17
+ end
18
+
19
+ end # context initializing
20
+
21
+
22
+ context "#register" do
23
+
24
+ let(:poller) { Poller.new }
25
+ let(:socket) { mock('socket') }
26
+
27
+ it "should return false when given a nil socket and no file descriptor" do
28
+ poller.register(nil, ZMQ::POLLIN, 0).should be_false
29
+ end
30
+
31
+ it "should return false when given 0 for +events+ (e.g. no registration)" do
32
+ poller.register(socket, 0).should be_false
33
+ end
34
+
35
+ it "should return the registered event value when given a nil socket and a valid non-zero file descriptor" do
36
+ poller.register(nil, ZMQ::POLLIN, 1).should == ZMQ::POLLIN
37
+ end
38
+
39
+ it "should return the default registered event value when given a valid socket" do
40
+ poller.register(socket).should == (ZMQ::POLLIN | ZMQ::POLLOUT)
41
+ end
42
+
43
+ it "should access the raw 0mq socket" do
44
+ raw_socket = FFI::MemoryPointer.new(4)
45
+ socket.should_receive(:kind_of?).with(ZMQ::Socket).and_return(true)
46
+ socket.should_receive(:socket).and_return(raw_socket)
47
+
48
+ poller.register(socket)
49
+ end
50
+ end
51
+
52
+
53
+ context "#delete" do
54
+ let(:poller) { Poller.new }
55
+ let(:socket) { mock('socket') }
56
+ let(:context) { Context.new }
57
+
58
+ it "should return false for an unregistered socket (i.e. not found)" do
59
+ poller.delete(socket).should be_false
60
+ end
61
+
62
+ it "returns true for a sucessfully deleted socket when only 1 is registered" do
63
+ socket1 = context.socket ZMQ::REP
64
+
65
+ poller.register socket1
66
+ poller.delete(socket1).should be_true
67
+ end
68
+
69
+ it "returns true for a sucessfully deleted socket when more than 1 is registered" do
70
+ socket1 = context.socket ZMQ::REP
71
+ socket2 = context.socket ZMQ::REP
72
+
73
+ poller.register socket1
74
+ poller.register socket2
75
+ poller.delete(socket2).should be_true
76
+ end
77
+
78
+ end
79
+
80
+
81
+ end # describe Poll
82
+
83
+
84
+ end # module ZMQ
@@ -17,6 +17,7 @@ module ZMQ
17
17
  @pull.setsockopt ZMQ::LINGER, 0
18
18
  port = connect_to_random_tcp_port(@pull)
19
19
  @link = "tcp://127.0.0.1:#{port}"
20
+ #@link = "inproc://push_pull_test" # can't connect to inproc *before* bind
20
21
  @push.bind @link
21
22
  end
22
23
 
@@ -30,6 +31,7 @@ module ZMQ
30
31
  @push.send_string string
31
32
  received = ''
32
33
  rc = @pull.recv_string received
34
+ assert_ok(rc)
33
35
  received.should == string
34
36
  end
35
37
 
@@ -63,11 +65,12 @@ module ZMQ
63
65
 
64
66
  if version2?
65
67
 
66
- it "should receive a single message for each message sent on each socket listening, when an equal number pulls to messages" do
68
+ it "should receive a single message for each message sent on each socket listening, when an equal number pulls to messages and a unique socket per thread" do
67
69
  received = []
68
70
  threads = []
69
71
  count = 4
70
72
  @pull.close # close this one since we aren't going to use it below and we don't want it to receive a message
73
+ mutex = Mutex.new
71
74
 
72
75
  count.times do |i|
73
76
  threads << Thread.new do
@@ -78,7 +81,7 @@ module ZMQ
78
81
  buffer = ''
79
82
  rc = pull.recv_string buffer
80
83
  rc.should == 0
81
- received << buffer
84
+ mutex.synchronize { received << buffer }
82
85
  pull.close
83
86
  end
84
87
  sleep 0.01 # give each thread time to spin up
@@ -91,6 +94,36 @@ module ZMQ
91
94
  received.find_all {|r| r == string}.length.should == count
92
95
  end
93
96
 
97
+ it "should receive a single message for each message sent on each socket listening, when an equal number pulls to messages and a single shared socket protected by a mutex" do
98
+ received = []
99
+ threads = []
100
+ count = 4
101
+ @pull.close # close this one since we aren't going to use it below and we don't want it to receive a message
102
+ pull = @context.socket ZMQ::PULL
103
+ rc = pull.setsockopt ZMQ::LINGER, 0
104
+ rc = pull.connect @link
105
+ rc.should == 0
106
+ mutex = Mutex.new
107
+
108
+ count.times do |i|
109
+ threads << Thread.new do
110
+ buffer = ''
111
+ rc = 0
112
+ mutex.synchronize { rc = pull.recv_string buffer }
113
+ rc.should == 0
114
+ mutex.synchronize { received << buffer }
115
+ end
116
+ sleep 0.01 # give each thread time to spin up
117
+ end
118
+
119
+ count.times { @push.send_string(string) }
120
+
121
+ threads.each {|t| t.join}
122
+ pull.close
123
+
124
+ received.find_all {|r| r == string}.length.should == count
125
+ end
126
+
94
127
  else # version3 or 4
95
128
 
96
129
  it "should receive a single message for each message sent on each socket listening, when an equal number pulls to messages" do
data/spec/socket_spec.rb CHANGED
@@ -10,8 +10,6 @@ module ZMQ
10
10
  [ZMQ::REQ, ZMQ::REP, ZMQ::DEALER, ZMQ::ROUTER, ZMQ::PUB, ZMQ::SUB, ZMQ::PUSH, ZMQ::PULL, ZMQ::PAIR]
11
11
  elsif LibZMQ.version3?
12
12
  [ZMQ::REQ, ZMQ::REP, ZMQ::DEALER, ZMQ::ROUTER, ZMQ::PUB, ZMQ::SUB, ZMQ::PUSH, ZMQ::PULL, ZMQ::PAIR, ZMQ::XPUB, ZMQ::XSUB]
13
- elsif LibZMQ.version4?
14
- [ZMQ::REQ, ZMQ::REP, ZMQ::ROUTER, ZMQ::PUB, ZMQ::SUB, ZMQ::PUSH, ZMQ::PULL, ZMQ::PAIR, ZMQ::XPUB, ZMQ::XSUB]
15
13
  end
16
14
 
17
15
  context "when initializing" do
data/spec/spec_helper.rb CHANGED
@@ -10,19 +10,15 @@ Thread.abort_on_exception = true
10
10
  # define some version guards so we can turn on/off specs based upon
11
11
  # the version of the 0mq library that is loaded
12
12
  def version2?
13
- LibZMQ.version2?
13
+ ZMQ::LibZMQ.version2?
14
14
  end
15
15
 
16
16
  def version3?
17
- LibZMQ.version3?
18
- end
19
-
20
- def version4?
21
- LibZMQ.version4?
17
+ ZMQ::LibZMQ.version3?
22
18
  end
23
19
 
24
20
 
25
- NonBlockingFlag = (LibZMQ.version2? ? ZMQ::NOBLOCK : ZMQ::DONTWAIT) unless defined?(NonBlockingFlag)
21
+ NonBlockingFlag = (ZMQ::LibZMQ.version2? ? ZMQ::NOBLOCK : ZMQ::DONTWAIT) unless defined?(NonBlockingFlag)
26
22
 
27
23
 
28
24
  module APIHelper
metadata CHANGED
@@ -1,134 +1,156 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ffi-rzmq
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 9
8
- - 0
9
- version: 0.9.0
4
+ prerelease:
5
+ version: 0.9.2
10
6
  platform: ruby
11
7
  authors:
12
- - Chuck Remes
8
+ - Chuck Remes
13
9
  autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
12
 
17
- date: 2011-09-14 00:00:00 -05:00
13
+ date: 2011-11-30 00:00:00 -06:00
18
14
  default_executable:
19
15
  dependencies:
20
- - !ruby/object:Gem::Dependency
21
- name: bones
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
24
- none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- segments:
29
- - 3
30
- - 5
31
- - 4
32
- version: 3.5.4
33
- type: :development
34
- version_requirements: *id001
16
+ - !ruby/object:Gem::Dependency
17
+ name: ffi
18
+ prerelease: false
19
+ requirement: &id001 !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: 1.0.9
25
+ type: :runtime
26
+ version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ prerelease: false
30
+ requirement: &id002 !ruby/object:Gem::Requirement
31
+ none: false
32
+ requirements:
33
+ - - ~>
34
+ - !ruby/object:Gem::Version
35
+ version: "2.6"
36
+ type: :development
37
+ version_requirements: *id002
38
+ - !ruby/object:Gem::Dependency
39
+ name: rake
40
+ prerelease: false
41
+ requirement: &id003 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: "0"
47
+ type: :development
48
+ version_requirements: *id003
35
49
  description: |-
36
50
  This gem wraps the ZeroMQ networking library using the ruby FFI (foreign
37
51
  function interface). It's a pure ruby wrapper so this gem can be loaded
38
52
  and run by any ruby runtime that supports FFI. That's all of them:
39
53
  MRI 1.9.x, Rubinius and JRuby.
40
- email: cremes@mac.com
54
+ email:
55
+ - cremes@mac.com
41
56
  executables: []
42
57
 
43
58
  extensions: []
44
59
 
45
- extra_rdoc_files:
46
- - AUTHORS.txt
47
- - History.txt
48
- - README.rdoc
49
- - examples/README.rdoc
50
- - version.txt
60
+ extra_rdoc_files: []
61
+
51
62
  files:
52
- - .bnsignore
53
- - History.txt
54
- - README.rdoc
55
- - Rakefile
56
- - examples/README.rdoc
57
- - examples/v2api/local_lat.rb
58
- - examples/v2api/local_lat_poll.rb
59
- - examples/v2api/local_throughput.rb
60
- - examples/v2api/publish_subscribe.rb
61
- - examples/v2api/remote_lat.rb
62
- - examples/v2api/remote_throughput.rb
63
- - examples/v2api/reqrep_poll.rb
64
- - examples/v2api/request_response.rb
65
- - examples/v2api/throughput_measurement.rb
66
- - examples/v3api/local_lat.rb
67
- - examples/v3api/local_lat_poll.rb
68
- - examples/v3api/local_throughput.rb
69
- - examples/v3api/publish_subscribe.rb
70
- - examples/v3api/remote_lat.rb
71
- - examples/v3api/remote_throughput.rb
72
- - examples/v3api/reqrep_poll.rb
73
- - examples/v3api/request_response.rb
74
- - examples/v3api/throughput_measurement.rb
75
- - ext/README
76
- - ffi-rzmq.gemspec
77
- - lib/ffi-rzmq.rb
78
- - lib/ffi-rzmq/constants.rb
79
- - lib/ffi-rzmq/context.rb
80
- - lib/ffi-rzmq/device.rb
81
- - lib/ffi-rzmq/exceptions.rb
82
- - lib/ffi-rzmq/libc.rb
83
- - lib/ffi-rzmq/libzmq.rb
84
- - lib/ffi-rzmq/message.rb
85
- - lib/ffi-rzmq/poll.rb
86
- - lib/ffi-rzmq/poll_items.rb
87
- - lib/ffi-rzmq/socket.rb
88
- - lib/ffi-rzmq/util.rb
89
- - spec/context_spec.rb
90
- - spec/device_spec.rb
91
- - spec/message_spec.rb
92
- - spec/multipart_spec.rb
93
- - spec/nonblocking_recv_spec.rb
94
- - spec/pushpull_spec.rb
95
- - spec/reqrep_spec.rb
96
- - spec/socket_spec.rb
97
- - spec/spec_helper.rb
98
- - version.txt
99
- - AUTHORS.txt
63
+ - .bnsignore
64
+ - .gitignore
65
+ - AUTHORS.txt
66
+ - Gemfile
67
+ - History.txt
68
+ - README.rdoc
69
+ - Rakefile
70
+ - examples/README.rdoc
71
+ - examples/v2api/latency_measurement.rb
72
+ - examples/v2api/local_lat.rb
73
+ - examples/v2api/local_lat_poll.rb
74
+ - examples/v2api/local_throughput.rb
75
+ - examples/v2api/publish_subscribe.rb
76
+ - examples/v2api/remote_lat.rb
77
+ - examples/v2api/remote_throughput.rb
78
+ - examples/v2api/reqrep_poll.rb
79
+ - examples/v2api/request_response.rb
80
+ - examples/v2api/throughput_measurement.rb
81
+ - examples/v2api/xreqxrep_poll.rb
82
+ - examples/v3api/latency_measurement.rb
83
+ - examples/v3api/local_lat.rb
84
+ - examples/v3api/local_lat_poll.rb
85
+ - examples/v3api/local_throughput.rb
86
+ - examples/v3api/publish_subscribe.rb
87
+ - examples/v3api/remote_lat.rb
88
+ - examples/v3api/remote_throughput.rb
89
+ - examples/v3api/reqrep_poll.rb
90
+ - examples/v3api/request_response.rb
91
+ - examples/v3api/throughput_measurement.rb
92
+ - examples/v3api/xreqxrep_poll.rb
93
+ - ext/README
94
+ - ffi-rzmq.gemspec
95
+ - lib/ffi-rzmq.rb
96
+ - lib/ffi-rzmq/constants.rb
97
+ - lib/ffi-rzmq/context.rb
98
+ - lib/ffi-rzmq/device.rb
99
+ - lib/ffi-rzmq/exceptions.rb
100
+ - lib/ffi-rzmq/libc.rb
101
+ - lib/ffi-rzmq/libzmq.rb
102
+ - lib/ffi-rzmq/message.rb
103
+ - lib/ffi-rzmq/poll.rb
104
+ - lib/ffi-rzmq/poll_items.rb
105
+ - lib/ffi-rzmq/socket.rb
106
+ - lib/ffi-rzmq/util.rb
107
+ - lib/ffi-rzmq/version.rb
108
+ - spec/context_spec.rb
109
+ - spec/device_spec.rb
110
+ - spec/message_spec.rb
111
+ - spec/multipart_spec.rb
112
+ - spec/nonblocking_recv_spec.rb
113
+ - spec/poll_spec.rb
114
+ - spec/pushpull_spec.rb
115
+ - spec/reqrep_spec.rb
116
+ - spec/socket_spec.rb
117
+ - spec/spec_helper.rb
100
118
  has_rdoc: true
101
119
  homepage: http://github.com/chuckremes/ffi-rzmq
102
120
  licenses: []
103
121
 
104
122
  post_install_message:
105
- rdoc_options:
106
- - --main
107
- - README.rdoc
123
+ rdoc_options: []
124
+
108
125
  require_paths:
109
- - lib
126
+ - lib
110
127
  required_ruby_version: !ruby/object:Gem::Requirement
111
128
  none: false
112
129
  requirements:
113
- - - ">="
114
- - !ruby/object:Gem::Version
115
- segments:
116
- - 0
117
- version: "0"
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: "0"
118
133
  required_rubygems_version: !ruby/object:Gem::Requirement
119
134
  none: false
120
135
  requirements:
121
- - - ">="
122
- - !ruby/object:Gem::Version
123
- segments:
124
- - 0
125
- version: "0"
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: "0"
126
139
  requirements: []
127
140
 
128
141
  rubyforge_project: ffi-rzmq
129
- rubygems_version: 1.3.7
142
+ rubygems_version: 1.5.1
130
143
  signing_key:
131
144
  specification_version: 3
132
145
  summary: This gem wraps the ZeroMQ (0mq) networking library using Ruby FFI (foreign function interface).
133
- test_files: []
134
-
146
+ test_files:
147
+ - spec/context_spec.rb
148
+ - spec/device_spec.rb
149
+ - spec/message_spec.rb
150
+ - spec/multipart_spec.rb
151
+ - spec/nonblocking_recv_spec.rb
152
+ - spec/poll_spec.rb
153
+ - spec/pushpull_spec.rb
154
+ - spec/reqrep_spec.rb
155
+ - spec/socket_spec.rb
156
+ - spec/spec_helper.rb