Skip to content
Browse files

Add socket option IPV4ONLY

  • Loading branch information...
1 parent bdd0a39 commit 04ceb85728d572baecce194b7a520bbfd2fe3f23 @celldee celldee committed Mar 30, 2012
Showing with 34 additions and 1 deletion.
  1. +1 −0 lib/ffi-rzmq/constants.rb
  2. +2 −1 lib/ffi-rzmq/socket.rb
  3. +31 −0 spec/socket_spec.rb
View
1 lib/ffi-rzmq/constants.rb
@@ -133,6 +133,7 @@ module ZMQ
MULTICAST_HOPS = 25
RCVTIMEO = 27
SNDTIMEO = 28
+ IPV4ONLY = 31
# Send/recv options
DONTWAIT = 1
View
3 lib/ffi-rzmq/socket.rb
@@ -686,6 +686,7 @@ class Socket
# ZMQ::RECONNECT_IVL - integer measured in milliseconds
# ZMQ::BACKLOG - integer
# ZMQ::RECOVER_IVL_MSEC - integer measured in milliseconds
+ # ZMQ::IPV4ONLY - integer
#
# Returns 0 when the operation completed successfully.
# Returns -1 when this operation failed.
@@ -735,7 +736,7 @@ def populate_option_lookup
super()
# integer options
- [RECONNECT_IVL_MAX, RCVHWM, SNDHWM, RATE, RECOVERY_IVL, SNDBUF, RCVBUF].each { |option| @option_lookup[option] = 0 }
+ [RECONNECT_IVL_MAX, RCVHWM, SNDHWM, RATE, RECOVERY_IVL, SNDBUF, RCVBUF, IPV4ONLY].each { |option| @option_lookup[option] = 0 }
end
# these finalizer-related methods cannot live in the CommonSocketBehavior
View
31 spec/socket_spec.rb
@@ -418,6 +418,37 @@ module ZMQ
array[0].should == value
end
end # context using option ZMQ::BACKLOG
+
+ context "using option ZMQ::IPV4ONLY" do
+ it "should enable use of IPV6 sockets when set to 0" do
+ value = 0
+ socket.setsockopt ZMQ::IPV4ONLY, value
+ array = []
+ rc = socket.getsockopt(ZMQ::IPV4ONLY, array)
+ rc.should == 0
+ array[0].should == value
+ end
+
+ it "should default to a value of 1" do
+ value = 1
+ array = []
+ rc = socket.getsockopt(ZMQ::IPV4ONLY, array)
+ rc.should == 0
+ array[0].should == value
+ end
+
+ it "returns -1 given a negative value" do
+ value = -1
+ rc = socket.setsockopt ZMQ::IPV4ONLY, value
+ rc.should == -1
+ end
+
+ it "returns -1 given a value > 1" do
+ value = 2
+ rc = socket.setsockopt ZMQ::IPV4ONLY, value
+ rc.should == -1
+ end
+ end # context using option ZMQ::IPV4ONLY
end # context #setsockopt

0 comments on commit 04ceb85

Please sign in to comment.
Something went wrong with that request. Please try again.