miu 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/lib/miu/socket.rb CHANGED
@@ -22,11 +22,15 @@ module Miu
22
22
  end
23
23
 
24
24
  def bind
25
- @socket.bind "tcp://#{@host}:#{@port}"
25
+ rc = @socket.bind "tcp://#{@host}:#{@port}"
26
+ error_check rc
27
+ self
26
28
  end
27
29
 
28
30
  def connect
29
- @socket.connect "tcp://#{@host}:#{@port}"
31
+ rc = @socket.connect "tcp://#{@host}:#{@port}"
32
+ error_check rc
33
+ self
30
34
  end
31
35
 
32
36
  def forward(forwarder)
@@ -43,5 +47,14 @@ module Miu
43
47
  @socket.close
44
48
  @context.terminate if @terminate_context
45
49
  end
50
+
51
+ protected
52
+
53
+ def error_check(rc, source = nil)
54
+ unless ZMQ::Util.resultcode_ok? rc
55
+ raise ZMQ::ZeroMQError.new source, rc, ZMQ::Util.errno, ZMQ::Util.error_string
56
+ end
57
+ true
58
+ end
46
59
  end
47
60
  end
@@ -9,17 +9,26 @@ module Miu
9
9
  options[:port] ||= Miu.default_pub_port
10
10
  super socket_type, options
11
11
 
12
- self.subscribe = options[:subscribe]
12
+ subscribe options[:subscribe] || ''
13
13
  yield self if block_given?
14
14
  end
15
15
 
16
- def subscribe
17
- @subscribe
16
+ def subscribe(value = nil)
17
+ if value
18
+ unsubscribe if @subscribe
19
+ @subscribe = value.to_s
20
+ @socket.setsockopt ZMQ::SUBSCRIBE, @subscribe
21
+ else
22
+ @subscribe
23
+ end
18
24
  end
19
25
 
20
- def subscribe=(value)
21
- @subscribe = value.to_s
22
- @socket.setsockopt ZMQ::SUBSCRIBE, @subscribe
26
+ def unsubscribe
27
+ if @subscribe
28
+ @socket.setsockopt ZMQ::UNSUBSCRIBE, @subscribe
29
+ @subscribe = nil
30
+ end
31
+ nil
23
32
  end
24
33
 
25
34
  def recv
data/lib/miu/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Miu
2
- VERSION = '0.0.5'
2
+ VERSION = '0.0.6'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: miu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -134,7 +134,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
134
134
  version: '0'
135
135
  segments:
136
136
  - 0
137
- hash: -2326395156696171372
137
+ hash: -3968051150084221078
138
138
  required_rubygems_version: !ruby/object:Gem::Requirement
139
139
  none: false
140
140
  requirements:
@@ -143,7 +143,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
143
143
  version: '0'
144
144
  segments:
145
145
  - 0
146
- hash: -2326395156696171372
146
+ hash: -3968051150084221078
147
147
  requirements: []
148
148
  rubyforge_project:
149
149
  rubygems_version: 1.8.24