Permalink
Browse files

Merge pull request #2014 from frodsan/fix_socket_constants

Fix Socket#socketpair on X19.
  • Loading branch information...
2 parents 01ec9b2 + 477e3ec commit bcb15bd379735d54bdb43e2d355091bf097b3964 @dbussink dbussink committed Nov 17, 2012
Showing with 28 additions and 0 deletions.
  1. +2 −0 lib/18/socket.rb
  2. +8 −0 lib/19/socket.rb
  3. +18 −0 spec/ruby/library/socket/shared/socketpair.rb
View
@@ -682,6 +682,8 @@ def self.socketpair(domain, type, protocol, klass=self)
else
raise SocketError, "unknown socket type #{type}"
end
+ elsif !type.kind_of? Integer
+ raise Errno::EPROTONOSUPPORT, type.inspect
end
FFI::MemoryPointer.new :int, 2 do |mp|
View
@@ -684,6 +684,14 @@ def self.socketpair(domain, type, protocol, klass=self)
end
end
+ if type.kind_of? Symbol
+ begin
+ type = Socket::Constants.const_get("SOCK_#{type}")
+ rescue NameError
+ raise SocketError, "unknown socket type #{type}"
+ end
+ end
+
FFI::MemoryPointer.new :int, 2 do |mp|
Socket::Foreign.socketpair(domain, type, protocol, mp)
fd0, fd1 = mp.read_array_of_int(2)
@@ -8,4 +8,22 @@
s2.close
end
end
+
+ ruby_version_is "1.9" do
+ it "raises SocketError if given symbol is not a Socket constants reference" do
+ lambda { Socket.socketpair(Socket::AF_UNIX, :NO_EXIST, 0) }.should raise_error(SocketError)
+ end
+
+ it "not raises SocketError if given symbol references a Socket constant" do
+ [ :DGRAM, :RAW, :RDM, :SEQPACKET, :STREAM ].each do |socket_type|
+ lambda { Socket.socketpair(Socket::AF_UNIX, socket_type, 0) }.should_not raise_error(SocketError)
+ end
+ end
+ end
+
+ ruby_version_is ""..."1.9" do
+ it "raises Errno::EPROTONOSUPPORT if socket type is not a String or Integer" do
+ lambda { Socket.socketpair(Socket::AF_UNIX, :DGRAM, 0) }.should raise_error(Errno::EPROTONOSUPPORT)
+ end
+ end
end

0 comments on commit bcb15bd

Please sign in to comment.