0mq 0.4.1 → 0.5.0
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.
- checksums.yaml +4 -4
- data/lib/0mq/poll_interruptible.rb +24 -7
- data/lib/0mq/socket.rb +5 -5
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0f5853df137983c39643738260536be6283df3a5
|
4
|
+
data.tar.gz: b9d8a07715d0a9e28a0d785a96cd2c98b4f5e7ab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d71708e4a35e312ac7d4c01fb8193c414f99d90e777784742e1f4e2fa128e8bbd42853e288562e4b0591042703415a05011777622a15a59e10f8501ea8c30577
|
7
|
+
data.tar.gz: f1557ddadcf7b3ed574f74983b0c017db99ffe22946034c21a632acfc28ddb71787544415d8e264da8d54ae0383314e9353b4207f5281c898b7a5d10ba9bf408
|
@@ -17,23 +17,33 @@ module ZMQ
|
|
17
17
|
@int_sock_rep.bind int_endpoint
|
18
18
|
@int_sock_req.connect int_endpoint
|
19
19
|
|
20
|
+
# Interruption blocks are stored here by key until #run receives them.
|
21
|
+
# After each is run, the return value is stored here in its place.
|
22
|
+
@interruptions = {}
|
23
|
+
|
20
24
|
@dead = false
|
21
25
|
|
22
26
|
super @int_sock_rep, *sockets
|
23
27
|
end
|
24
28
|
|
25
|
-
# Same as Poll#run, but will yield [nil, nil] to the block if interrupted
|
29
|
+
# Same as Poll#run, but will yield [nil, nil] to the block if interrupted.
|
30
|
+
# Return value may be an empty hash if the poller was killed.
|
26
31
|
def run(&block)
|
27
32
|
raise "#{self} cannot run; it was permanently killed." if @dead
|
28
33
|
|
29
34
|
super do |socket, revents|
|
30
35
|
if socket == @int_sock_rep
|
31
|
-
|
36
|
+
key, * = socket.recv_array
|
37
|
+
kill = key == "KILL"
|
38
|
+
|
39
|
+
# Call the user block of #interrupt and store the return value
|
40
|
+
@interruptions[key] = @interruptions[key].call unless kill
|
32
41
|
|
42
|
+
# Call the user block of #run
|
33
43
|
block.call nil, nil if block
|
34
44
|
|
35
45
|
socket.send_array ["OKAY"]
|
36
|
-
@int_sock_rep.close if
|
46
|
+
@int_sock_rep.close if kill
|
37
47
|
else
|
38
48
|
block.call socket, revents if block
|
39
49
|
end
|
@@ -44,11 +54,18 @@ module ZMQ
|
|
44
54
|
# This should be run anytime to let the poller re-evaluate state, etc..
|
45
55
|
# This should only be accessed from a thread other than the poll thread,
|
46
56
|
# and only if the poll thread is running
|
47
|
-
|
48
|
-
|
49
|
-
|
57
|
+
# If a block is given, it will be executed in the poll thread just
|
58
|
+
# prior to the execution of the user block passed to {#run}.
|
59
|
+
def interrupt(&block)
|
60
|
+
block ||= Proc.new { true }
|
61
|
+
key = block.object_id.to_s 36
|
62
|
+
|
63
|
+
@interruptions[key] = block # Store the block to be called
|
64
|
+
|
65
|
+
@int_sock_req.send_string key # Signal an interruption to #run
|
66
|
+
@int_sock_req.recv_array # Wait until it has been handled by #run
|
50
67
|
|
51
|
-
|
68
|
+
@interruptions.delete key # Return the stored result of the block
|
52
69
|
end
|
53
70
|
|
54
71
|
# Interrupt the running poll loop and permanently kill the Poll object
|
data/lib/0mq/socket.rb
CHANGED
@@ -121,17 +121,17 @@ module ZMQ
|
|
121
121
|
end
|
122
122
|
|
123
123
|
# Send a multipart message as an array of strings
|
124
|
-
def send_array(array)
|
124
|
+
def send_array(array, flags = 0)
|
125
125
|
array = array.to_a
|
126
|
-
array[0...-1].each { |str| send_string str, ZMQ::SNDMORE }
|
127
|
-
send_string array.last
|
126
|
+
array[0...-1].each { |str| send_string str, ZMQ::SNDMORE|flags }
|
127
|
+
send_string array.last, flags
|
128
128
|
end
|
129
129
|
|
130
130
|
# Receive a multipart message as an array of strings
|
131
|
-
def recv_array
|
131
|
+
def recv_array(flags = 0)
|
132
132
|
[].tap do |ary|
|
133
133
|
loop do
|
134
|
-
ary << recv_string
|
134
|
+
ary << recv_string(flags)
|
135
135
|
break unless get_opt(ZMQ::RCVMORE)
|
136
136
|
end
|
137
137
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: 0mq
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joe McIlvain
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-03
|
12
|
+
date: 2014-06-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ffi-rzmq-core
|
@@ -147,7 +147,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
147
147
|
version: '0'
|
148
148
|
requirements: []
|
149
149
|
rubyforge_project:
|
150
|
-
rubygems_version: 2.2.
|
150
|
+
rubygems_version: 2.2.2
|
151
151
|
signing_key:
|
152
152
|
specification_version: 4
|
153
153
|
summary: 0mq
|