Skip to content

Commit

Permalink
always attempt to convert IO.select timeout argument to_f (9K version…
Browse files Browse the repository at this point in the history
… of #821)
  • Loading branch information
kares committed Jan 8, 2016
1 parent e4aae85 commit 363cbb4
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions core/src/main/java/org/jruby/RubyIO.java
Original file line number Diff line number Diff line change
Expand Up @@ -3314,7 +3314,6 @@ public static RubyIO convertToIO(ThreadContext context, IRubyObject obj) {
@JRubyMethod(name = "select", required = 1, optional = 3, meta = true)
public static IRubyObject select(ThreadContext context, IRubyObject recv, IRubyObject[] argv) {
IRubyObject read, write, except, _timeout;
Long timeout;
read = write = except = _timeout = context.nil;

switch (argv.length) {
Expand All @@ -3327,13 +3326,21 @@ public static IRubyObject select(ThreadContext context, IRubyObject recv, IRubyO
case 1:
read = argv[0];
}
final Long timeout;
if (_timeout.isNil()) {
timeout = null;
}
else {
double tmp = _timeout.convertToFloat().getDoubleValue();
if (tmp < 0) throw context.runtime.newArgumentError("negative timeout");
timeout = (long)(tmp * 1000); // ms
try { // MRI calls to_f even if not respond_to? (or respond_to_missing?) :to_f
_timeout = _timeout.callMethod(context, "to_f");
}
catch (RaiseException e) {
TypeConverter.handleUncoercibleObject(true, _timeout, context.runtime.getFloat());
throw e; // won't happen
}
final double t = _timeout.convertToFloat().getDoubleValue();
if ( t < 0 ) throw context.runtime.newArgumentError("negative timeout");
timeout = (long) (t * 1000); // ms
}

SelectExecutor args = new SelectExecutor(read, write, except, timeout);
Expand Down

0 comments on commit 363cbb4

Please sign in to comment.