ffi-rzmq 2.0.1 → 2.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d4e271f6dc0fcbad07111b4b23c969f192eb6d57
4
- data.tar.gz: d5a508626d471997f3568646cd05a95a70ad19f1
3
+ metadata.gz: 691dd239d1036375a2f06806953e89e7674d6c19
4
+ data.tar.gz: 74f1929b8be63e5d38b884e24a6bacab02fe90e9
5
5
  SHA512:
6
- metadata.gz: 72b0886538590486c2e8c64e4e03eeab7259c39a9720b0ae763f7c4d0e149cda5926ddbc1710b39ecbf4cfeee0f348d1c85e1816c437764ac99becb7be784286
7
- data.tar.gz: 0ca81c180fb1a7a8c7dd7767f7200589ec91fb42553c49eac03a2b91c5e51a95f002c64503e2d79fe77cee74adb0331a9adda1107ffd498effaa10ce2b471f01
6
+ metadata.gz: e78fb2755c2325b4de8fe3922d8c14b45a1171488ab26897c868f72e7b233b755ba1eb44bdacbd6ee4023d4228f9e57718bf86a0cf1cf427d3fb04b480d8876d
7
+ data.tar.gz: 3bc7c5bfb8d9212959a41fb8e7a00d3f73873fe5e8d68abded9f20aa182d4b6cd4d74a7d6d7e14030e5d66e5ef191cf22f1614cdffc217cc523df1cc17f91a66
@@ -1,3 +1,24 @@
1
+ == 2.0.4
2
+ * Screwed up the release managment. Had wrong version in version.rb. Fixed.
3
+
4
+ == 2.0.3
5
+ * Updated specs to use RSpec 3.x syntax. Never again... if they change it
6
+ then I'm dumping rspec.
7
+
8
+ * Now loading version.rb during startup so that ZMQ::VERSION returns a string.
9
+
10
+ * Modified README to point most people to the Ruby gem that wraps the CZMQ
11
+ library. It's a much higher-level library that makes writing zeromq apps
12
+ very easy. This gem is for writing low-level code which most people don't
13
+ want or need to do. This gem is going into maintenance mode only.
14
+
15
+
16
+ == 2.0.2
17
+
18
+ * Updated README to make it clearer which versions of libzmq are supported.
19
+
20
+ * Updated README to use a newer example.
21
+
1
22
  == 2.0.1 / 20140122
2
23
  * Fix setsockopt with string parameters for options that have very strict
3
24
  requirements (like CURVE_SECRETKEY) (37aed3c)
@@ -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.
@@ -56,62 +79,71 @@ All features are implemented.
56
79
 
57
80
  == SYNOPSIS:
58
81
 
59
- 0mq API v2 client code:
82
+ 0mq API v3.2-4 client code:
60
83
 
61
84
  require 'rubygems'
62
85
  require 'ffi-rzmq'
63
86
 
64
87
  if ARGV.length < 3
65
- puts "usage: local_lat <connect-to> <message-size> <roundtrip-count>"
88
+ puts "usage: ruby local_lat.rb <connect-to> <message-size> <roundtrip-count>"
66
89
  exit
67
90
  end
68
-
91
+
69
92
  bind_to = ARGV[0]
70
93
  message_size = ARGV[1].to_i
71
94
  roundtrip_count = ARGV[2].to_i
72
95
 
73
96
  ctx = ZMQ::Context.new
74
- s = ctx.socket ZMQ::REP
75
- rc = s.setsockopt(ZMQ::HWM, 100)
76
- rc = s.bind(bind_to)
97
+ s = ctx.socket ZMQ::REP
98
+ rc = s.setsockopt(ZMQ::SNDHWM, 100)
99
+ rc = s.setsockopt(ZMQ::RCVHWM, 100)
100
+ rc = s.bind(bind_to)
77
101
 
78
- msg = ""
79
102
  roundtrip_count.times do
80
- rc = s.recv_string msg
103
+ msg = ""
104
+ rc = s.recv_string msg
81
105
  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
106
+ rc = s.send_string msg, 0
83
107
  end
84
108
 
85
-
86
- 0mq API v2 server code:
109
+ 0mq API v3.2-4 server code:
87
110
 
88
111
  require 'rubygems'
89
112
  require 'ffi-rzmq'
90
113
 
91
114
  if ARGV.length < 3
92
- puts "usage: remote_lat <connect-to> <message-size> <roundtrip-count>"
115
+ puts "usage: ruby remote_lat.rb <connect-to> <message-size> <roundtrip-count>"
93
116
  exit
94
117
  end
95
-
118
+
119
+ def assert(rc)
120
+ raise "Last API call failed at #{caller(1)}" unless rc >= 0
121
+ end
122
+
96
123
  connect_to = ARGV[0]
97
124
  message_size = ARGV[1].to_i
98
125
  roundtrip_count = ARGV[2].to_i
99
126
 
100
127
  ctx = ZMQ::Context.new
101
- s = ctx.socket ZMQ::REQ
102
- rc = s.connect(connect_to)
128
+ s = ctx.socket ZMQ::REQ
129
+ rc = s.connect(connect_to)
103
130
 
104
131
  msg = "#{ '3' * message_size }"
105
132
 
106
- start_time = Time.now
133
+ time_start = Time.now
107
134
 
108
- msg = ""
109
135
  roundtrip_count.times do
110
- rc = s.send_string msg, 0
111
- rc = s.recv_string msg
136
+ assert(s.send_string(msg, 0))
137
+
138
+ msg = ''
139
+ assert(s.recv_string(msg, 0))
140
+
112
141
  raise "Message size doesn't match, expected [#{message_size}] but received [#{msg.size}]" if message_size != msg.size
113
142
  end
114
143
 
144
+ time_end = Time.now
145
+ puts "Time #{( time_end - time_start )}"
146
+
115
147
  == Better Examples
116
148
 
117
149
  I highly recommend visiting the Learn Ruby 0mq project for a bunch of good code examples.
@@ -139,7 +171,7 @@ It will crash randomly and you will be sad.
139
171
 
140
172
  == INSTALL:
141
173
 
142
- Make sure the ZeroMQ library is already installed on your system.
174
+ Make sure the ZeroMQ library is already installed on your system. We recommend 'brew' or 'macports' to get it.
143
175
 
144
176
  % gem install ffi-rzmq # should grab the latest release
145
177
 
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
@@ -66,6 +66,6 @@ end # module ZMQ
66
66
  require 'ffi-rzmq-core'
67
67
 
68
68
  # the order of files is important
69
- %w(util exceptions context message socket poll_items poll_item poll device).each do |file|
69
+ %w(util exceptions context message socket poll_items poll_item poll device version).each do |file|
70
70
  require ZMQ.libpath(['ffi-rzmq', file])
71
71
  end
@@ -1,3 +1,3 @@
1
1
  module ZMQ
2
- VERSION = "2.0.1"
2
+ VERSION = "2.0.4"
3
3
  end
@@ -11,31 +11,31 @@ module ZMQ
11
11
  include APIHelper
12
12
 
13
13
  it "should return nil for negative io threads" do
14
- Context.create(-1).should be_nil
14
+ expect(Context.create(-1)).to eq(nil)
15
15
  end
16
16
 
17
17
  it "should default to requesting 1 i/o thread when no argument is passed" do
18
18
  ctx = Context.create
19
- ctx.io_threads.should == 1
19
+ expect(ctx.io_threads).to eq(1)
20
20
  end
21
21
 
22
22
  it "should set the :pointer accessor to non-nil" do
23
23
  ctx = Context.create
24
- ctx.pointer.should_not be_nil
24
+ expect(ctx.pointer).not_to be_nil
25
25
  end
26
26
 
27
27
  it "should set the :context accessor to non-nil" do
28
28
  ctx = Context.create
29
- ctx.context.should_not be_nil
29
+ expect(ctx.context).not_to be_nil
30
30
  end
31
31
 
32
32
  it "should set the :pointer and :context accessors to the same value" do
33
33
  ctx = Context.create
34
- ctx.pointer.should == ctx.context
34
+ expect(ctx.pointer).to eq(ctx.context)
35
35
  end
36
36
 
37
37
  it "should define a finalizer on this object" do
38
- ObjectSpace.should_receive(:define_finalizer)
38
+ expect(ObjectSpace).to receive(:define_finalizer)
39
39
  ctx = Context.create
40
40
  end
41
41
  end # context initializing
@@ -45,31 +45,31 @@ module ZMQ
45
45
  include APIHelper
46
46
 
47
47
  it "should raise a ContextError exception for negative io threads" do
48
- lambda { Context.new(-1) }.should raise_exception(ZMQ::ContextError)
48
+ expect { Context.new(-1) }.to raise_exception(ZMQ::ContextError)
49
49
  end
50
50
 
51
51
  it "should default to requesting 1 i/o thread when no argument is passed" do
52
52
  ctx = Context.new
53
- ctx.io_threads.should == 1
53
+ expect(ctx.io_threads).to eq(1)
54
54
  end
55
55
 
56
56
  it "should set the :pointer accessor to non-nil" do
57
57
  ctx = Context.new
58
- ctx.pointer.should_not be_nil
58
+ expect(ctx.pointer).not_to be_nil
59
59
  end
60
60
 
61
61
  it "should set the :context accessor to non-nil" do
62
62
  ctx = Context.new
63
- ctx.context.should_not be_nil
63
+ expect(ctx.context).not_to be_nil
64
64
  end
65
65
 
66
66
  it "should set the :pointer and :context accessors to the same value" do
67
67
  ctx = Context.new
68
- ctx.pointer.should == ctx.context
68
+ expect(ctx.pointer).to eq(ctx.context)
69
69
  end
70
70
 
71
71
  it "should define a finalizer on this object" do
72
- ObjectSpace.should_receive(:define_finalizer)
72
+ expect(ObjectSpace).to receive(:define_finalizer)
73
73
  Context.new 1
74
74
  end
75
75
  end # context initializing
@@ -79,13 +79,13 @@ module ZMQ
79
79
  it "should set the context to nil when terminating the library's context" do
80
80
  ctx = Context.new # can't use a shared context here because we are terminating it!
81
81
  ctx.terminate
82
- ctx.pointer.should be_nil
82
+ expect(ctx.pointer).to be_nil
83
83
  end
84
84
 
85
85
  it "should call the correct library function to terminate the context" do
86
86
  ctx = Context.new
87
87
 
88
- LibZMQ.should_receive(:zmq_ctx_destroy).with(ctx.pointer).and_return(0)
88
+ expect(LibZMQ).to receive(:zmq_ctx_destroy).with(ctx.pointer).and_return(0)
89
89
  ctx.terminate
90
90
  end
91
91
  end # context terminate
@@ -94,8 +94,8 @@ module ZMQ
94
94
  context "when allocating a socket" do
95
95
  it "should return nil when allocation fails" do
96
96
  ctx = Context.new
97
- LibZMQ.stub(:zmq_socket => nil)
98
- ctx.socket(ZMQ::REQ).should be_nil
97
+ allow(LibZMQ).to receive(:zmq_socket).and_return(nil)
98
+ expect(ctx.socket(ZMQ::REQ)).to be_nil
99
99
  end
100
100
  end # context socket
101
101
 
@@ -63,16 +63,16 @@ module ZMQ
63
63
 
64
64
  res = ''
65
65
  rc = puller.recv_string(res, ZMQ::DONTWAIT)
66
- res.should == "hello"
66
+ expect(res).to eq("hello")
67
67
 
68
68
  pusher.close
69
69
  puller.close
70
70
  end
71
71
 
72
72
  it "should raise an ArgumentError when trying to pass non-socket objects into the device" do
73
- lambda {
73
+ expect {
74
74
  Device.new(1,2)
75
- }.should raise_exception(ArgumentError)
75
+ }.to raise_exception(ArgumentError)
76
76
  end
77
77
  end
78
78
  end
@@ -9,12 +9,12 @@ module ZMQ
9
9
  context "when initializing with an argument" do
10
10
 
11
11
  it "calls zmq_msg_init_data()" do
12
- LibZMQ.should_receive(:zmq_msg_init_data)
12
+ expect(LibZMQ).to receive(:zmq_msg_init_data)
13
13
  message = Message.new "text"
14
14
  end
15
15
 
16
16
  it "should *not* define a finalizer on this object" do
17
- ObjectSpace.should_not_receive(:define_finalizer)
17
+ expect(ObjectSpace).not_to receive(:define_finalizer)
18
18
  Message.new "text"
19
19
  end
20
20
  end # context initializing with arg
@@ -22,12 +22,12 @@ module ZMQ
22
22
  context "when initializing *without* an argument" do
23
23
 
24
24
  it "calls zmq_msg_init()" do
25
- LibZMQ.should_receive(:zmq_msg_init).and_return(0)
25
+ expect(LibZMQ).to receive(:zmq_msg_init).and_return(0)
26
26
  message = Message.new
27
27
  end
28
28
 
29
29
  it "should *not* define a finalizer on this object" do
30
- ObjectSpace.should_not_receive(:define_finalizer)
30
+ expect(ObjectSpace).not_to receive(:define_finalizer)
31
31
  Message.new "text"
32
32
  end
33
33
  end # context initializing with arg
@@ -37,14 +37,14 @@ module ZMQ
37
37
  it "calls zmq_msg_init_data()" do
38
38
  message = Message.new "text"
39
39
 
40
- LibZMQ.should_receive(:zmq_msg_init_data)
40
+ expect(LibZMQ).to receive(:zmq_msg_init_data)
41
41
  message.copy_in_string("new text")
42
42
  end
43
43
 
44
44
  it "correctly finds the length of binary data by ignoring encoding" do
45
45
  message = Message.new
46
46
  message.copy_in_string("\x83\x6e\x04\x00\x00\x44\xd1\x81")
47
- message.size.should == 8
47
+ expect(message.size).to eq(8)
48
48
  end
49
49
  end
50
50
 
@@ -54,7 +54,7 @@ module ZMQ
54
54
  message = Message.new "text"
55
55
  copy = Message.new
56
56
 
57
- LibZMQ.should_receive(:zmq_msg_copy)
57
+ expect(LibZMQ).to receive(:zmq_msg_copy)
58
58
  copy.copy(message)
59
59
  end
60
60
  end # context copy
@@ -65,7 +65,7 @@ module ZMQ
65
65
  message = Message.new "text"
66
66
  copy = Message.new
67
67
 
68
- LibZMQ.should_receive(:zmq_msg_move)
68
+ expect(LibZMQ).to receive(:zmq_msg_move)
69
69
  copy.move(message)
70
70
  end
71
71
  end # context move
@@ -75,7 +75,7 @@ module ZMQ
75
75
  it "calls zmq_msg_size()" do
76
76
  message = Message.new "text"
77
77
 
78
- LibZMQ.should_receive(:zmq_msg_size)
78
+ expect(LibZMQ).to receive(:zmq_msg_size)
79
79
  message.size
80
80
  end
81
81
  end # context size
@@ -85,7 +85,7 @@ module ZMQ
85
85
  it "calls zmq_msg_data()" do
86
86
  message = Message.new "text"
87
87
 
88
- LibZMQ.should_receive(:zmq_msg_data)
88
+ expect(LibZMQ).to receive(:zmq_msg_data)
89
89
  message.data
90
90
  end
91
91
  end # context data
@@ -95,7 +95,7 @@ module ZMQ
95
95
  it "calls zmq_msg_close() the first time" do
96
96
  message = Message.new "text"
97
97
 
98
- LibZMQ.should_receive(:zmq_msg_close)
98
+ expect(LibZMQ).to receive(:zmq_msg_close)
99
99
  message.close
100
100
  end
101
101
 
@@ -103,7 +103,7 @@ module ZMQ
103
103
  message = Message.new "text"
104
104
  message.close
105
105
 
106
- LibZMQ.should_not_receive(:zmq_msg_close)
106
+ expect(LibZMQ).not_to receive(:zmq_msg_close)
107
107
  message.close
108
108
  end
109
109
  end # context close
@@ -116,7 +116,7 @@ module ZMQ
116
116
  context "when initializing with an argument" do
117
117
 
118
118
  it "should define a finalizer on this object" do
119
- ObjectSpace.should_receive(:define_finalizer)
119
+ expect(ObjectSpace).to receive(:define_finalizer)
120
120
  ManagedMessage.new "text"
121
121
  end
122
122
  end # context initializing