em-zeromq 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,19 +1,48 @@
1
1
  # em-zeromq #
2
2
 
3
+ ## Current maintainer ##
4
+
5
+ This gem is currently maintained by schmurfy, it will stay here for now
6
+ but may be moved to my account later.
7
+
3
8
  ## Description: ##
4
9
 
5
10
  EventMachine support for ZeroMQ
6
11
 
7
12
  ## Usage: ##
8
13
 
9
- Tested and functional with Rubinius, jRuby, and 1.9.2.
14
+ Supported on:
15
+ - MRI 1.9+
16
+ - Rubinius
17
+ - JRuby
10
18
 
11
- If using 1.9.2 you must `gem install ffi` before using.
12
-
13
- MRI 1.8.7 does not work with libzmq.
19
+ While the gem should work on Rubinius and JRuby I mainly use it with MRI 1.9+ so
20
+ there may be some glitchs.
14
21
 
15
22
  Want to help out? Ask!
16
23
 
24
+ ## Usage Warning ##
25
+
26
+ To ensure your zeromq context won't be reclaimed by the garbage collector you need
27
+ to keep a reference to it in scope, this is what you don't want to do (that's how the example used to be written):
28
+
29
+ ```ruby
30
+ EM.run do
31
+ context = EM::ZeroMQ::Context.new(1)
32
+ dealer_socket = context.connect(...)
33
+ dealer_socket.send_msg('', "ping")
34
+ end
35
+ ```
36
+
37
+ If you do this everything will appear to work fine at first but as soon as the garbage collector
38
+ is triggered your context will get destroyed and your application will hang.
39
+
40
+ The same may be true for references to socket but I have no evidence of that.
41
+ It should not be a major problem anyway since code like above is only written for examples/tests
42
+ but I just pulled my hair trying to figure out why my test code was not working so now you
43
+ have been warned !
44
+
45
+
17
46
  ## Example ##
18
47
  ```ruby
19
48
  require 'rubygems'
@@ -30,9 +59,9 @@ class EMTestPullHandler
30
59
  end
31
60
  end
32
61
 
62
+
63
+ ctx = EM::ZeroMQ::Context.new(1)
33
64
  EM.run do
34
- ctx = EM::ZeroMQ::Context.new(1)
35
-
36
65
  # setup push sockets
37
66
  push_socket1 = ctx.bind( ZMQ::PUSH, 'tcp://127.0.0.1:2091')
38
67
  push_socket2 = ctx.bind( ZMQ::PUSH, 'ipc:///tmp/a')
data/em-zeromq.gemspec CHANGED
@@ -6,8 +6,8 @@ Gem::Specification.new do |s|
6
6
  s.name = "em-zeromq"
7
7
  s.version = EmZeromq::VERSION
8
8
  s.platform = Gem::Platform::RUBY
9
- s.authors = ["Andrew Cholakian"]
10
- s.email = ["andrew@andrewvc.com"]
9
+ s.authors = ["Andrew Cholakian", "Julien Ammous"]
10
+ s.email = ["schmurfy@gmail.com"]
11
11
  s.homepage = "https://github.com/andrewvc/em-zeromq"
12
12
  s.summary = %q{Low level event machine support for ZeroMQ}
13
13
  s.description = %q{Low level event machine support for ZeroMQ}
@@ -15,9 +15,9 @@ Gem::Specification.new do |s|
15
15
 
16
16
  s.rubyforge_project = "em-zeromq"
17
17
 
18
- s.add_dependency 'eventmachine', '>= 1.0.0.beta.4'
18
+ s.add_dependency 'eventmachine', '1.0.0.beta.4'
19
19
  s.add_dependency 'ffi', '>= 1.0.0'
20
- s.add_dependency 'ffi-rzmq', '~> 0.9.0'
20
+ s.add_dependency 'ffi-rzmq', '0.9.3'
21
21
 
22
22
  s.add_development_dependency 'rspec', '>= 2.5.0'
23
23
  s.add_development_dependency 'rake'
data/example/simple.rb CHANGED
@@ -19,9 +19,9 @@ end
19
19
 
20
20
  puts "Started (with zmq #{ZMQ::Util.version.join('.')})."
21
21
 
22
+
23
+ ctx = EM::ZeroMQ::Context.new(1)
22
24
  EM.run do
23
- ctx = EM::ZeroMQ::Context.new(1)
24
-
25
25
  # setup push sockets
26
26
  push_socket1 = ctx.bind( ZMQ::PUSH, 'tcp://127.0.0.1:2091')
27
27
  push_socket2 = ctx.bind( ZMQ::PUSH, 'ipc:///tmp/a')
@@ -12,7 +12,7 @@ module EventMachine
12
12
  end
13
13
 
14
14
  def self.map_sockopt(opt, name)
15
- define_method(name){ @socket.getsockopt(opt) }
15
+ define_method(name){ getsockopt(opt) }
16
16
  define_method("#{name}="){|val| @socket.setsockopt(opt, val) }
17
17
  end
18
18
 
@@ -68,13 +68,30 @@ module EventMachine
68
68
  if sent
69
69
  # all the previous parts were queued, send
70
70
  # the last one
71
- @socket.send_string(parts[-1], ZMQ::NOBLOCK)
71
+ ret = @socket.send_string(parts[-1], ZMQ::NOBLOCK)
72
+ if ret < 0
73
+ raise "Unable to send message: #{ZMQ::Util.error_string}"
74
+ end
72
75
  else
73
76
  # error while sending the previous parts
74
77
  # register the socket for writability
75
78
  self.notify_writable = true
76
- false
79
+ sent = false
77
80
  end
81
+
82
+ notify_readable()
83
+
84
+ sent
85
+ end
86
+
87
+ def getsockopt(opt)
88
+ ret = []
89
+ rc = @socket.getsockopt(opt, ret)
90
+ unless ZMQ::Util.resultcode_ok?(rc)
91
+ raise ZMQOperationFailed, "getsockopt: #{ZMQ::Util.error_string}"
92
+ end
93
+
94
+ (ret.size == 1) ? ret[0] : ret
78
95
  end
79
96
 
80
97
  def setsockopt(opt, value)
@@ -143,13 +160,13 @@ module EventMachine
143
160
  end
144
161
  end
145
162
  def readable?
146
- (@socket.getsockopt(ZMQ::EVENTS) & ZMQ::POLLIN) == ZMQ::POLLIN
163
+ (getsockopt(ZMQ::EVENTS) & ZMQ::POLLIN) == ZMQ::POLLIN
147
164
  end
148
165
 
149
166
  def writable?
150
167
  return true
151
168
  # ZMQ::EVENTS has issues in ZMQ HEAD, we'll ignore this till they're fixed
152
- # (@socket.getsockopt(ZMQ::EVENTS) & ZMQ::POLLOUT) == ZMQ::POLLOUT
169
+ # (getsockopt(ZMQ::EVENTS) & ZMQ::POLLOUT) == ZMQ::POLLOUT
153
170
  end
154
171
 
155
172
  private
@@ -45,8 +45,12 @@ module EventMachine
45
45
  socket.connect(address)
46
46
  end
47
47
 
48
- fd = socket.getsockopt(ZMQ::FD)
49
- conn = EM.watch(fd, EventMachine::ZeroMQ::Connection, socket, socket_type, address, handler)
48
+ fd = []
49
+ if socket.getsockopt(ZMQ::FD, fd) < 0
50
+ raise "Unable to get socket FD: #{ZMQ::Util.error_string}"
51
+ end
52
+
53
+ conn = EM.watch(fd[0], EventMachine::ZeroMQ::Connection, socket, socket_type, address, handler)
50
54
 
51
55
  if READABLES.include?(socket_type)
52
56
  conn.register_readable
@@ -4,39 +4,13 @@ module RZMQCompat
4
4
 
5
5
  def self.included(klass)
6
6
  klass.instance_eval do
7
- %w(getsockopt recv).each do |m|
7
+ %w(recv).each do |m|
8
8
  alias_method :"#{m}_without_raise", m.to_sym
9
9
  alias_method m.to_sym, :"#{m}_with_raise"
10
10
  end
11
11
  end
12
12
  end
13
13
 
14
- def getsockopt_with_raise(opt, *args)
15
- arity = method(:getsockopt_without_raise).arity
16
- if args.empty?
17
- case arity
18
- when 1
19
- getsockopt_without_raise(opt)
20
-
21
- when 2
22
- ret = []
23
- rc = getsockopt_without_raise(opt, ret)
24
- unless ZMQ::Util.resultcode_ok?(rc)
25
- raise ZMQOperationFailed, "getsockopt: #{ZMQ.errno}"
26
- end
27
-
28
- (ret.size == 1) ? ret[0] : ret
29
-
30
- else
31
- raise "Unsupported version of ffi-rzmq, getsockopt takes #{arity} arguments"
32
- end
33
-
34
- else
35
- # just pass the call to the original method
36
- getsockopt_without_raise(opt, *args)
37
- end
38
- end
39
-
40
14
  def recv_with_raise(msg, flags = 0)
41
15
  ret = recv_without_raise(msg, flags)
42
16
  if (ret == true) || (ret == 0)
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module EmZeromq
3
- VERSION = "0.2.2"
3
+ VERSION = "0.2.3"
4
4
  end
@@ -23,11 +23,10 @@ describe EventMachine::ZeroMQ do
23
23
  @on_writable_callback.call(socket) if @on_writable_callback
24
24
  end
25
25
  def on_readable(socket, messages)
26
- ident, delim, message = messages.map(&:copy_out_string)
27
- ident.should == "dealer1"
28
- @received += [ident, delim, message].map {|s| ZMQ::Message.new(s)}
26
+ _, message = messages.map(&:copy_out_string)
27
+ @received += [message].map {|s| ZMQ::Message.new(s)}
29
28
 
30
- socket.send_msg(ident, delim, "re:#{message}")
29
+ socket.send_msg('', "re:#{message}")
31
30
  end
32
31
  end
33
32
 
@@ -44,16 +43,19 @@ describe EventMachine::ZeroMQ do
44
43
  results = {}
45
44
  @test_message = test_message = "M#{rand(999)}"
46
45
 
47
- run_reactor(0.5) do
46
+ run_reactor(2) do
48
47
  results[:dealer_hndlr] = dealer_hndlr = EMTestDealerHandler.new
49
48
  results[:router_hndlr] = router_hndlr = EMTestRouterHandler.new
50
49
 
51
50
  addr = rand_addr
52
51
  dealer_conn = SPEC_CTX.bind(ZMQ::DEALER, addr, dealer_hndlr, :identity => "dealer1")
53
52
  router_conn = SPEC_CTX.connect(ZMQ::ROUTER, addr, router_hndlr, :identity => "router1")
54
- router_conn.send_msg('x', test_message)
53
+
54
+ EM::add_timer(0.1) do
55
+ router_conn.send_msg('dealer1','', test_message)
56
+ end
55
57
 
56
- EM::Timer.new(0.1) do
58
+ EM::Timer.new(0.2) do
57
59
  results[:specs_ran] = true
58
60
  end
59
61
  end
metadata CHANGED
@@ -1,30 +1,31 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: em-zeromq
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Andrew Cholakian
9
+ - Julien Ammous
9
10
  autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
- date: 2011-11-27 00:00:00.000000000 Z
13
+ date: 2012-02-23 00:00:00.000000000 Z
13
14
  dependencies:
14
15
  - !ruby/object:Gem::Dependency
15
16
  name: eventmachine
16
- requirement: &7728660 !ruby/object:Gem::Requirement
17
+ requirement: &70154900691620 !ruby/object:Gem::Requirement
17
18
  none: false
18
19
  requirements:
19
- - - ! '>='
20
+ - - =
20
21
  - !ruby/object:Gem::Version
21
22
  version: 1.0.0.beta.4
22
23
  type: :runtime
23
24
  prerelease: false
24
- version_requirements: *7728660
25
+ version_requirements: *70154900691620
25
26
  - !ruby/object:Gem::Dependency
26
27
  name: ffi
27
- requirement: &7728080 !ruby/object:Gem::Requirement
28
+ requirement: &70154900707520 !ruby/object:Gem::Requirement
28
29
  none: false
29
30
  requirements:
30
31
  - - ! '>='
@@ -32,21 +33,21 @@ dependencies:
32
33
  version: 1.0.0
33
34
  type: :runtime
34
35
  prerelease: false
35
- version_requirements: *7728080
36
+ version_requirements: *70154900707520
36
37
  - !ruby/object:Gem::Dependency
37
38
  name: ffi-rzmq
38
- requirement: &7727520 !ruby/object:Gem::Requirement
39
+ requirement: &70154900707060 !ruby/object:Gem::Requirement
39
40
  none: false
40
41
  requirements:
41
- - - ~>
42
+ - - =
42
43
  - !ruby/object:Gem::Version
43
- version: 0.9.0
44
+ version: 0.9.3
44
45
  type: :runtime
45
46
  prerelease: false
46
- version_requirements: *7727520
47
+ version_requirements: *70154900707060
47
48
  - !ruby/object:Gem::Dependency
48
49
  name: rspec
49
- requirement: &7726580 !ruby/object:Gem::Requirement
50
+ requirement: &70154900706600 !ruby/object:Gem::Requirement
50
51
  none: false
51
52
  requirements:
52
53
  - - ! '>='
@@ -54,10 +55,10 @@ dependencies:
54
55
  version: 2.5.0
55
56
  type: :development
56
57
  prerelease: false
57
- version_requirements: *7726580
58
+ version_requirements: *70154900706600
58
59
  - !ruby/object:Gem::Dependency
59
60
  name: rake
60
- requirement: &7725760 !ruby/object:Gem::Requirement
61
+ requirement: &70154900706220 !ruby/object:Gem::Requirement
61
62
  none: false
62
63
  requirements:
63
64
  - - ! '>='
@@ -65,10 +66,10 @@ dependencies:
65
66
  version: '0'
66
67
  type: :development
67
68
  prerelease: false
68
- version_requirements: *7725760
69
+ version_requirements: *70154900706220
69
70
  description: Low level event machine support for ZeroMQ
70
71
  email:
71
- - andrew@andrewvc.com
72
+ - schmurfy@gmail.com
72
73
  executables: []
73
74
  extensions: []
74
75
  extra_rdoc_files: []
@@ -105,16 +106,27 @@ required_ruby_version: !ruby/object:Gem::Requirement
105
106
  - - ! '>='
106
107
  - !ruby/object:Gem::Version
107
108
  version: '0'
109
+ segments:
110
+ - 0
111
+ hash: -3798582032913593030
108
112
  required_rubygems_version: !ruby/object:Gem::Requirement
109
113
  none: false
110
114
  requirements:
111
115
  - - ! '>='
112
116
  - !ruby/object:Gem::Version
113
117
  version: '0'
118
+ segments:
119
+ - 0
120
+ hash: -3798582032913593030
114
121
  requirements: []
115
122
  rubyforge_project: em-zeromq
116
- rubygems_version: 1.8.10
123
+ rubygems_version: 1.8.15
117
124
  signing_key:
118
125
  specification_version: 3
119
126
  summary: Low level event machine support for ZeroMQ
120
- test_files: []
127
+ test_files:
128
+ - spec/context_spec.rb
129
+ - spec/pub_sub_spec.rb
130
+ - spec/push_pull_spec.rb
131
+ - spec/router_dealer_spec.rb
132
+ - spec/spec_helper.rb