ffi-rzmq 1.0.3 → 2.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +7 -0
  2. data/.travis.yml +1 -1
  3. data/AUTHORS.txt +5 -1
  4. data/History.txt +45 -0
  5. data/README.rdoc +58 -28
  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.rb +2 -3
  24. data/lib/ffi-rzmq/context.rb +25 -53
  25. data/lib/ffi-rzmq/device.rb +8 -4
  26. data/lib/ffi-rzmq/exceptions.rb +3 -0
  27. data/lib/ffi-rzmq/message.rb +24 -30
  28. data/lib/ffi-rzmq/poll.rb +5 -16
  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/spec/context_spec.rb +18 -23
  33. data/spec/device_spec.rb +13 -12
  34. data/spec/message_spec.rb +13 -13
  35. data/spec/multipart_spec.rb +11 -11
  36. data/spec/nonblocking_recv_spec.rb +22 -22
  37. data/spec/poll_spec.rb +49 -49
  38. data/spec/pushpull_spec.rb +12 -11
  39. data/spec/reqrep_spec.rb +11 -11
  40. data/spec/socket_spec.rb +109 -196
  41. data/spec/spec_helper.rb +3 -11
  42. data/spec/util_spec.rb +29 -0
  43. metadata +80 -104
  44. data/examples/v2api/latency_measurement.rb +0 -139
  45. data/examples/v2api/local_lat.rb +0 -58
  46. data/examples/v2api/local_lat_poll.rb +0 -66
  47. data/examples/v2api/local_throughput.rb +0 -58
  48. data/examples/v2api/pub.rb +0 -46
  49. data/examples/v2api/remote_throughput.rb +0 -39
  50. data/examples/v2api/sub.rb +0 -74
  51. data/examples/v2api/throughput_measurement.rb +0 -138
  52. data/examples/v2api/xreqxrep_poll.rb +0 -93
  53. data/examples/v3api/publish_subscribe.rb +0 -82
  54. data/examples/v3api/remote_lat.rb +0 -71
  55. data/examples/v3api/reqrep_poll.rb +0 -62
  56. data/examples/v3api/request_response.rb +0 -40
  57. data/lib/ffi-rzmq/constants.rb +0 -187
  58. data/lib/ffi-rzmq/libc.rb +0 -19
  59. data/lib/ffi-rzmq/libzmq.rb +0 -283
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,29 @@
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 (libsodium linked)" do
10
+ expect(ZMQ::Util).to receive(:curve_keypair).and_return([0, 1])
11
+ public_key, private_key = ZMQ::Util.curve_keypair
12
+
13
+ expect(public_key).not_to eq private_key
14
+ expect(public_key).not_to be_nil
15
+ expect(private_key).not_to be_nil
16
+ end
17
+
18
+ it "raises if zmq does not support CURVE (libsodium not linked)" do
19
+ expect do
20
+ allow(LibZMQ).to receive(:zmq_curve_keypair).and_return(-1)
21
+ ZMQ::Util.curve_keypair
22
+ end.to raise_exception(ZMQ::NotSupportedError)
23
+ end
24
+
25
+ end
26
+ end
27
+
28
+ end
29
+ end
metadata CHANGED
@@ -1,117 +1,96 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: ffi-rzmq
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 1
7
- - 0
8
- - 3
9
- version: 1.0.3
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.4
10
5
  platform: ruby
11
- authors:
6
+ authors:
12
7
  - Chuck Remes
13
8
  autorequire:
14
9
  bindir: bin
15
10
  cert_chain: []
16
-
17
- date: 2013-10-03 00:00:00 -05:00
18
- default_executable:
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
21
- name: ffi
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
24
- requirements:
11
+ date: 2015-01-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ffi-rzmq-core
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
25
17
  - - ">="
26
- - !ruby/object:Gem::Version
27
- segments:
28
- - 0
29
- version: "0"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.0.1
30
20
  type: :runtime
31
- version_requirements: *id001
32
- - !ruby/object:Gem::Dependency
33
- name: rspec
34
21
  prerelease: false
35
- requirement: &id002 !ruby/object:Gem::Requirement
36
- requirements:
37
- - - ~>
38
- - !ruby/object:Gem::Version
39
- segments:
40
- - 2
41
- - 6
42
- version: "2.6"
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 1.0.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.14'
43
34
  type: :development
44
- version_requirements: *id002
45
- - !ruby/object:Gem::Dependency
46
- name: rake
47
35
  prerelease: false
48
- requirement: &id003 !ruby/object:Gem::Requirement
49
- requirements:
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.14'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
50
45
  - - ">="
51
- - !ruby/object:Gem::Version
52
- segments:
53
- - 0
54
- version: "0"
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
55
48
  type: :development
56
- version_requirements: *id003
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
57
55
  description: |-
58
56
  This gem wraps the ZeroMQ networking library using the ruby FFI (foreign
59
57
  function interface). It's a pure ruby wrapper so this gem can be loaded
60
- and run by any ruby runtime that supports FFI. That's all of the major ones -
61
- MRI, Rubinius and JRuby.
62
- email:
58
+ and run by any ruby runtime that supports FFI. That's all of the major ones - MRI, Rubinius and JRuby.
59
+ email:
63
60
  - git@chuckremes.com
64
61
  executables: []
65
-
66
62
  extensions: []
67
-
68
63
  extra_rdoc_files: []
69
-
70
- files:
71
- - .bnsignore
72
- - .gitignore
73
- - .travis.yml
64
+ files:
65
+ - ".bnsignore"
66
+ - ".gitignore"
67
+ - ".travis.yml"
74
68
  - AUTHORS.txt
75
69
  - Gemfile
76
70
  - History.txt
77
71
  - README.rdoc
78
72
  - Rakefile
79
73
  - examples/README.rdoc
80
- - examples/v2api/latency_measurement.rb
81
- - examples/v2api/local_lat.rb
82
- - examples/v2api/local_lat_poll.rb
83
- - examples/v2api/local_throughput.rb
84
- - examples/v2api/pub.rb
85
- - examples/v2api/publish_subscribe.rb
86
- - examples/v2api/remote_lat.rb
87
- - examples/v2api/remote_throughput.rb
88
- - examples/v2api/reqrep_poll.rb
89
- - examples/v2api/request_response.rb
90
- - examples/v2api/sub.rb
91
- - examples/v2api/throughput_measurement.rb
92
- - examples/v2api/xreqxrep_poll.rb
93
- - examples/v3api/latency_measurement.rb
94
- - examples/v3api/local_lat.rb
95
- - examples/v3api/local_lat_poll.rb
96
- - examples/v3api/local_throughput.rb
97
- - examples/v3api/pub.rb
98
- - examples/v3api/publish_subscribe.rb
99
- - examples/v3api/remote_lat.rb
100
- - examples/v3api/remote_throughput.rb
101
- - examples/v3api/reqrep_poll.rb
102
- - examples/v3api/request_response.rb
103
- - examples/v3api/sub.rb
104
- - examples/v3api/throughput_measurement.rb
105
- - examples/v3api/xreqxrep_poll.rb
74
+ - examples/latency_measurement.rb
75
+ - examples/local_lat.rb
76
+ - examples/local_lat_poll.rb
77
+ - examples/local_throughput.rb
78
+ - examples/pub.rb
79
+ - examples/publish_subscribe.rb
80
+ - examples/remote_lat.rb
81
+ - examples/remote_throughput.rb
82
+ - examples/repreq_over_curve.rb
83
+ - examples/reqrep_poll.rb
84
+ - examples/request_response.rb
85
+ - examples/sub.rb
86
+ - examples/throughput_measurement.rb
87
+ - examples/xreqxrep_poll.rb
106
88
  - ext/README
107
89
  - ffi-rzmq.gemspec
108
90
  - lib/ffi-rzmq.rb
109
- - lib/ffi-rzmq/constants.rb
110
91
  - lib/ffi-rzmq/context.rb
111
92
  - lib/ffi-rzmq/device.rb
112
93
  - lib/ffi-rzmq/exceptions.rb
113
- - lib/ffi-rzmq/libc.rb
114
- - lib/ffi-rzmq/libzmq.rb
115
94
  - lib/ffi-rzmq/message.rb
116
95
  - lib/ffi-rzmq/poll.rb
117
96
  - lib/ffi-rzmq/poll_item.rb
@@ -132,37 +111,33 @@ files:
132
111
  - spec/spec_helper.rb
133
112
  - spec/support/test.crt
134
113
  - spec/support/test.key
135
- has_rdoc: true
114
+ - spec/util_spec.rb
136
115
  homepage: http://github.com/chuckremes/ffi-rzmq
137
- licenses: []
138
-
116
+ licenses:
117
+ - MIT
118
+ metadata: {}
139
119
  post_install_message:
140
120
  rdoc_options: []
141
-
142
- require_paths:
121
+ require_paths:
143
122
  - lib
144
- required_ruby_version: !ruby/object:Gem::Requirement
145
- requirements:
123
+ required_ruby_version: !ruby/object:Gem::Requirement
124
+ requirements:
146
125
  - - ">="
147
- - !ruby/object:Gem::Version
148
- segments:
149
- - 0
150
- version: "0"
151
- required_rubygems_version: !ruby/object:Gem::Requirement
152
- requirements:
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ required_rubygems_version: !ruby/object:Gem::Requirement
129
+ requirements:
153
130
  - - ">="
154
- - !ruby/object:Gem::Version
155
- segments:
156
- - 0
157
- version: "0"
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
158
133
  requirements: []
159
-
160
134
  rubyforge_project: ffi-rzmq
161
- rubygems_version: 1.3.6
135
+ rubygems_version: 2.2.2
162
136
  signing_key:
163
- specification_version: 3
164
- summary: This gem wraps the ZeroMQ (0mq) networking library using Ruby FFI (foreign function interface).
165
- test_files:
137
+ specification_version: 4
138
+ summary: This gem wraps the ZeroMQ (0mq) networking library using Ruby FFI (foreign
139
+ function interface).
140
+ test_files:
166
141
  - spec/context_spec.rb
167
142
  - spec/device_spec.rb
168
143
  - spec/message_spec.rb
@@ -175,3 +150,4 @@ test_files:
175
150
  - spec/spec_helper.rb
176
151
  - spec/support/test.crt
177
152
  - spec/support/test.key
153
+ - spec/util_spec.rb
@@ -1,139 +0,0 @@
1
-
2
- require File.join(File.dirname(__FILE__), '..', '..', 'lib', 'ffi-rzmq')
3
-
4
-
5
- # Within a single process, we start up two threads. One thread has a REQ (request)
6
- # socket and the second thread has a REP (reply) socket. We measure the
7
- # *round-trip* latency between these sockets. Only *one* message is in flight at
8
- # any given moment.
9
- #
10
- # This example also illustrates how a single context can be shared amongst several
11
- # threads. Sharing a single context also allows a user to specify the "inproc"
12
- # transport in addition to "tcp" and "ipc".
13
- #
14
- # % ruby latency_measurement.rb tcp://127.0.0.1:5555 1024 1_000_000
15
- #
16
- # % ruby latency_measurement.rb inproc://lm_sock 1024 1_000_000
17
- #
18
-
19
- if ARGV.length < 3
20
- puts "usage: ruby latency_measurement.rb <connect-to> <message-size> <roundtrip-count>"
21
- exit
22
- end
23
-
24
- link = ARGV[0]
25
- message_size = ARGV[1].to_i
26
- roundtrip_count = ARGV[2].to_i
27
-
28
- def assert(rc)
29
- raise "Last API call failed at #{caller(1)}" unless rc >= 0
30
- end
31
-
32
- begin
33
- master_context = ZMQ::Context.new
34
- rescue ContextError => e
35
- STDERR.puts "Failed to allocate context or socket!"
36
- raise
37
- end
38
-
39
-
40
- class Receiver
41
- def initialize context, link, size, count
42
- @context = context
43
- @link = link
44
- @size = size
45
- @count = count
46
-
47
- begin
48
- @socket = @context.socket(ZMQ::REP)
49
- rescue ContextError => e
50
- STDERR.puts "Failed to allocate REP socket!"
51
- raise
52
- end
53
-
54
- assert(@socket.setsockopt(ZMQ::LINGER, 100))
55
-
56
- assert(@socket.setsockopt(ZMQ::HWM, 100))
57
-
58
- assert(@socket.bind(@link))
59
- end
60
-
61
- def run
62
- @count.times do
63
- string = ''
64
- assert(@socket.recv_string(string, 0))
65
-
66
- raise "Message size doesn't match, expected [#{@size}] but received [#{string.size}]" if @size != string.size
67
-
68
- assert(@socket.send_string(string, 0))
69
- end
70
-
71
- assert(@socket.close)
72
- end
73
- end
74
-
75
- class Transmitter
76
- def initialize context, link, size, count
77
- @context = context
78
- @link = link
79
- @size = size
80
- @count = count
81
-
82
- begin
83
- @socket = @context.socket(ZMQ::REQ)
84
- rescue ContextError => e
85
- STDERR.puts "Failed to allocate REP socket!"
86
- raise
87
- end
88
-
89
- assert(@socket.setsockopt(ZMQ::LINGER, 100))
90
-
91
- assert(@socket.setsockopt(ZMQ::HWM, 100))
92
-
93
- assert(@socket.connect(@link))
94
- end
95
-
96
- def run
97
- msg = "#{ '3' * @size }"
98
-
99
- elapsed = elapsed_microseconds do
100
- @count.times do
101
- assert(@socket.send_string(msg, 0))
102
- assert(@socket.recv_string(msg, 0))
103
-
104
- raise "Message size doesn't match, expected [#{@size}] but received [#{msg.size}]" if @size != msg.size
105
- end
106
- end
107
-
108
- latency = elapsed / @count / 2
109
-
110
- puts "message size: %i [B]" % @size
111
- puts "roundtrip count: %i" % @count
112
- puts "throughput (msgs/s): %i" % (@count / (elapsed / 1_000_000))
113
- puts "mean latency: %.3f [us]" % latency
114
- assert(@socket.close)
115
- end
116
-
117
- def elapsed_microseconds(&blk)
118
- start = Time.now
119
- yield
120
- value = ((Time.now - start) * 1_000_000)
121
- end
122
- end
123
-
124
- threads = []
125
- threads << Thread.new do
126
- receiver = Receiver.new(master_context, link, message_size, roundtrip_count)
127
- receiver.run
128
- end
129
-
130
- sleep 1
131
-
132
- threads << Thread.new do
133
- transmitter = Transmitter.new(master_context, link, message_size, roundtrip_count)
134
- transmitter.run
135
- end
136
-
137
- threads.each {|t| t.join}
138
-
139
- master_context.terminate
@@ -1,58 +0,0 @@
1
- #
2
- # Copyright (c) 2007-2010 iMatix Corporation
3
- #
4
- # This file is part of 0MQ.
5
- #
6
- # 0MQ is free software; you can redistribute it and/or modify it under
7
- # the terms of the Lesser GNU General Public License as published by
8
- # the Free Software Foundation; either version 3 of the License, or
9
- # (at your option) any later version.
10
- #
11
- # 0MQ is distributed in the hope that it will be useful,
12
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- # Lesser GNU General Public License for more details.
15
- #
16
- # You should have received a copy of the Lesser GNU General Public License
17
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
18
-
19
- require File.join(File.dirname(__FILE__), '..', '..', 'lib', 'ffi-rzmq')
20
-
21
- if ARGV.length < 3
22
- puts "usage: ruby local_lat.rb <connect-to> <message-size> <roundtrip-count>"
23
- exit
24
- end
25
-
26
- bind_to = ARGV[0]
27
- message_size = ARGV[1].to_i
28
- roundtrip_count = ARGV[2].to_i
29
-
30
- def assert(rc)
31
- raise "Last API call failed at #{caller(1)}" unless rc >= 0
32
- end
33
-
34
- begin
35
- ctx = ZMQ::Context.new
36
- s = ctx.socket(ZMQ::REP)
37
- rescue ContextError => e
38
- STDERR.puts "Failed to allocate context or socket!"
39
- raise
40
- end
41
-
42
- assert(s.setsockopt(ZMQ::LINGER, 100))
43
- assert(s.setsockopt(ZMQ::HWM, 100))
44
-
45
- assert(s.bind(bind_to))
46
-
47
- roundtrip_count.times do
48
- string = ''
49
- assert(s.recv_string(string, 0))
50
-
51
- raise "Message size doesn't match, expected [#{message_size}] but received [#{string.size}]" if message_size != string.size
52
-
53
- assert(s.send_string(string, 0))
54
- end
55
-
56
- assert(s.close)
57
-
58
- ctx.terminate