Permalink
Browse files

Fix JRUBY-4850: Second argument to TCPSocket.new should allow for ser…

…vice name.

Note that, if an unexpected value is passed, we still do not raise the same exception as MRI; e.g., MRI raises NameError, while we raise TypeError.
  • Loading branch information...
1 parent 2b166c9 commit b5ae167edfdc2fd23182c57f2ea12beda0fbba53 @BanzaiMan BanzaiMan committed Jun 6, 2010
Showing with 6 additions and 2 deletions.
  1. +6 −2 src/org/jruby/ext/socket/RubyTCPSocket.java
@@ -84,8 +84,12 @@ public RubyTCPSocket(Ruby runtime, RubyClass type) {
}
private int getPortFrom(Ruby runtime, IRubyObject arg) {
- return RubyNumeric.fix2int(arg instanceof RubyString ?
- RubyNumeric.str2inum(runtime, (RubyString) arg, 0, true) : arg);
+ if (arg instanceof RubyString) {
+ jnr.netdb.Service service = jnr.netdb.Service.getServiceByName(arg.asJavaString(), "tcp");
+ return service != null ?
+ service.getPort() : RubyNumeric.fix2int(RubyNumeric.str2inum(runtime, (RubyString) arg, 0, true));
+ }
+ return RubyNumeric.fix2int(arg);
}
@JRubyMethod(required = 2, optional = 2, visibility = Visibility.PRIVATE, backtrace = true)

0 comments on commit b5ae167

Please sign in to comment.