rbczmq 0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +23 -0
- data/.travis.yml +19 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +19 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +247 -0
- data/Rakefile +67 -0
- data/examples/loop.rb +109 -0
- data/examples/poller.rb +37 -0
- data/examples/pub_sub.rb +101 -0
- data/examples/push_pull.rb +104 -0
- data/examples/req_rep.rb +100 -0
- data/ext/czmq.tar.gz +0 -0
- data/ext/rbczmq/context.c +280 -0
- data/ext/rbczmq/context.h +26 -0
- data/ext/rbczmq/extconf.rb +138 -0
- data/ext/rbczmq/frame.c +401 -0
- data/ext/rbczmq/frame.h +24 -0
- data/ext/rbczmq/jruby.h +22 -0
- data/ext/rbczmq/loop.c +413 -0
- data/ext/rbczmq/loop.h +24 -0
- data/ext/rbczmq/message.c +620 -0
- data/ext/rbczmq/message.h +24 -0
- data/ext/rbczmq/poller.c +308 -0
- data/ext/rbczmq/poller.h +29 -0
- data/ext/rbczmq/pollitem.c +251 -0
- data/ext/rbczmq/pollitem.h +25 -0
- data/ext/rbczmq/rbczmq_ext.c +198 -0
- data/ext/rbczmq/rbczmq_ext.h +94 -0
- data/ext/rbczmq/rbczmq_prelude.h +22 -0
- data/ext/rbczmq/rubinius.h +24 -0
- data/ext/rbczmq/ruby18.h +43 -0
- data/ext/rbczmq/ruby19.h +15 -0
- data/ext/rbczmq/socket.c +1570 -0
- data/ext/rbczmq/socket.h +136 -0
- data/ext/rbczmq/timer.c +110 -0
- data/ext/rbczmq/timer.h +23 -0
- data/ext/zeromq.tar.gz +0 -0
- data/lib/rbczmq.rb +3 -0
- data/lib/zmq.rb +77 -0
- data/lib/zmq/context.rb +50 -0
- data/lib/zmq/default_handler.rb +16 -0
- data/lib/zmq/frame.rb +11 -0
- data/lib/zmq/handler.rb +76 -0
- data/lib/zmq/loop.rb +131 -0
- data/lib/zmq/message.rb +9 -0
- data/lib/zmq/poller.rb +22 -0
- data/lib/zmq/pollitem.rb +31 -0
- data/lib/zmq/socket.rb +125 -0
- data/lib/zmq/socket/dealer.rb +33 -0
- data/lib/zmq/socket/pair.rb +39 -0
- data/lib/zmq/socket/pub.rb +30 -0
- data/lib/zmq/socket/pull.rb +29 -0
- data/lib/zmq/socket/push.rb +32 -0
- data/lib/zmq/socket/rep.rb +37 -0
- data/lib/zmq/socket/req.rb +37 -0
- data/lib/zmq/socket/router.rb +38 -0
- data/lib/zmq/socket/sub.rb +27 -0
- data/lib/zmq/timer.rb +12 -0
- data/lib/zmq/version.rb +5 -0
- data/perf/pair.rb +7 -0
- data/perf/pair/local.rb +22 -0
- data/perf/pair/remote.rb +25 -0
- data/perf/pub_sub.rb +7 -0
- data/perf/pub_sub/local.rb +22 -0
- data/perf/pub_sub/remote.rb +25 -0
- data/perf/push_pull.rb +7 -0
- data/perf/push_pull/local.rb +21 -0
- data/perf/push_pull/remote.rb +25 -0
- data/perf/req_rep.rb +7 -0
- data/perf/req_rep/local.rb +35 -0
- data/perf/req_rep/remote.rb +28 -0
- data/perf/runner.rb +142 -0
- data/rbczmq.gemspec +22 -0
- data/test/helper.rb +21 -0
- data/test/socket/test_dealer_socket.rb +14 -0
- data/test/socket/test_pair_socket.rb +24 -0
- data/test/socket/test_pair_sockets.rb +74 -0
- data/test/socket/test_pub_socket.rb +17 -0
- data/test/socket/test_pub_sub_sockets.rb +87 -0
- data/test/socket/test_pull_socket.rb +17 -0
- data/test/socket/test_push_pull_sockets.rb +81 -0
- data/test/socket/test_push_socket.rb +17 -0
- data/test/socket/test_rep_socket.rb +25 -0
- data/test/socket/test_req_rep_sockets.rb +42 -0
- data/test/socket/test_req_socket.rb +27 -0
- data/test/socket/test_router_socket.rb +14 -0
- data/test/socket/test_routing.rb +66 -0
- data/test/socket/test_sub_socket.rb +17 -0
- data/test/test_context.rb +86 -0
- data/test/test_frame.rb +78 -0
- data/test/test_handler.rb +28 -0
- data/test/test_loop.rb +252 -0
- data/test/test_message.rb +201 -0
- data/test/test_poller.rb +154 -0
- data/test/test_pollitem.rb +78 -0
- data/test/test_socket.rb +403 -0
- data/test/test_threading.rb +34 -0
- data/test/test_timer.rb +37 -0
- data/test/test_zmq.rb +62 -0
- metadata +208 -0
@@ -0,0 +1,34 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.join(File.dirname(__FILE__), 'helper')
|
4
|
+
|
5
|
+
Thread.abort_on_exception = true
|
6
|
+
|
7
|
+
class TestZmqThreading < ZmqTestCase
|
8
|
+
def test_threaded
|
9
|
+
ctx = ZMQ::Context.new
|
10
|
+
rep, req, threads = nil, nil, []
|
11
|
+
# Spawn a few threads in sleep state
|
12
|
+
5.times{|i| threads << Thread.new{ sleep(0.5); i } }
|
13
|
+
# Spawn a few CPU bound threads
|
14
|
+
5.times{|i| threads << Thread.new{ 500_000.times{} } }
|
15
|
+
expected = "threaded message"
|
16
|
+
threads << Thread.new do
|
17
|
+
rep = ctx.socket ZMQ::PAIR
|
18
|
+
rep.bind('inproc://test.threaded')
|
19
|
+
sleep 0.5
|
20
|
+
rep.recv
|
21
|
+
end
|
22
|
+
sleep 0.3
|
23
|
+
threads << Thread.new do
|
24
|
+
req = ctx.socket ZMQ::PAIR
|
25
|
+
req.connect('inproc://test.threaded')
|
26
|
+
req.send(expected)
|
27
|
+
end
|
28
|
+
Thread.pass
|
29
|
+
sleep 0.3
|
30
|
+
threads.map!{|t| t.value }
|
31
|
+
thread_vals = [0, 1, 2, 3, 4, 500_000, 500_000, 500_000, 500_000, 500_000, expected, true]
|
32
|
+
assert_equal thread_vals, threads
|
33
|
+
end
|
34
|
+
end
|
data/test/test_timer.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.join(File.dirname(__FILE__), 'helper')
|
4
|
+
|
5
|
+
class TestZmqTimer < ZmqTestCase
|
6
|
+
|
7
|
+
def test_alloc
|
8
|
+
cb = Proc.new{ :done }
|
9
|
+
assert_raises ArgumentError do
|
10
|
+
ZMQ::Timer.new(1, 2)
|
11
|
+
end
|
12
|
+
assert_instance_of ZMQ::Timer, ZMQ::Timer.new(1, 2, cb)
|
13
|
+
assert_instance_of ZMQ::Timer, ZMQ::Timer.new(1, 2){ :fired }
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_fire
|
17
|
+
timer = ZMQ::Timer.new(1, 2){ :fired }
|
18
|
+
assert_equal :fired, timer.fire
|
19
|
+
assert_equal :fired, timer.call
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_on_error
|
23
|
+
timer = ZMQ::Timer.new(1, 2){ :fired }
|
24
|
+
err = StandardError.new("oops")
|
25
|
+
assert_raises StandardError do
|
26
|
+
timer.on_error(err)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_cancel
|
31
|
+
timer = ZMQ::Timer.new(1, 2){ :fired }
|
32
|
+
timer.cancel
|
33
|
+
assert_raises ZMQ::Error do
|
34
|
+
timer.call
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/test/test_zmq.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.join(File.dirname(__FILE__), 'helper')
|
4
|
+
|
5
|
+
class TestZmq < ZmqTestCase
|
6
|
+
def test_interrupted_p
|
7
|
+
assert !ZMQ.interrupted?
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_version
|
11
|
+
assert_equal [2,1,11], ZMQ.version
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_now
|
15
|
+
assert [Bignum, Fixnum].include?(ZMQ.now.class)
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_log
|
19
|
+
assert_nil ZMQ.log("log message")
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_error
|
23
|
+
expected = [ZMQ::Error, NilClass]
|
24
|
+
assert expected.any?{|c| c === ZMQ.error }
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_errno
|
28
|
+
assert_instance_of Fixnum, ZMQ.errno
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_select
|
32
|
+
ctx = ZMQ::Context.new
|
33
|
+
poller = ZMQ::Poller.new
|
34
|
+
assert_equal 0, poller.poll
|
35
|
+
rep = ctx.socket(:REP)
|
36
|
+
rep.linger = 0
|
37
|
+
rep.bind("inproc://test.select")
|
38
|
+
req = ctx.socket(:REQ)
|
39
|
+
req.linger = 0
|
40
|
+
req.connect("inproc://test.select")
|
41
|
+
|
42
|
+
r, w, e = ZMQ.select([rep], nil, nil, 1)
|
43
|
+
assert_equal [], r
|
44
|
+
assert_equal [], w
|
45
|
+
assert_equal [], e
|
46
|
+
|
47
|
+
assert req.send("request")
|
48
|
+
|
49
|
+
r, w, e = ZMQ.select([rep], nil, nil, 1)
|
50
|
+
assert_equal [rep], r
|
51
|
+
assert_equal [], w
|
52
|
+
assert_equal [], e
|
53
|
+
ensure
|
54
|
+
ctx.destroy
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_pollitem
|
58
|
+
item = ZMQ::Pollitem(STDOUT, ZMQ::POLLIN)
|
59
|
+
assert_equal STDOUT, item.pollable
|
60
|
+
assert_equal ZMQ::POLLIN, item.events
|
61
|
+
end
|
62
|
+
end
|
metadata
ADDED
@@ -0,0 +1,208 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rbczmq
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 9
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: "0.1"
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- "Lourens Naud\xC3\xA9"
|
13
|
+
- James Tucker
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2012-02-21 00:00:00 +00:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: rake-compiler
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 63
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
- 8
|
33
|
+
- 0
|
34
|
+
version: 0.8.0
|
35
|
+
type: :development
|
36
|
+
version_requirements: *id001
|
37
|
+
description: "Ruby extension for CZMQ - High-level C Binding for \xC3\x98MQ (http://czmq.zeromq.org)"
|
38
|
+
email:
|
39
|
+
- lourens@methodmissing.com
|
40
|
+
- jftucker@gmail.com
|
41
|
+
executables: []
|
42
|
+
|
43
|
+
extensions:
|
44
|
+
- ext/rbczmq/extconf.rb
|
45
|
+
extra_rdoc_files: []
|
46
|
+
|
47
|
+
files:
|
48
|
+
- .gitignore
|
49
|
+
- .travis.yml
|
50
|
+
- Gemfile
|
51
|
+
- Gemfile.lock
|
52
|
+
- MIT-LICENSE
|
53
|
+
- README.rdoc
|
54
|
+
- Rakefile
|
55
|
+
- examples/loop.rb
|
56
|
+
- examples/poller.rb
|
57
|
+
- examples/pub_sub.rb
|
58
|
+
- examples/push_pull.rb
|
59
|
+
- examples/req_rep.rb
|
60
|
+
- ext/czmq.tar.gz
|
61
|
+
- ext/rbczmq/context.c
|
62
|
+
- ext/rbczmq/context.h
|
63
|
+
- ext/rbczmq/extconf.rb
|
64
|
+
- ext/rbczmq/frame.c
|
65
|
+
- ext/rbczmq/frame.h
|
66
|
+
- ext/rbczmq/jruby.h
|
67
|
+
- ext/rbczmq/loop.c
|
68
|
+
- ext/rbczmq/loop.h
|
69
|
+
- ext/rbczmq/message.c
|
70
|
+
- ext/rbczmq/message.h
|
71
|
+
- ext/rbczmq/poller.c
|
72
|
+
- ext/rbczmq/poller.h
|
73
|
+
- ext/rbczmq/pollitem.c
|
74
|
+
- ext/rbczmq/pollitem.h
|
75
|
+
- ext/rbczmq/rbczmq_ext.c
|
76
|
+
- ext/rbczmq/rbczmq_ext.h
|
77
|
+
- ext/rbczmq/rbczmq_prelude.h
|
78
|
+
- ext/rbczmq/rubinius.h
|
79
|
+
- ext/rbczmq/ruby18.h
|
80
|
+
- ext/rbczmq/ruby19.h
|
81
|
+
- ext/rbczmq/socket.c
|
82
|
+
- ext/rbczmq/socket.h
|
83
|
+
- ext/rbczmq/timer.c
|
84
|
+
- ext/rbczmq/timer.h
|
85
|
+
- ext/zeromq.tar.gz
|
86
|
+
- lib/rbczmq.rb
|
87
|
+
- lib/zmq.rb
|
88
|
+
- lib/zmq/context.rb
|
89
|
+
- lib/zmq/default_handler.rb
|
90
|
+
- lib/zmq/frame.rb
|
91
|
+
- lib/zmq/handler.rb
|
92
|
+
- lib/zmq/loop.rb
|
93
|
+
- lib/zmq/message.rb
|
94
|
+
- lib/zmq/poller.rb
|
95
|
+
- lib/zmq/pollitem.rb
|
96
|
+
- lib/zmq/socket.rb
|
97
|
+
- lib/zmq/socket/dealer.rb
|
98
|
+
- lib/zmq/socket/pair.rb
|
99
|
+
- lib/zmq/socket/pub.rb
|
100
|
+
- lib/zmq/socket/pull.rb
|
101
|
+
- lib/zmq/socket/push.rb
|
102
|
+
- lib/zmq/socket/rep.rb
|
103
|
+
- lib/zmq/socket/req.rb
|
104
|
+
- lib/zmq/socket/router.rb
|
105
|
+
- lib/zmq/socket/sub.rb
|
106
|
+
- lib/zmq/timer.rb
|
107
|
+
- lib/zmq/version.rb
|
108
|
+
- perf/pair.rb
|
109
|
+
- perf/pair/local.rb
|
110
|
+
- perf/pair/remote.rb
|
111
|
+
- perf/pub_sub.rb
|
112
|
+
- perf/pub_sub/local.rb
|
113
|
+
- perf/pub_sub/remote.rb
|
114
|
+
- perf/push_pull.rb
|
115
|
+
- perf/push_pull/local.rb
|
116
|
+
- perf/push_pull/remote.rb
|
117
|
+
- perf/req_rep.rb
|
118
|
+
- perf/req_rep/local.rb
|
119
|
+
- perf/req_rep/remote.rb
|
120
|
+
- perf/runner.rb
|
121
|
+
- rbczmq.gemspec
|
122
|
+
- test/helper.rb
|
123
|
+
- test/socket/test_dealer_socket.rb
|
124
|
+
- test/socket/test_pair_socket.rb
|
125
|
+
- test/socket/test_pair_sockets.rb
|
126
|
+
- test/socket/test_pub_socket.rb
|
127
|
+
- test/socket/test_pub_sub_sockets.rb
|
128
|
+
- test/socket/test_pull_socket.rb
|
129
|
+
- test/socket/test_push_pull_sockets.rb
|
130
|
+
- test/socket/test_push_socket.rb
|
131
|
+
- test/socket/test_rep_socket.rb
|
132
|
+
- test/socket/test_req_rep_sockets.rb
|
133
|
+
- test/socket/test_req_socket.rb
|
134
|
+
- test/socket/test_router_socket.rb
|
135
|
+
- test/socket/test_routing.rb
|
136
|
+
- test/socket/test_sub_socket.rb
|
137
|
+
- test/test_context.rb
|
138
|
+
- test/test_frame.rb
|
139
|
+
- test/test_handler.rb
|
140
|
+
- test/test_loop.rb
|
141
|
+
- test/test_message.rb
|
142
|
+
- test/test_poller.rb
|
143
|
+
- test/test_pollitem.rb
|
144
|
+
- test/test_socket.rb
|
145
|
+
- test/test_threading.rb
|
146
|
+
- test/test_timer.rb
|
147
|
+
- test/test_zmq.rb
|
148
|
+
has_rdoc: true
|
149
|
+
homepage: http://github.com/methodmissing/rbczmq
|
150
|
+
licenses: []
|
151
|
+
|
152
|
+
post_install_message:
|
153
|
+
rdoc_options:
|
154
|
+
- --charset=UTF-8
|
155
|
+
require_paths:
|
156
|
+
- lib
|
157
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
158
|
+
none: false
|
159
|
+
requirements:
|
160
|
+
- - ">="
|
161
|
+
- !ruby/object:Gem::Version
|
162
|
+
hash: 3
|
163
|
+
segments:
|
164
|
+
- 0
|
165
|
+
version: "0"
|
166
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
167
|
+
none: false
|
168
|
+
requirements:
|
169
|
+
- - ">="
|
170
|
+
- !ruby/object:Gem::Version
|
171
|
+
hash: 3
|
172
|
+
segments:
|
173
|
+
- 0
|
174
|
+
version: "0"
|
175
|
+
requirements: []
|
176
|
+
|
177
|
+
rubyforge_project:
|
178
|
+
rubygems_version: 1.6.2
|
179
|
+
signing_key:
|
180
|
+
specification_version: 3
|
181
|
+
summary: "Ruby extension for CZMQ - High-level C Binding for \xC3\x98MQ (http://czmq.zeromq.org)"
|
182
|
+
test_files:
|
183
|
+
- test/helper.rb
|
184
|
+
- test/socket/test_dealer_socket.rb
|
185
|
+
- test/socket/test_pair_socket.rb
|
186
|
+
- test/socket/test_pair_sockets.rb
|
187
|
+
- test/socket/test_pub_socket.rb
|
188
|
+
- test/socket/test_pub_sub_sockets.rb
|
189
|
+
- test/socket/test_pull_socket.rb
|
190
|
+
- test/socket/test_push_pull_sockets.rb
|
191
|
+
- test/socket/test_push_socket.rb
|
192
|
+
- test/socket/test_rep_socket.rb
|
193
|
+
- test/socket/test_req_rep_sockets.rb
|
194
|
+
- test/socket/test_req_socket.rb
|
195
|
+
- test/socket/test_router_socket.rb
|
196
|
+
- test/socket/test_routing.rb
|
197
|
+
- test/socket/test_sub_socket.rb
|
198
|
+
- test/test_context.rb
|
199
|
+
- test/test_frame.rb
|
200
|
+
- test/test_handler.rb
|
201
|
+
- test/test_loop.rb
|
202
|
+
- test/test_message.rb
|
203
|
+
- test/test_poller.rb
|
204
|
+
- test/test_pollitem.rb
|
205
|
+
- test/test_socket.rb
|
206
|
+
- test/test_threading.rb
|
207
|
+
- test/test_timer.rb
|
208
|
+
- test/test_zmq.rb
|