0mq 0.5.2 → 0.5.3

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
- ---
2
- SHA1:
3
- metadata.gz: 136e40f0d38d2aa86916cc8134140819f3b6153d
4
- data.tar.gz: b9dc4d0d931e3069dcd6f72705d23276e5b96fd5
5
- SHA512:
6
- metadata.gz: 6e78f5d97aac700192c295c5c246e310154c1a259d7f9e478552bcadf62daec60aee60994c8bba0cd8430fd872a7cd6f8de9bd73f577d7058fe0557b67198069
7
- data.tar.gz: fedd23a1ff754f4e94da1388990633dea10b1b87b48951189093d3b801e5d4d24dfd6ce051c7330a10d1e77f4b536099fc87048ff3b01a4d3fe1cbf3ba3ef3d0
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4b23969552a6f935b9713b5be875a4dcb856ad06
4
+ data.tar.gz: 162abab4d33dfdbff296b777f8d20293a1ea1c14
5
+ SHA512:
6
+ metadata.gz: 80b4fa45c4a4a7df01aaca3bdc9bc2326f9ea1556ca3208fe554e4448df1df080c2e643c5b36a2d8a714aeb6ea4eaef01f0763582e7f8d5380f3043df01e843b
7
+ data.tar.gz: b4a71aaaa6c2e2120e4811ea4d1499a1e1d5329b47297f6287654ac0418774eaed38a6915e89726d35a0138d1d16b2457d1adf6e2b84501ec15aa18cdf4cd125
@@ -1,6 +1,33 @@
1
1
 
2
2
  module ZMQ
3
3
 
4
+ # "Native 0MQ error codes"
5
+ # Each is defined in zmq.h and is not a standard errno code
6
+ # Description for each error code is paraphrased from the zmq man pages
7
+ {
8
+ :EFSM => "Finite state machine is in the wrong state",
9
+ :ENOCOMPATPROTO => "The requested protocol is not compatible",
10
+ :ETERM => "The context was terminated",
11
+ :EMTHREAD => "No I/O thread is available to accomplish the task",
12
+ }.each do |name, message|
13
+ klass = Class.new SystemCallError do
14
+ define_singleton_method :exception do |*args|
15
+ superclass.superclass.singleton_class
16
+ .instance_method(:new).bind(self).call(*args).tap { |exc|
17
+ exc.define_singleton_method(:message) { message }
18
+ exc.define_singleton_method(:to_s) { message }
19
+ exc.define_singleton_method(:inspect) {
20
+ "#<Errno::#{name}: #{message}>"
21
+ }
22
+ }
23
+ end
24
+ end
25
+
26
+ klass.const_set :Errno, ZMQ.const_get(name)
27
+ Errno.const_set name, klass
28
+ end
29
+
30
+
4
31
  # A hash of error number => exception class.
5
32
  # Example: 1 => Errno::EPERM
6
33
  @error_map = Hash.new
@@ -16,7 +43,6 @@ module ZMQ
16
43
  # Example: ZMQ.error_check if rc == -1
17
44
  def self.error_check(adjust_backtrace=false)
18
45
  errno = LibZMQ.zmq_errno
19
- return true if errno == 25 # TODO: What is this for? Remove?
20
46
 
21
47
  backtrace = adjust_backtrace ? caller[0...-2] : caller
22
48
  if @error_map.has_key? errno
@@ -26,4 +52,4 @@ module ZMQ
26
52
  end
27
53
  end
28
54
 
29
- end
55
+ end
@@ -8,14 +8,21 @@ module ZMQ
8
8
  # Note that either #kill or #close MUST be called when done with the object.
9
9
  # There is no automatic finalizer for this object.
10
10
  def initialize(*sockets)
11
- @int_sock_rep = ZMQ::Socket.new ZMQ::REP
12
- @int_sock_req = ZMQ::Socket.new ZMQ::REQ
11
+ @int_sock_rep = ZMQ::Socket.new ZMQ::REP
12
+ @int_sock_req = ZMQ::Socket.new ZMQ::REQ
13
+ @int_sock_push = ZMQ::Socket.new ZMQ::PUSH
14
+ @int_sock_pull = ZMQ::Socket.new ZMQ::PULL
13
15
 
14
16
  # Choose an endpoint name that we can expect to be unique
15
17
  # so that they can be shared within the DefaultContext
16
18
  int_endpoint = "inproc://__PollInterruptible_int_"+hash.to_s(26)
17
- @int_sock_rep.bind int_endpoint
18
- @int_sock_req.connect int_endpoint
19
+
20
+ @int_sock_rep.bind int_endpoint+'R'
21
+ @int_sock_req.connect int_endpoint+'R'
22
+ @int_lock_req = Mutex.new
23
+ @int_sock_pull.bind int_endpoint+'P'
24
+ @int_sock_push.connect int_endpoint+'P'
25
+ @int_lock_push = Mutex.new
19
26
 
20
27
  # Interruption blocks are stored here by key until #run receives them.
21
28
  # After each is run, the return value is stored here in its place.
@@ -23,7 +30,7 @@ module ZMQ
23
30
 
24
31
  @dead = false
25
32
 
26
- super @int_sock_rep, *sockets
33
+ super @int_sock_rep, @int_sock_pull, *sockets
27
34
  end
28
35
 
29
36
  # Same as Poll#run, but will yield [nil, nil] to the block if interrupted.
@@ -32,26 +39,35 @@ module ZMQ
32
39
  raise "#{self} cannot run; it was permanently killed." if @dead
33
40
 
34
41
  super do |socket, revents|
35
- if socket == @int_sock_rep
42
+ if socket == @int_sock_rep || socket == @int_sock_pull
36
43
  key, * = socket.recv_array
37
44
  kill = key == "KILL"
45
+ blocking = socket == @int_sock_rep
38
46
 
39
47
  # Call the user block of #interrupt and store the return value
40
- @interruptions[key] = @interruptions[key].call unless kill
48
+ unless kill
49
+ result = @interruptions[key].call
50
+ blocking ? @interruptions[key] = result : @interruptions.delete(key)
51
+ end
41
52
 
42
53
  # Call the user block of #run
43
54
  block.call nil, nil if block
44
55
 
45
- socket.send_array ["OKAY"]
56
+ # Send a response if the interruption was blocking
57
+ socket.send_array ["OKAY"] if blocking
46
58
 
47
59
  if kill
48
60
  @int_sock_rep.close
61
+ @int_sock_pull.close
49
62
  @dead = true
50
63
  end
51
64
  else
52
65
  block.call socket, revents if block
53
66
  end
54
- end.tap { |hash| hash.delete @int_sock_rep }
67
+ end.tap do |hash|
68
+ hash.delete @int_sock_rep
69
+ hash.delete @int_sock_pull
70
+ end
55
71
  end
56
72
 
57
73
  # Interrupt the running poll loop, but do not clean up.
@@ -60,16 +76,28 @@ module ZMQ
60
76
  # and only if the poll thread is running
61
77
  # If a block is given, it will be executed in the poll thread just
62
78
  # prior to the execution of the user block passed to {#run}.
63
- def interrupt(&block)
79
+ # If the blocking: false option is is given, the call will not wait for
80
+ # the interruption to be processed.
81
+ def interrupt(opts={}, &block)
82
+ blocking = opts.fetch :blocking, true
64
83
  block ||= Proc.new { true }
84
+ # block = block.dup
65
85
  key = block.object_id.to_s 36
66
86
 
67
87
  @interruptions[key] = block # Store the block to be called
68
88
 
69
- @int_sock_req.send_string key # Signal an interruption to #run
70
- @int_sock_req.recv_array # Wait until it has been handled by #run
71
-
72
- @interruptions.delete key # Return the stored result of the block
89
+ if blocking
90
+ @int_lock_req.synchronize {
91
+ @int_sock_req.send_string key # Signal an interruption to #run
92
+ @int_sock_req.recv_array # Wait until it has been handled by #run
93
+ }
94
+ return @interruptions.delete key # Return the stored result of the block
95
+ else
96
+ @int_lock_push.synchronize {
97
+ @int_sock_push.send_string key # Signal an interruption to #run
98
+ }
99
+ return nil
100
+ end
73
101
  end
74
102
 
75
103
  # Interrupt the running poll loop and permanently kill the Poll object
@@ -80,10 +108,13 @@ module ZMQ
80
108
  def kill
81
109
  return nil if @dead
82
110
 
83
- @int_sock_req.send_array ["KILL"]
84
- @int_sock_req.recv_array
111
+ @int_lock_req.synchronize do
112
+ @int_sock_req.send_array ["KILL"]
113
+ @int_sock_req.recv_array
114
+ end
85
115
 
86
116
  @int_sock_req.close
117
+ @int_sock_push.close
87
118
 
88
119
  true
89
120
  end
@@ -97,6 +128,8 @@ module ZMQ
97
128
 
98
129
  @int_sock_rep.close
99
130
  @int_sock_req.close
131
+ @int_sock_pull.close
132
+ @int_sock_push.close
100
133
 
101
134
  @dead = true
102
135
  end
metadata CHANGED
@@ -1,134 +1,116 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: 0mq
3
- version: !ruby/object:Gem::Version
4
- version: 0.5.2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.3
5
5
  platform: ruby
6
- authors:
6
+ authors:
7
7
  - Joe McIlvain
8
8
  - Alex McLain
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-06-11 00:00:00.000000000 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
12
+
13
+ date: 2014-06-28 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
15
16
  name: ffi-rzmq-core
16
- requirement: !ruby/object:Gem::Requirement
17
- requirements:
18
- - - "~>"
19
- - !ruby/object:Gem::Version
20
- version: '1.0'
21
- type: :runtime
22
17
  prerelease: false
23
- version_requirements: !ruby/object:Gem::Requirement
24
- requirements:
25
- - - "~>"
26
- - !ruby/object:Gem::Version
27
- version: '1.0'
28
- - !ruby/object:Gem::Dependency
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ~>
21
+ - !ruby/object:Gem::Version
22
+ version: "1.0"
23
+ type: :runtime
24
+ version_requirements: *id001
25
+ - !ruby/object:Gem::Dependency
29
26
  name: bundler
30
- requirement: !ruby/object:Gem::Requirement
31
- requirements:
32
- - - ">="
33
- - !ruby/object:Gem::Version
34
- version: '0'
35
- type: :development
36
27
  prerelease: false
37
- version_requirements: !ruby/object:Gem::Requirement
38
- requirements:
39
- - - ">="
40
- - !ruby/object:Gem::Version
41
- version: '0'
42
- - !ruby/object:Gem::Dependency
43
- name: rake
44
- requirement: !ruby/object:Gem::Requirement
45
- requirements:
46
- - - ">="
47
- - !ruby/object:Gem::Version
48
- version: '0'
28
+ requirement: &id002 !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: "1.6"
49
33
  type: :development
34
+ version_requirements: *id002
35
+ - !ruby/object:Gem::Dependency
36
+ name: rake
50
37
  prerelease: false
51
- version_requirements: !ruby/object:Gem::Requirement
52
- requirements:
53
- - - ">="
54
- - !ruby/object:Gem::Version
55
- version: '0'
56
- - !ruby/object:Gem::Dependency
57
- name: pry
58
- requirement: !ruby/object:Gem::Requirement
59
- requirements:
60
- - - ">="
61
- - !ruby/object:Gem::Version
62
- version: '0'
38
+ requirement: &id003 !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ~>
41
+ - !ruby/object:Gem::Version
42
+ version: "10.3"
63
43
  type: :development
44
+ version_requirements: *id003
45
+ - !ruby/object:Gem::Dependency
46
+ name: pry
64
47
  prerelease: false
65
- version_requirements: !ruby/object:Gem::Requirement
66
- requirements:
67
- - - ">="
68
- - !ruby/object:Gem::Version
69
- version: '0'
70
- - !ruby/object:Gem::Dependency
71
- name: pry-rescue
72
- requirement: !ruby/object:Gem::Requirement
73
- requirements:
74
- - - ">="
75
- - !ruby/object:Gem::Version
76
- version: '0'
48
+ requirement: &id004 !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ~>
51
+ - !ruby/object:Gem::Version
52
+ version: "0.9"
77
53
  type: :development
54
+ version_requirements: *id004
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry-rescue
78
57
  prerelease: false
79
- version_requirements: !ruby/object:Gem::Requirement
80
- requirements:
81
- - - ">="
82
- - !ruby/object:Gem::Version
83
- version: '0'
84
- - !ruby/object:Gem::Dependency
85
- name: rspec
86
- requirement: !ruby/object:Gem::Requirement
87
- requirements:
88
- - - "~>"
89
- - !ruby/object:Gem::Version
90
- version: '3.0'
58
+ requirement: &id005 !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ~>
61
+ - !ruby/object:Gem::Version
62
+ version: "1.4"
91
63
  type: :development
64
+ version_requirements: *id005
65
+ - !ruby/object:Gem::Dependency
66
+ name: rspec
92
67
  prerelease: false
93
- version_requirements: !ruby/object:Gem::Requirement
94
- requirements:
95
- - - "~>"
96
- - !ruby/object:Gem::Version
97
- version: '3.0'
98
- - !ruby/object:Gem::Dependency
99
- name: rspec-its
100
- requirement: !ruby/object:Gem::Requirement
101
- requirements:
102
- - - "~>"
103
- - !ruby/object:Gem::Version
104
- version: '1.0'
68
+ requirement: &id006 !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ~>
71
+ - !ruby/object:Gem::Version
72
+ version: "3.0"
105
73
  type: :development
74
+ version_requirements: *id006
75
+ - !ruby/object:Gem::Dependency
76
+ name: rspec-its
106
77
  prerelease: false
107
- version_requirements: !ruby/object:Gem::Requirement
108
- requirements:
109
- - - "~>"
110
- - !ruby/object:Gem::Version
111
- version: '1.0'
112
- - !ruby/object:Gem::Dependency
78
+ requirement: &id007 !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: "1.0"
83
+ type: :development
84
+ version_requirements: *id007
85
+ - !ruby/object:Gem::Dependency
113
86
  name: fivemat
114
- requirement: !ruby/object:Gem::Requirement
115
- requirements:
116
- - - ">="
117
- - !ruby/object:Gem::Version
118
- version: '0'
87
+ prerelease: false
88
+ requirement: &id008 !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ~>
91
+ - !ruby/object:Gem::Version
92
+ version: "1.3"
119
93
  type: :development
94
+ version_requirements: *id008
95
+ - !ruby/object:Gem::Dependency
96
+ name: yard
120
97
  prerelease: false
121
- version_requirements: !ruby/object:Gem::Requirement
122
- requirements:
123
- - - ">="
124
- - !ruby/object:Gem::Version
125
- version: '0'
98
+ requirement: &id009 !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ~>
101
+ - !ruby/object:Gem::Version
102
+ version: "0.8"
103
+ type: :development
104
+ version_requirements: *id009
126
105
  description: A Ruby-like wrapper for ffi-rzmq-core (ZeroMQ)
127
106
  email: joe.eli.mac@gmail.com
128
107
  executables: []
108
+
129
109
  extensions: []
110
+
130
111
  extra_rdoc_files: []
131
- files:
112
+
113
+ files:
132
114
  - LICENSE
133
115
  - README.md
134
116
  - lib/0mq.rb
@@ -142,28 +124,31 @@ files:
142
124
  - lib/0mq/socket/options.rb
143
125
  - lib/0mq/version.rb
144
126
  homepage: https://github.com/jemc/0mq/
145
- licenses:
127
+ licenses:
146
128
  - MIT
147
129
  metadata: {}
130
+
148
131
  post_install_message:
149
132
  rdoc_options: []
150
- require_paths:
133
+
134
+ require_paths:
151
135
  - lib
152
- required_ruby_version: !ruby/object:Gem::Requirement
153
- requirements:
154
- - - ">="
155
- - !ruby/object:Gem::Version
156
- version: '0'
157
- required_rubygems_version: !ruby/object:Gem::Requirement
158
- requirements:
159
- - - ">="
160
- - !ruby/object:Gem::Version
161
- version: '0'
136
+ required_ruby_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - &id010
139
+ - ">="
140
+ - !ruby/object:Gem::Version
141
+ version: "0"
142
+ required_rubygems_version: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - *id010
162
145
  requirements: []
146
+
163
147
  rubyforge_project:
164
148
  rubygems_version: 2.2.2
165
149
  signing_key:
166
150
  specification_version: 4
167
151
  summary: 0mq
168
152
  test_files: []
153
+
169
154
  has_rdoc: