ffi-rzmq 1.0.3 → 2.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
@@ -47,44 +47,29 @@ module ZMQ
47
47
 
48
48
  # Use the factory method Context#create to make contexts.
49
49
  #
50
- if LibZMQ.version2?
51
- def self.create io_threads = 1
52
- new(io_threads) rescue nil
53
- end
54
-
55
- def initialize io_threads = 1
56
- @io_threads = io_threads
57
- @context = LibZMQ.zmq_init io_threads
58
- ZMQ::Util.error_check 'zmq_init', (@context.nil? || @context.null?) ? -1 : 0
59
-
60
- define_finalizer
61
- end
62
- elsif LibZMQ.version3?
50
+ def self.create(opts = {})
51
+ new(opts) rescue nil
52
+ end
63
53
 
64
- def self.create(opts = {})
65
- new(opts) rescue nil
54
+ def initialize(opts = {})
55
+ if opts.respond_to?(:empty?)
56
+ @io_threads = opts[:io_threads] || IO_THREADS_DFLT
57
+ @max_sockets = opts[:max_sockets] || MAX_SOCKETS_DFLT
58
+ else
59
+ @io_threads = opts || 1
60
+ @max_sockets = MAX_SOCKETS_DFLT
66
61
  end
67
62
 
68
- def initialize(opts = {})
69
- if opts.respond_to?(:empty?)
70
- @io_threads = opts[:io_threads] || IO_THREADS_DFLT
71
- @max_sockets = opts[:max_sockets] || MAX_SOCKETS_DFLT
72
- else
73
- @io_threads = opts || 1
74
- @max_sockets = MAX_SOCKETS_DFLT
75
- end
76
-
77
- @context = LibZMQ.zmq_ctx_new
78
- ZMQ::Util.error_check 'zmq_ctx_new', (@context.nil? || @context.null?) ? -1 : 0
63
+ @context = LibZMQ.zmq_ctx_new
64
+ ZMQ::Util.error_check 'zmq_ctx_new', (@context.nil? || @context.null?) ? -1 : 0
79
65
 
80
- rc = LibZMQ.zmq_ctx_set(@context, ZMQ::IO_THREADS, @io_threads)
81
- ZMQ::Util.error_check 'zmq_ctx_set', rc
66
+ rc = LibZMQ.zmq_ctx_set(@context, ZMQ::IO_THREADS, @io_threads)
67
+ ZMQ::Util.error_check 'zmq_ctx_set', rc
82
68
 
83
- rc = LibZMQ.zmq_ctx_set(@context, ZMQ::MAX_SOCKETS, @max_sockets)
84
- ZMQ::Util.error_check 'zmq_ctx_set', rc
69
+ rc = LibZMQ.zmq_ctx_set(@context, ZMQ::MAX_SOCKETS, @max_sockets)
70
+ ZMQ::Util.error_check 'zmq_ctx_set', rc
85
71
 
86
- define_finalizer
87
- end
72
+ define_finalizer
88
73
  end
89
74
 
90
75
  # Call to release the context and any remaining data associated
@@ -94,27 +79,14 @@ module ZMQ
94
79
  #
95
80
  # Returns 0 for success, -1 for failure.
96
81
  #
97
- if LibZMQ.version2?
98
- def terminate
99
- unless @context.nil? || @context.null?
100
- remove_finalizer
101
- rc = LibZMQ.zmq_term @context
102
- @context = nil
103
- rc
104
- else
105
- 0
106
- end
107
- end
108
- elsif LibZMQ.version3?
109
- def terminate
110
- unless @context.nil? || @context.null?
111
- remove_finalizer
112
- rc = LibZMQ.zmq_ctx_destroy(@context)
113
- @context = nil
114
- rc
115
- else
116
- 0
117
- end
82
+ def terminate
83
+ unless @context.nil? || @context.null?
84
+ remove_finalizer
85
+ rc = LibZMQ.terminate_context(@context)
86
+ @context = nil
87
+ rc || 0
88
+ else
89
+ 0
118
90
  end
119
91
  end
120
92
 
@@ -157,7 +129,7 @@ module ZMQ
157
129
  end
158
130
 
159
131
  def self.close context, pid
160
- Proc.new { LibZMQ.zmq_term context if !context.null? && Process.pid == pid }
132
+ Proc.new { LibZMQ.zmq_ctx_term context if !context.null? && Process.pid == pid }
161
133
  end
162
134
  end
163
135
 
@@ -3,10 +3,10 @@ module ZMQ
3
3
  class Device
4
4
  attr_reader :device
5
5
 
6
- def self.create(device_type, frontend, backend)
6
+ def self.create(frontend, backend, capture=nil)
7
7
  dev = nil
8
8
  begin
9
- dev = new(device_type, frontend, backend)
9
+ dev = new(frontend, backend, capture)
10
10
  rescue ArgumentError
11
11
  dev = nil
12
12
  end
@@ -14,15 +14,19 @@ module ZMQ
14
14
  dev
15
15
  end
16
16
 
17
- def initialize(device_type, frontend, backend)
17
+ def initialize(frontend, backend, capture=nil)
18
18
  [["frontend", frontend], ["backend", backend]].each do |name, socket|
19
19
  unless socket.is_a?(ZMQ::Socket)
20
20
  raise ArgumentError, "Expected a ZMQ::Socket, not a #{socket.class} as the #{name}"
21
21
  end
22
22
  end
23
23
 
24
- LibZMQ.zmq_device(device_type, frontend.socket, backend.socket)
24
+ LibZMQ.zmq_proxy(frontend.socket, backend.socket, capture ? capture.socket : nil)
25
25
  end
26
26
  end
27
+
28
+ # Alias for Device
29
+ #
30
+ class Proxy < Device; end
27
31
 
28
32
  end
@@ -13,6 +13,9 @@ module ZMQ
13
13
  end
14
14
  end # call ZeroMQError
15
15
 
16
+ class NotSupportedError < ZeroMQError
17
+ end
18
+
16
19
 
17
20
  class ContextError < ZeroMQError
18
21
  # True when the exception was raised due to the library
@@ -84,8 +84,8 @@ module ZMQ
84
84
  # puts "value1 is #{message.value1}"
85
85
  #
86
86
  class Message
87
-
88
- # Recommended way to create a standard message. A Message object is
87
+
88
+ # Recommended way to create a standard message. A Message object is
89
89
  # returned upon success, nil when allocation fails.
90
90
  #
91
91
  def self.create message = nil
@@ -129,7 +129,7 @@ module ZMQ
129
129
  data_buffer.write_string bytes, len
130
130
 
131
131
  # use libC to call free on the data buffer; earlier versions used an
132
- # FFI::Function here that called back into Ruby, but Rubinius won't
132
+ # FFI::Function here that called back into Ruby, but Rubinius won't
133
133
  # support that and there are issues with the other runtimes too
134
134
  LibZMQ.zmq_msg_init_data @pointer, data_buffer, len, LibC::Free, nil
135
135
  end
@@ -182,42 +182,36 @@ module ZMQ
182
182
  #
183
183
  def close
184
184
  rc = 0
185
-
185
+
186
186
  if @pointer
187
187
  rc = LibZMQ.zmq_msg_close @pointer
188
188
  @pointer = nil
189
189
  end
190
-
190
+
191
191
  rc
192
192
  end
193
-
193
+
194
194
  # cache the msg size so we don't have to recalculate it when creating
195
195
  # each new instance
196
- @msg_size = LibZMQ::Msg.size
197
-
196
+ @msg_size = LibZMQ::Message.size
197
+
198
198
  def self.msg_size() @msg_size; end
199
199
 
200
200
  end # class Message
201
-
202
- if LibZMQ.version3?
203
- class Message
204
- # Version3 only
205
- #
206
- def get(property)
207
- LibZMQ.zmq_msg_get(@pointer, property)
208
- end
209
-
210
- # Version3 only
211
- #
212
- # Returns true if this message has additional parts coming.
213
- #
214
- def more?
215
- Util.resultcode_ok?(get(MORE))
216
- end
217
-
218
- def set(property, value)
219
- LibZMQ.zmq_msg_set(@pointer, property, value)
220
- end
201
+
202
+ class Message
203
+ def get(property)
204
+ LibZMQ.zmq_msg_get(@pointer, property)
205
+ end
206
+
207
+ # Returns true if this message has additional parts coming.
208
+ #
209
+ def more?
210
+ Util.resultcode_ok?(get(MORE))
211
+ end
212
+
213
+ def set(property, value)
214
+ LibZMQ.zmq_msg_set(@pointer, property, value)
221
215
  end
222
216
  end
223
217
 
@@ -254,7 +248,7 @@ module ZMQ
254
248
  #
255
249
  def copy_in_bytes bytes, len
256
250
  rc = super(bytes, len)
257
-
251
+
258
252
  # make sure we have a way to deallocate this memory if the object goes
259
253
  # out of scope
260
254
  define_finalizer
@@ -296,7 +290,7 @@ module ZMQ
296
290
  # cache the msg size so we don't have to recalculate it when creating
297
291
  # each new instance
298
292
  # need to do this again because ivars are not inheritable
299
- @msg_size = LibZMQ::Msg.size
293
+ @msg_size = LibZMQ::Message.size
300
294
 
301
295
  end # class ManagedMessage
302
296
 
data/lib/ffi-rzmq/poll.rb CHANGED
@@ -150,22 +150,11 @@ module ZMQ
150
150
  # milliseconds, so we need to convert that value to
151
151
  # microseconds for the library.
152
152
  #
153
- if LibZMQ.version2?
154
- def adjust timeout
155
- if :blocking == timeout || -1 == timeout
156
- -1
157
- else
158
- (timeout * 1000).to_i
159
- end
160
- end
161
- else
162
- # version3 changed units from microseconds to milliseconds
163
- def adjust timeout
164
- if :blocking == timeout || -1 == timeout
165
- -1
166
- else
167
- timeout.to_i
168
- end
153
+ def adjust timeout
154
+ if :blocking == timeout || -1 == timeout
155
+ -1
156
+ else
157
+ timeout.to_i
169
158
  end
170
159
  end
171
160
 
@@ -1,5 +1,4 @@
1
1
  require 'forwardable'
2
- require 'io_extensions'
3
2
 
4
3
  module ZMQ
5
4
  class PollItem