diff --git a/ext/io/event/selector/epoll.c b/ext/io/event/selector/epoll.c index 82fee3c6..5c1f2f40 100644 --- a/ext/io/event/selector/epoll.c +++ b/ext/io/event/selector/epoll.c @@ -786,24 +786,21 @@ struct timespec * make_timeout(VALUE duration, struct timespec * storage) { return NULL; } - if (RB_FLOAT_TYPE_P(duration)) { - double value = RFLOAT_VALUE(duration); - time_t seconds = value; - - storage->tv_sec = seconds; - storage->tv_nsec = (value - seconds) * 1000000000L; - - return storage; - } - - else if (RB_INTEGER_TYPE_P(duration)) { + if (RB_INTEGER_TYPE_P(duration)) { storage->tv_sec = NUM2TIMET(duration); storage->tv_nsec = 0; return storage; } - rb_raise(rb_eArgError, "unable to convert timeout: %"PRIsVALUE, rb_inspect(duration)); + duration = rb_to_float(duration); + double value = RFLOAT_VALUE(duration); + time_t seconds = value; + + storage->tv_sec = seconds; + storage->tv_nsec = (value - seconds) * 1000000000L; + + return storage; } static diff --git a/ext/io/event/selector/kqueue.c b/ext/io/event/selector/kqueue.c index fb5a40e4..699439b0 100644 --- a/ext/io/event/selector/kqueue.c +++ b/ext/io/event/selector/kqueue.c @@ -799,24 +799,21 @@ struct timespec * make_timeout(VALUE duration, struct timespec * storage) { return NULL; } - if (RB_FLOAT_TYPE_P(duration)) { - double value = RFLOAT_VALUE(duration); - time_t seconds = value; - - storage->tv_sec = seconds; - storage->tv_nsec = (value - seconds) * 1000000000L; - - return storage; - } - - else if (RB_INTEGER_TYPE_P(duration)) { + if (RB_INTEGER_TYPE_P(duration)) { storage->tv_sec = NUM2TIMET(duration); storage->tv_nsec = 0; return storage; } - rb_raise(rb_eArgError, "unable to convert timeout: %"PRIsVALUE, rb_inspect(duration)); + duration = rb_to_float(duration); + double value = RFLOAT_VALUE(duration); + time_t seconds = value; + + storage->tv_sec = seconds; + storage->tv_nsec = (value - seconds) * 1000000000L; + + return storage; } static diff --git a/ext/io/event/selector/uring.c b/ext/io/event/selector/uring.c index a753cd47..33f1c3ae 100644 --- a/ext/io/event/selector/uring.c +++ b/ext/io/event/selector/uring.c @@ -901,24 +901,21 @@ struct __kernel_timespec * make_timeout(VALUE duration, struct __kernel_timespec return NULL; } - if (RB_FLOAT_TYPE_P(duration)) { - double value = RFLOAT_VALUE(duration); - time_t seconds = value; - - storage->tv_sec = seconds; - storage->tv_nsec = (value - seconds) * 1000000000L; - - return storage; - } - - else if (RB_INTEGER_TYPE_P(duration)) { + if (RB_INTEGER_TYPE_P(duration)) { storage->tv_sec = NUM2TIMET(duration); storage->tv_nsec = 0; return storage; } - rb_raise(rb_eArgError, "unable to convert timeout: %"PRIsVALUE, rb_inspect(duration)); + duration = rb_to_float(duration); + double value = RFLOAT_VALUE(duration); + time_t seconds = value; + + storage->tv_sec = seconds; + storage->tv_nsec = (value - seconds) * 1000000000L; + + return storage; } static diff --git a/lib/io/event/selector/select.rb b/lib/io/event/selector/select.rb index 99df92d4..eb5d0281 100644 --- a/lib/io/event/selector/select.rb +++ b/lib/io/event/selector/select.rb @@ -420,8 +420,11 @@ def select(duration = nil) duration = 0 unless @ready.empty? error = nil - if duration && duration > 0.0 - start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC) + if duration + duration = duration/1.0 + if duration > 0 + start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC) + end else @idle_duration = 0.0 end diff --git a/test/io/event/selector.rb b/test/io/event/selector.rb index 3d087c52..3214ead1 100644 --- a/test/io/event/selector.rb +++ b/test/io/event/selector.rb @@ -49,7 +49,7 @@ def transfer it "raises an error when given an invalid duration" do expect do selector.select("invalid") - end.to raise_exception(ArgumentError) + end.to raise_exception end end