Permalink
Browse files

Restrict PAIR sockets to inproc transport only

  • Loading branch information...
1 parent 0441865 commit 313894d5cc867695d8cc00706c63ddbe9a6874c7 @methodmissing committed Feb 19, 2012
View
@@ -233,15 +233,12 @@ Running tests
* czmq send methods aren't non-blocking by default
* Enforce socket timeouts
* Revisit the ZMQ::Loop API
-* Restrict pair sockets to inproc transport only
-* Revisit JRuby C API support
* Push gem out to rubygems.org
* RDOC fail on mixed C and Ruby source files that document that same constants
* GC guards to prevent recycling objects being sent / received.
* Sockets can bind && connect to multiple endpoints - account for that
* Watch out for further cases where REQ / REP pairs could raise EFSM
* Fix Rubinius linking wrong libzmq
-* Regen gh-pages branch to reflect ZMQ::Poller changes
* Do not clobber local scope from macros (James's commit in master)
* Support installation without vendor'ed libs as well
* Incorporate examples into CI as well
View
@@ -21,6 +21,17 @@ class ZMQ::Socket::Pair
# [ZMQ::Socket#hwm option action] Block
TYPE_STR = "PAIR"
+ REXP_INPROC = /inproc:\/\//
+
+ def bind(endpoint)
+ raise(ZMQ::Error, "PAIR sockets can only listen using the inproc:// transport") unless endpoint =~ REXP_INPROC
+ super
+ end
+
+ def connect(endpoint)
+ raise(ZMQ::Error, "PAIR sockets can only connect using the inproc:// transport") unless endpoint =~ REXP_INPROC
+ super
+ end
def type
ZMQ::PAIR
View
@@ -3,4 +3,5 @@
$:.unshift('.')
require File.join(File.dirname(__FILE__), 'runner')
-Runner.start(:pair, ENV["MSG_COUNT"], ENV["MSG_SIZE"], ENV["MSG_ENCODING"])
+$runner = ThreadRunner.new(ENV["MSG_COUNT"], ENV["MSG_SIZE"], ENV["MSG_ENCODING"])
+$runner.start(:pair)
View
@@ -2,10 +2,11 @@
ctx = ZMQ::Context.new
pair = ctx.socket(:PAIR)
-pair.connect(Runner::ENDPOINT)
+sleep 2
+pair.connect($runner.endpoint)
messages, start_time = 0, nil
-while (case Runner.encoding
+while (case $runner.encoding
when :string
pair.recv
when :frame
@@ -15,7 +16,7 @@
end) do
start_time ||= Time.now
messages += 1
- break if messages == Runner.msg_count
+ break if messages == $runner.msg_count
end
-Runner.stats(start_time)
+$runner.stats(start_time)
View
@@ -1,14 +1,14 @@
# encoding: utf-8
-ctx = ZMQ::Context.new
+ctx = ZMQ.context
pair = ctx.socket(:PAIR);
-pair.bind(Runner::ENDPOINT);
+pair.bind($runner.endpoint);
-msg = Runner.payload
+msg = $runner.payload
start_time = Time.now
-Runner.msg_count.times do
- case Runner.encoding
+$runner.msg_count.times do
+ case $runner.encoding
when :string
pair.send(msg)
when :frame
@@ -22,4 +22,4 @@
end
end
-puts "Sent #{Runner.msg_count} messages in %ss ..." % (Time.now - start_time)
+puts "Sent #{$runner.msg_count} messages in %ss ..." % (Time.now - start_time)
View
@@ -3,4 +3,5 @@
$:.unshift('.')
require File.join(File.dirname(__FILE__), 'runner')
-Runner.start(:pub_sub, ENV["MSG_COUNT"], ENV["MSG_SIZE"], ENV["MSG_ENCODING"], ENV["PROCESSES"])
+$runner = ProcessRunner.new(ENV["MSG_COUNT"], ENV["MSG_SIZE"], ENV["MSG_ENCODING"], ENV["PROCESSES"])
+$runner.start(:pub_sub)
View
@@ -3,10 +3,10 @@
ctx = ZMQ::Context.new
sub = ctx.socket(:SUB)
sub.subscribe("")
-sub.connect(Runner::ENDPOINT)
+sub.connect($runner.endpoint)
messages, start_time = 0, nil
-while (case Runner.encoding
+while (case $runner.encoding
when :string
sub.recv
when :frame
@@ -16,7 +16,7 @@
end) do
start_time ||= Time.now
messages += 1
- break if messages == Runner.msg_count
+ break if messages == $runner.msg_count
end
-Runner.stats(start_time)
+$runner.stats(start_time)
View
@@ -2,13 +2,13 @@
ctx = ZMQ::Context.new
pub = ctx.socket(:PUB);
-pub.bind(Runner::ENDPOINT);
+pub.bind($runner.endpoint);
-msg = Runner.payload
+msg = $runner.payload
start_time = Time.now
-Runner.msg_count.times do
- case Runner.encoding
+$runner.msg_count.times do
+ case $runner.encoding
when :string
pub.send(msg)
when :frame
@@ -22,4 +22,4 @@
end
end
-puts "Sent #{Runner.msg_count} messages in %ss ..." % (Time.now - start_time)
+puts "Sent #{$runner.msg_count} messages in %ss ..." % (Time.now - start_time)
View
@@ -3,4 +3,5 @@
$:.unshift('.')
require File.join(File.dirname(__FILE__), 'runner')
-Runner.start(:push_pull, ENV["MSG_COUNT"], ENV["MSG_SIZE"], ENV["MSG_ENCODING"], ENV["PROCESSES"])
+$runner = ProcessRunner.new(ENV["MSG_COUNT"], ENV["MSG_SIZE"], ENV["MSG_ENCODING"], ENV["PROCESSES"])
+$runner.start(:push_pull)
View
@@ -2,10 +2,10 @@
ctx = ZMQ::Context.new
pull = ctx.socket(:PULL)
-pull.connect(Runner::ENDPOINT)
+pull.connect($runner.endpoint)
messages, start_time = 0, nil
-while (case Runner.encoding
+while (case $runner.encoding
when :string
pull.recv
when :frame
@@ -15,7 +15,7 @@
end) do
start_time ||= Time.now
messages += 1
- break if messages == Runner.process_msg_count
+ break if messages == $runner.process_msg_count
end
-Runner.stats(start_time)
+$runner.stats(start_time)
View
@@ -2,13 +2,13 @@
ctx = ZMQ::Context.new
push = ctx.socket(:PUSH);
-push.bind(Runner::ENDPOINT);
+push.bind($runner.endpoint);
-msg = Runner.payload
+msg = $runner.payload
start_time = Time.now
-Runner.msg_count.times do
- case Runner.encoding
+$runner.msg_count.times do
+ case $runner.encoding
when :string
push.send(msg)
when :frame
@@ -22,4 +22,4 @@
end
end
-puts "Sent #{Runner.msg_count} messages in %ss ..." % (Time.now - start_time)
+puts "Sent #{$runner.msg_count} messages in %ss ..." % (Time.now - start_time)
View
@@ -3,4 +3,5 @@
$:.unshift('.')
require File.join(File.dirname(__FILE__), 'runner')
-Runner.start(:req_rep, ENV["MSG_COUNT"], ENV["MSG_SIZE"], ENV["MSG_ENCODING"])
+$runner = ProcessRunner.new(ENV["MSG_COUNT"], ENV["MSG_SIZE"], ENV["MSG_ENCODING"])
+$runner.start(:req_rep)
View
@@ -2,12 +2,12 @@
ctx = ZMQ::Context.new
req = ctx.socket(:REQ)
-req.connect(Runner::ENDPOINT)
+req.connect($runner.endpoint)
-msg = Runner.payload
+msg = $runner.payload
messages, start_time = 0, nil
-while (case Runner.encoding
+while (case $runner.encoding
when :string
req.send(msg)
when :frame
@@ -21,15 +21,15 @@
end) do
start_time ||= Time.now
messages += 1
- case Runner.encoding
+ case $runner.encoding
when :string
req.recv
when :frame
req.recv_frame
when :message
req.recv_message
end
- break if messages == Runner.msg_count
+ break if messages == $runner.msg_count
end
-Runner.stats(start_time)
+$runner.stats(start_time)
View
@@ -2,11 +2,11 @@
ctx = ZMQ::Context.new
rep = ctx.socket(:REP);
-rep.bind(Runner::ENDPOINT);
+rep.bind($runner.endpoint);
start_time = Time.now
-Runner.msg_count.times do
- msg = case Runner.encoding
+$runner.msg_count.times do
+ msg = case $runner.encoding
when :string
rep.recv
when :frame
@@ -15,7 +15,7 @@
rep.recv_message
end
- case Runner.encoding
+ case $runner.encoding
when :string
rep.send(msg)
when :frame
@@ -25,4 +25,4 @@
end
end
-puts "Sent #{Runner.msg_count} messages in %ss ..." % (Time.now - start_time)
+puts "Sent #{$runner.msg_count} messages in %ss ..." % (Time.now - start_time)
Oops, something went wrong.

0 comments on commit 313894d

Please sign in to comment.