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/test/io/event/selector.rb b/test/io/event/selector.rb index 3d087c52..c8c93fb2 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(TypeError) end end