Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fix Socket#new on X19. #2037

Merged
merged 2 commits into from

3 participants

@frodsan

When I create a new Socket without giving a protocol,
Rubinius 1.9 mode should use 0 internally as the default
like Ruby 1.9.3:

>> require 'socket'
=> true
>> Socket.new(Socket::PF_UNIX, :DGRAM)
=> #<Socket:fd 5>

Fixes #2032.

@frodsan frodsan Fix Socket#new on X19.
When I create a new Socket without giving a protocol,
Rubinius 1.9 mode should use 0 internally as the default
like Ruby 1.9.3:

    >> require 'socket'
    => true
    >> Socket.new(Socket::PF_UNIX, :DGRAM)
    => #<Socket:fd 5>

Fixes #2032.
21fee9d
@dbussink
Owner

Can you please also add a spec for this? We should also check whether there's a constant we can use instead of 0 as a magic variable.

@frodsan

I based it on the documentation: http://www.ruby-doc.org/stdlib-1.9.3/libdoc/socket/rdoc/Socket.html

protocol should be a protocol defined in the domain. This is optional. If it is not given, 0 is used internally.

sock_initialize(int argc, VALUE *argv, VALUE sock)
{
    VALUE domain, type, protocol;
    int fd;
    int d, t;

    rb_scan_args(argc, argv, "21", &domain, &type, &protocol);
    if (NIL_P(protocol))
        protocol = INT2FIX(0);
@brixen brixen merged commit c15ad57 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 19, 2012
  1. @frodsan

    Fix Socket#new on X19.

    frodsan authored
    When I create a new Socket without giving a protocol,
    Rubinius 1.9 mode should use 0 internally as the default
    like Ruby 1.9.3:
    
        >> require 'socket'
        => true
        >> Socket.new(Socket::PF_UNIX, :DGRAM)
        => #<Socket:fd 5>
    
    Fixes #2032.
  2. @frodsan
This page is out of date. Refresh to see the latest.
View
2  lib/19/socket.rb
@@ -710,7 +710,7 @@ class << self
end
end
- def initialize(family, socket_type, protocol)
+ def initialize(family, socket_type, protocol=0)
@no_reverse_lookup = self.class.do_not_reverse_lookup
socket_type = self.class.get_socket_type(socket_type)
descriptor = Socket::Foreign.socket family, socket_type, protocol
View
4 spec/ruby/library/socket/socket/new_spec.rb
@@ -24,5 +24,9 @@
lambda { Socket.new(Socket::PF_UNIX, socket_type, 0) }.should_not raise_error(SocketError)
end
end
+
+ it "protocol parameter should be optional" do
+ lambda { Socket.new(Socket::PF_UNIX, :DGRAM) }.should_not raise_error(ArgumentError)
+ end
end
end
Something went wrong with that request. Please try again.