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
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 403a3126661f6dc781b72e58f03a2c6b84e38c8d72e9f4b25115c44731aef8e7
4
+ data.tar.gz: 86bd066c1eddd598e67387144e21e45875e2fd79e8a57c6d38c56f04a11b2f19
5
+ SHA512:
6
+ metadata.gz: 8704b9f4d77c7a3dba2381dfea0a8cc96604b453c4e042162c0410371bea0207433b8348b954398c5855427e6f4efc8b51a437a7abe4582f4de1d73e42ed17c1
7
+ data.tar.gz: a4df109b2adcc9b18ea2f772bac5d1130b33b7066a8c1160706cc201c0aa08f58acbef56b44c53a9151c38f9bcb553ccb2ede46182bfdaf9d79bccf85a7b4b08
data/.travis.yml CHANGED
@@ -1,15 +1,14 @@
1
- before_install: sudo apt-get install libzmq3-dev
2
- script: bundle exec rspec
1
+ script: ./travis_build_script.sh
3
2
  language: ruby
4
3
  rvm:
5
- - 1.9.3
6
- - 2.0.0
4
+ - 2.6.0
7
5
  - ruby-head
8
- - jruby-19mode
6
+ - jruby
9
7
  - jruby-head
10
- - rbx-19mode
8
+ - rbx-3
11
9
 
12
10
  matrix:
13
11
  allow_failures:
14
12
  - rvm: ruby-head
15
13
  - rvm: jruby-head
14
+ - rvm: rbx-3
data/AUTHORS.txt CHANGED
@@ -28,4 +28,10 @@ Simon Chiang , github: thinkerbot
28
28
 
29
29
  Harlow Ward, github: harlow
30
30
 
31
- Paul Chechetin, github: paulche
31
+ Paul Chechetin, github: paulche
32
+
33
+ Michael Zaccari, github: mzaccari
34
+
35
+ Jason Roelofs, github: jasonroelofs
36
+
37
+ Cédric Boutillier, github: boutil
data/History.txt CHANGED
@@ -1,3 +1,82 @@
1
+ == 2.0.7
2
+ * Fix Issue #130
3
+ Fix to better support Zeromq 3.x users when performing context termination.
4
+ Support library ffi-rzmq-core was updated to handle this support, so
5
+ we now have a minimum dependency of ffi-rzmq-core 1.0.7 on this gem.
6
+
7
+ * Fix Issue #131
8
+ Update the OpenSSL key and certificate files. Original files were 1024 bits
9
+ but this causes problems on some modern Linux (e.g. Debian) which complains
10
+ about the key length. Updated to 4096 bits. Copied the key and cert
11
+ generation scripts from the Debian repository with attribution. Thanks to
12
+ @boutil for the helper script and the bug report.
13
+
14
+ == 2.0.6
15
+ * Fix for uncaught exception. Strange case... somehow calling
16
+ `zmq_ctx_term` was returning nil, so when checking the result code it
17
+ would fail. No overrides a nil value with 0 so check passes.
18
+
19
+ * Update some JRuby-specific code to fetch a file descriptor value. API
20
+ changed from earlier versions, so code is updated to use new API. All
21
+ specs pass.
22
+
23
+ == 2.0.5
24
+ * Fix issue #123. Bundled gems were a bit outdated so upgraded to latest
25
+ rspec gem.
26
+
27
+ * Fix issue #124. Newer releases of libzmq are not exporting all symbols
28
+ to the global namespace so some lazy loading performed by FFI was
29
+ failing. Now force all symbols into global namespace.
30
+
31
+ * Fix "::Fixnum has been deprecated" warnings from MRI 2.4.x+.
32
+
33
+ * Force ffi-rzmq-core 1.0.6 or later as dependency.
34
+
35
+ == 2.0.4
36
+ * Screwed up the release managment. Had wrong version in version.rb. Fixed.
37
+
38
+ == 2.0.3
39
+ * Updated specs to use RSpec 3.x syntax. Never again... if they change it
40
+ then I'm dumping rspec.
41
+
42
+ * Now loading version.rb during startup so that ZMQ::VERSION returns a string.
43
+
44
+ * Modified README to point most people to the Ruby gem that wraps the CZMQ
45
+ library. It's a much higher-level library that makes writing zeromq apps
46
+ very easy. This gem is for writing low-level code which most people don't
47
+ want or need to do. This gem is going into maintenance mode only.
48
+
49
+
50
+ == 2.0.2
51
+
52
+ * Updated README to make it clearer which versions of libzmq are supported.
53
+
54
+ * Updated README to use a newer example.
55
+
56
+ == 2.0.1 / 20140122
57
+ * Fix setsockopt with string parameters for options that have very strict
58
+ requirements (like CURVE_SECRETKEY) (37aed3c)
59
+
60
+ * Provide a wrapper for zmq_curve_keypair for ZeroMQ4
61
+
62
+ == 2.0.0 / 20140108
63
+ * Split out all of the FFI code to its own gem so other projects can use
64
+ it without the effort of duplication.
65
+
66
+ * Support libzmq 4 API and its new security API . Thanks to Devin
67
+ Christensen (devin-c) and Jason Roelofs (jasonroelofs) for related
68
+ patches.
69
+
70
+ * Minor documentation fixes. Thanks to Michael Zaccari (mzaccari) for
71
+ the fix.
72
+
73
+ * Improved the readability of any FFI code (now moved to ffi-rzmq-core
74
+ project). Thanks to Stephen von Takach (stakach) for the patch.
75
+
76
+ * Updated AUTHORS.txt
77
+
78
+
79
+
1
80
  == 1.0.3 / 20131003
2
81
  * Fixes for issues #96 and #97. Thanks to Paul Chechetin (paulche) for
3
82
  the issues and patches.
data/README.rdoc CHANGED
@@ -2,6 +2,22 @@ ffi-rzmq
2
2
  by Chuck Remes
3
3
  http://www.zeromq.org/bindings:ruby-ffi
4
4
 
5
+ == FUTURE SUPPORT
6
+
7
+ Most people writing Zeromq applications in Ruby should be using the rbczmq
8
+ project. It wraps the CZMQ binding which is a much higher-level library
9
+ for writing Zeromq code. Find the Ruby gem here:
10
+
11
+ http://github.com/methodmissing/rbczmq
12
+
13
+ Few projects need to write the low-level zeromq code that this gem allows.
14
+ With the release of ffi-rzmq 2.0.3, this library is going into permanent
15
+ maintenance mode. As new versions of libzmq are released, interested parties
16
+ should send pull requests to this project or its related project
17
+ ffi-rzmq-core to support new features.
18
+
19
+ The original README text follows...
20
+
5
21
  == DESCRIPTION:
6
22
 
7
23
  This gem wraps the ZeroMQ networking library using the ruby FFI (foreign
@@ -9,11 +25,18 @@ function interface). It's a pure ruby wrapper so this gem can be loaded
9
25
  and run by any ruby runtime that supports FFI. That's all of them:
10
26
  MRI 1.9.x, Rubinius and JRuby.
11
27
 
12
- This single gem supports 0mq 2.2.x and 3.2.x 0mq APIs. The 0mq project started
28
+ The Ruby API provided by this gem is *NOT* very Ruby-like. It very closely
29
+ tracks the libzmq C API. However, the contributors to this project have
30
+ done all of the hard work to wrap up all of libzmq and make it accessible
31
+ from Ruby. If you want it to be more Ruby-like (e.g. raise Exceptions instead
32
+ of returning integer codes) then *wrap this library* with your own and release
33
+ it as a gem. We will all be grateful!
34
+
35
+ This single gem supports 0mq 3.2.x and 4.x APIs. The 0mq project started
13
36
  making backward-incompatible changes to the API with the 3.1.x release.
14
37
  The gem auto-configures itself to expose the API conforming to the loaded
15
- C library. 0mq API 3.0 is *not* supported; the 0mq community voted to
16
- abandon it.
38
+ C library. 0mq 2.x is no longer supported. 0mq API 3.0 is *not* supported;
39
+ the 0mq community voted to abandon it.
17
40
 
18
41
  The impetus behind this library was to provide support for ZeroMQ in
19
42
  JRuby which has native threads. Unlike MRI, which has a GIL, JRuby and
@@ -36,7 +59,7 @@ than using a C extension.
36
59
  == FEATURES/PROBLEMS:
37
60
 
38
61
  This gem needs more tests. This gem has been battle tested by myself
39
- and others for over a year, so I am fairly confident that it is solid.
62
+ and others for years, so I am fairly confident that it is solid.
40
63
  However, it is inevitable that there will be bugs, so please open
41
64
  issues for them here or fork this project, fix them, and send me a pull
42
65
  request.
@@ -46,6 +69,14 @@ on that gem to load and run this code, then this project also no longer
46
69
  supports MRI 1.8.x. I recommend JRuby for the best performance and
47
70
  stability.
48
71
 
72
+ The `Socket` and `Context` classes have finalizers which will
73
+ be called by the garbage collector when there are no more references.
74
+ However, these finalizers should not be relied upon to orderly close
75
+ your sockets and then the context. Finalizers run in a non-determinant
76
+ order, so the `Context` finalizer may run first which will hang the
77
+ program. To avoid this, make sure to close all sockets before the
78
+ program exits.
79
+
49
80
  All features are implemented.
50
81
 
51
82
  == BUILD STATUS:
@@ -56,62 +87,71 @@ All features are implemented.
56
87
 
57
88
  == SYNOPSIS:
58
89
 
59
- 0mq API v2 client code:
90
+ 0mq API v3.2-4 client code:
60
91
 
61
92
  require 'rubygems'
62
93
  require 'ffi-rzmq'
63
94
 
64
95
  if ARGV.length < 3
65
- puts "usage: local_lat <connect-to> <message-size> <roundtrip-count>"
96
+ puts "usage: ruby local_lat.rb <connect-to> <message-size> <roundtrip-count>"
66
97
  exit
67
98
  end
68
-
99
+
69
100
  bind_to = ARGV[0]
70
101
  message_size = ARGV[1].to_i
71
102
  roundtrip_count = ARGV[2].to_i
72
103
 
73
104
  ctx = ZMQ::Context.new
74
- s = ctx.socket ZMQ::REP
75
- rc = s.setsockopt(ZMQ::HWM, 100)
76
- rc = s.bind(bind_to)
105
+ s = ctx.socket ZMQ::REP
106
+ rc = s.setsockopt(ZMQ::SNDHWM, 100)
107
+ rc = s.setsockopt(ZMQ::RCVHWM, 100)
108
+ rc = s.bind(bind_to)
77
109
 
78
- msg = ""
79
110
  roundtrip_count.times do
80
- rc = s.recv_string msg
111
+ msg = ""
112
+ rc = s.recv_string msg
81
113
  raise "Message size doesn't match, expected [#{message_size}] but received [#{msg.size}]" if message_size != msg.size
82
- rc = s.send_string msg, 0
114
+ rc = s.send_string msg, 0
83
115
  end
84
116
 
85
-
86
- 0mq API v2 server code:
117
+ 0mq API v3.2-4 server code:
87
118
 
88
119
  require 'rubygems'
89
120
  require 'ffi-rzmq'
90
121
 
91
122
  if ARGV.length < 3
92
- puts "usage: remote_lat <connect-to> <message-size> <roundtrip-count>"
123
+ puts "usage: ruby remote_lat.rb <connect-to> <message-size> <roundtrip-count>"
93
124
  exit
94
125
  end
95
-
126
+
127
+ def assert(rc)
128
+ raise "Last API call failed at #{caller(1)}" unless rc >= 0
129
+ end
130
+
96
131
  connect_to = ARGV[0]
97
132
  message_size = ARGV[1].to_i
98
133
  roundtrip_count = ARGV[2].to_i
99
134
 
100
135
  ctx = ZMQ::Context.new
101
- s = ctx.socket ZMQ::REQ
102
- rc = s.connect(connect_to)
136
+ s = ctx.socket ZMQ::REQ
137
+ rc = s.connect(connect_to)
103
138
 
104
139
  msg = "#{ '3' * message_size }"
105
140
 
106
- start_time = Time.now
141
+ time_start = Time.now
107
142
 
108
- msg = ""
109
143
  roundtrip_count.times do
110
- rc = s.send_string msg, 0
111
- rc = s.recv_string msg
144
+ assert(s.send_string(msg, 0))
145
+
146
+ msg = ''
147
+ assert(s.recv_string(msg, 0))
148
+
112
149
  raise "Message size doesn't match, expected [#{message_size}] but received [#{msg.size}]" if message_size != msg.size
113
150
  end
114
151
 
152
+ time_end = Time.now
153
+ puts "Time #{( time_end - time_start )}"
154
+
115
155
  == Better Examples
116
156
 
117
157
  I highly recommend visiting the Learn Ruby 0mq project for a bunch of good code examples.
@@ -122,17 +162,15 @@ I highly recommend visiting the Learn Ruby 0mq project for a bunch of good code
122
162
 
123
163
  == REQUIREMENTS:
124
164
 
125
- * 0mq 2.2.x, 3.2.x or later; 2.0.x, 3.0.x and 3.1.x are no longer supported
165
+ * 0mq 3.2.x, 4.x or later; 2.x, 3.0.x and 3.1.x are no longer supported
126
166
 
127
167
  The ZeroMQ library must be installed on your system in a well-known location
128
168
  like /usr/local/lib. This is the default for new ZeroMQ installs.
129
169
 
130
170
  If you have installed ZeroMQ using brew, you need to `brew link zeromq` before installing this gem.
131
171
 
132
- Future releases may include the library as a C extension built at
133
- time of installation.
134
-
135
172
  * ffi (>= 1.0.0)
173
+ * ffi-rzmq-core
136
174
 
137
175
  This is a requirement for MRI and Rubinius. JRuby has FFI support built
138
176
  in as a standard component. Do *not* run this gem under MRI with an old 'ffi' gem.
@@ -141,7 +179,7 @@ It will crash randomly and you will be sad.
141
179
 
142
180
  == INSTALL:
143
181
 
144
- Make sure the ZeroMQ library is already installed on your system.
182
+ Make sure the ZeroMQ library is already installed on your system. We recommend 'brew' or 'macports' to get it.
145
183
 
146
184
  % gem install ffi-rzmq # should grab the latest release
147
185
 
@@ -163,7 +201,7 @@ that activity. That DLL also requires that you copy libstdc++-6.dll and libgcc_s
163
201
 
164
202
  (The MIT License)
165
203
 
166
- Copyright (c) 2013 Chuck Remes
204
+ Copyright (c) 2013-2017 Chuck Remes
167
205
 
168
206
  Permission is hereby granted, free of charge, to any person obtaining
169
207
  a copy of this software and associated documentation files (the
data/Rakefile CHANGED
@@ -4,3 +4,18 @@ require 'rspec/core/rake_task'
4
4
  RSpec::Core::RakeTask.new
5
5
 
6
6
  task :default => :spec
7
+
8
+ task :console do
9
+ require 'irb'
10
+ require 'irb/completion'
11
+ require 'ffi-rzmq'
12
+ ARGV.clear
13
+ IRB.start
14
+ end
15
+
16
+ task :pryconsole do
17
+ require 'pry'
18
+ require 'ffi-rzmq'
19
+ ARGV.clear
20
+ Pry.start
21
+ end
data/examples/README.rdoc CHANGED
@@ -4,14 +4,12 @@
4
4
 
5
5
  1. lib dir
6
6
 
7
- All of the examples assume the lib directory containing the gem sources is two directories up from the location of the example.
7
+ All of the examples assume the lib directory containing the gem sources is one directory up from the location of the example.
8
8
 
9
9
  2. Installed libzmq library
10
10
 
11
11
  The ZeroMQ C libraries need to be downloaded, compiled and installed separately from the gem. Please see http://www.zeromq.org/area:download for links to the downloadable files along with some simple installation instructions. Also, be sure to check the FAQ if you run into problems with compiling.
12
12
 
13
- This gem auto-configures itself to conform to the API for 0mq 2.1.x and 3.1.x. The 0mq project started making backward-incompatible changes with the 3.x branch. Rather than create separate gems, this one handles all of them.
14
-
15
13
  It is possible to install the libzmq* files directly into the gem in the ext/ directory. This directory is checked for loadable libraries first before it falls back to checking the system paths.
16
14
 
17
15
  3. One terminal window
@@ -1,6 +1,5 @@
1
1
 
2
- require File.join(File.dirname(__FILE__), '..', '..', 'lib', 'ffi-rzmq')
3
-
2
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'ffi-rzmq')
4
3
 
5
4
  # Within a single process, we start up two threads. One thread has a REQ (request)
6
5
  # socket and the second thread has a REP (reply) socket. We measure the
@@ -16,7 +16,7 @@
16
16
  # You should have received a copy of the Lesser GNU General Public License
17
17
  # along with this program. If not, see <http://www.gnu.org/licenses/>.
18
18
 
19
- require File.join(File.dirname(__FILE__), '..', '..', 'lib', 'ffi-rzmq')
19
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'ffi-rzmq')
20
20
 
21
21
  if ARGV.length < 3
22
22
  puts "usage: ruby local_lat.rb <connect-to> <message-size> <roundtrip-count>"
@@ -1,5 +1,5 @@
1
1
 
2
- require File.join(File.dirname(__FILE__), '..', '..', 'lib', 'ffi-rzmq')
2
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'ffi-rzmq')
3
3
 
4
4
  if ARGV.length < 3
5
5
  puts "usage: ruby local_lat.rb <connect-to> <message-size> <roundtrip-count>"
@@ -38,7 +38,7 @@ start_time = Time.now
38
38
 
39
39
  # kick it off
40
40
  message = ZMQ::Message.new("a" * message_size)
41
- assert(s1.sendmsg(message, ZMQ::NonBlocking))
41
+ assert(s1.sendmsg(message, ZMQ::DONTWAIT))
42
42
 
43
43
  i = roundtrip_count
44
44
 
@@ -49,8 +49,8 @@ until i.zero?
49
49
 
50
50
  poller.readables.each do |socket|
51
51
  received_message = ''
52
- assert(socket.recv_string(received_message, ZMQ::NonBlocking))
53
- assert(socket.sendmsg(ZMQ::Message.new(received_message), ZMQ::NonBlocking))
52
+ assert(socket.recv_string(received_message, ZMQ::DONTWAIT))
53
+ assert(socket.sendmsg(ZMQ::Message.new(received_message), ZMQ::DONTWAIT))
54
54
  end
55
55
  end
56
56
 
@@ -1,5 +1,5 @@
1
1
 
2
- require File.join(File.dirname(__FILE__), '..', '..', 'lib', 'ffi-rzmq')
2
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'ffi-rzmq')
3
3
 
4
4
  if ARGV.length != 3
5
5
  puts "usage: ruby local_throughtput.rb <bind-to> <message-size> <message-count>"
@@ -1,5 +1,5 @@
1
1
 
2
- require File.join(File.dirname(__FILE__), '..', '..', 'lib', 'ffi-rzmq')
2
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'ffi-rzmq')
3
3
 
4
4
  if ARGV.length != 3
5
5
  puts "usage: ruby remote_throughput.rb <connect-to> <message-size> <message-count>"
@@ -1,4 +1,4 @@
1
- require File.join(File.dirname(__FILE__), '..', '..', 'lib', 'ffi-rzmq')
1
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'ffi-rzmq')
2
2
 
3
3
 
4
4
  def assert(rc)
@@ -71,7 +71,7 @@ assert(s4.recv_string(body)) if s4.more_parts?
71
71
  puts "s4 received topic [#{topic}], body [#{body}]"
72
72
 
73
73
  s5_string = ''
74
- rc = s5.recv_string(s5_string, ZMQ::NonBlocking)
74
+ rc = s5.recv_string(s5_string, ZMQ::DONTWAIT)
75
75
  eagain = (rc == -1 && ZMQ::Util.errno == ZMQ::EAGAIN)
76
76
  puts(eagain ? "s5 received no messages" : "s5 FAILED")
77
77
 
@@ -17,7 +17,7 @@
17
17
  # along with this program. If not, see <http://www.gnu.org/licenses/>.
18
18
 
19
19
 
20
- require File.join(File.dirname(__FILE__), '..', '..', 'lib', 'ffi-rzmq')
20
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'ffi-rzmq')
21
21
 
22
22
  if ARGV.length < 3
23
23
  puts "usage: ruby remote_lat.rb <connect-to> <message-size> <roundtrip-count>"
@@ -1,5 +1,5 @@
1
1
 
2
- require File.join(File.dirname(__FILE__), '..', '..', 'lib', 'ffi-rzmq')
2
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'ffi-rzmq')
3
3
 
4
4
  if ARGV.length != 3
5
5
  puts "usage: ruby remote_throughput.rb <connect-to> <message-size> <message-count>"
@@ -27,9 +27,10 @@ end
27
27
  #assert(s.setsockopt(ZMQ::SNDHWM, 0))
28
28
  assert(s.connect(connect_to))
29
29
 
30
- # the sleep gives the downstream SUB socket a chance to register its
30
+ # give the downstream SUB socket a chance to register its
31
31
  # subscription filters with this PUB socket
32
- sleep 1
32
+ puts "Hit any key to start publishing"
33
+ STDIN.gets
33
34
 
34
35
  contents = "#{'0'*message_size}"
35
36
 
@@ -0,0 +1,60 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'ffi-rzmq')
2
+
3
+ # This example shows the basics of a CURVE-secured REP/REQ setup between
4
+ # a Server and Client. This is the minimal required setup for authenticating
5
+ # a connection between a Client and a Server. For validating the Client's authentication
6
+ # once the initial connection has succeeded, you'll need a ZAP handler on the Server.
7
+
8
+ # Build the Server's keys
9
+ server_public_key, server_private_key = ZMQ::Util.curve_keypair
10
+
11
+ # Build the Client's keys
12
+ client_public_key, client_private_key = ZMQ::Util.curve_keypair
13
+
14
+ context = ZMQ::Context.new
15
+ bind_point = "tcp://127.0.0.1:4455"
16
+
17
+ ##
18
+ # Configure the Server
19
+ ##
20
+ server = context.socket ZMQ::REP
21
+
22
+ server.setsockopt(ZMQ::CURVE_SERVER, 1)
23
+ server.setsockopt(ZMQ::CURVE_SECRETKEY, server_private_key)
24
+
25
+ server.bind(bind_point)
26
+
27
+ ##
28
+ # Configure the Client to talk to the Server
29
+ ##
30
+ client = context.socket ZMQ::REQ
31
+
32
+ client.setsockopt(ZMQ::CURVE_SERVERKEY, server_public_key)
33
+ client.setsockopt(ZMQ::CURVE_PUBLICKEY, client_public_key)
34
+ client.setsockopt(ZMQ::CURVE_SECRETKEY, client_private_key)
35
+
36
+ client.connect(bind_point)
37
+
38
+ ##
39
+ # Show that communication still works
40
+ ##
41
+
42
+ client_message = "Hello Server!"
43
+ server_response = "Hello Client!"
44
+
45
+ puts "Client sending: #{client_message}"
46
+ client.send_string client_message
47
+
48
+ server.recv_string(server_message = '')
49
+ puts "Server received: #{server_message}, replying with #{server_response}"
50
+
51
+ server.send_string(server_response)
52
+
53
+ client.recv_string(response = '')
54
+ puts "Client has received: #{response}"
55
+
56
+ puts "Finished"
57
+
58
+ client.close
59
+ server.close
60
+ context.terminate
@@ -1,6 +1,5 @@
1
1
 
2
- require File.join(File.dirname(__FILE__), '..', '..', 'lib', 'ffi-rzmq')
3
-
2
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'ffi-rzmq')
4
3
 
5
4
  def assert(rc)
6
5
  raise "Last API call failed at #{caller(1)}" unless rc >= 0
@@ -38,7 +37,7 @@ until @done do
38
37
  payload = "#{ '3' * 1024 }"
39
38
 
40
39
  puts "sending payload nonblocking"
41
- assert(s1.send_string(payload, ZMQ::NonBlocking))
40
+ assert(s1.send_string(payload, ZMQ::DONTWAIT))
42
41
  @unsent = false
43
42
  end
44
43
 
@@ -46,7 +45,7 @@ until @done do
46
45
  if Time.now - start_time > 1
47
46
  poller.readables.each do |sock|
48
47
  received_msg = ''
49
- assert(sock.recv_string(received_msg, ZMQ::NonBlocking))
48
+ assert(sock.recv_string(received_msg, ZMQ::DONTWAIT))
50
49
 
51
50
  puts "message received [#{received_msg}]"
52
51
  @done = true
@@ -1,6 +1,5 @@
1
1
 
2
- require File.join(File.dirname(__FILE__), '..', '..', 'lib', 'ffi-rzmq')
3
-
2
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'ffi-rzmq')
4
3
 
5
4
  def assert(rc)
6
5
  raise "Last API call failed at #{caller(1)}" unless rc >= 0
@@ -1,11 +1,10 @@
1
1
 
2
- require File.join(File.dirname(__FILE__), '..', '..', 'lib', 'ffi-rzmq')
2
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'ffi-rzmq')
3
3
 
4
4
  #if ARGV.length != 3
5
5
  # puts "usage: ruby local_throughtput.rb <bind-to> <message-size> <message-count>"
6
6
  # Process.exit
7
7
  #end
8
- p ZMQ::Util.version
9
8
 
10
9
  def assert(rc)
11
10
  raise "Last API call failed at #{caller(1)}" unless rc >= 0
@@ -1,4 +1,4 @@
1
- require File.join(File.dirname(__FILE__), '..', '..', 'lib', 'ffi-rzmq')
1
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'ffi-rzmq')
2
2
  require 'thread'
3
3
 
4
4
  # Within a single process, we start up five threads. Main thread has a PUB (publisher)
@@ -1,6 +1,5 @@
1
1
 
2
- require File.join(File.dirname(__FILE__), '..', '..', 'lib', 'ffi-rzmq')
3
-
2
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'ffi-rzmq')
4
3
 
5
4
  def assert(rc)
6
5
  raise "Last API call failed at #{caller(1)}" unless rc >= 0
@@ -43,7 +42,7 @@ until @done do
43
42
 
44
43
  5.times do |i|
45
44
  payload = "#{ i.to_s * 40 }"
46
- assert(s1.send_string(payload, ZMQ::NonBlocking))
45
+ assert(s1.send_string(payload, ZMQ::DONTWAIT))
47
46
  end
48
47
  @unsent = false
49
48
  end
@@ -54,12 +53,12 @@ until @done do
54
53
 
55
54
  if sock.identity =~ /xrep/
56
55
  routing_info = ''
57
- assert(sock.recv_string(routing_info, ZMQ::NonBlocking))
56
+ assert(sock.recv_string(routing_info, ZMQ::DONTWAIT))
58
57
  puts "routing_info received [#{routing_info}] on socket.identity [#{sock.identity}]"
59
58
  else
60
59
  routing_info = nil
61
60
  received_msg = ''
62
- assert(sock.recv_string(received_msg, ZMQ::NonBlocking))
61
+ assert(sock.recv_string(received_msg, ZMQ::DONTWAIT))
63
62
 
64
63
  # skip to the next iteration if received_msg is nil; that means we got an EAGAIN
65
64
  next unless received_msg
@@ -68,13 +67,13 @@ until @done do
68
67
 
69
68
  while sock.more_parts? do
70
69
  received_msg = ''
71
- assert(sock.recv_string(received_msg, ZMQ::NonBlocking))
70
+ assert(sock.recv_string(received_msg, ZMQ::DONTWAIT))
72
71
 
73
72
  puts "message received [#{received_msg}]"
74
73
  end
75
74
 
76
75
  puts "kick back a reply"
77
- assert(sock.send_string(routing_info, ZMQ::SNDMORE | ZMQ::NonBlocking)) if routing_info
76
+ assert(sock.send_string(routing_info, ZMQ::SNDMORE | ZMQ::DONTWAIT)) if routing_info
78
77
  time = Time.now.strftime "%Y-%m-%dT%H:%M:%S.#{Time.now.usec}"
79
78
  reply = "reply " + sock.identity.upcase + " #{time}"
80
79
  puts "sent reply [#{reply}], #{time}"
data/ffi-rzmq.gemspec CHANGED
@@ -11,9 +11,9 @@ Gem::Specification.new do |s|
11
11
  s.summary = %q{This gem wraps the ZeroMQ (0mq) networking library using Ruby FFI (foreign function interface).}
12
12
  s.description = %q{This gem wraps the ZeroMQ networking library using the ruby FFI (foreign
13
13
  function interface). It's a pure ruby wrapper so this gem can be loaded
14
- and run by any ruby runtime that supports FFI. That's all of the major ones -
15
- MRI, Rubinius and JRuby.}
14
+ and run by any ruby runtime that supports FFI. That's all of the major ones - MRI, Rubinius and JRuby.}
16
15
 
16
+ s.license = 'MIT'
17
17
  s.rubyforge_project = "ffi-rzmq"
18
18
 
19
19
  s.files = `git ls-files`.split("\n")
@@ -21,7 +21,7 @@ MRI, Rubinius and JRuby.}
21
21
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
22
22
  s.require_paths = ["lib"]
23
23
 
24
- s.add_runtime_dependency "ffi"#, [">= 1.0.9"]
25
- s.add_development_dependency "rspec", ["~> 2.6"]
24
+ s.add_runtime_dependency "ffi-rzmq-core", [">= 1.0.7"]
25
+ s.add_development_dependency "rspec", ["~> 3.7"]
26
26
  s.add_development_dependency "rake"
27
27
  end