static VALUE t_get_loop_time (VALUE self UNUSED) { uint64_t current_time = evma_get_current_loop_time(); if (current_time == 0) { return Qnil; } // Generally the industry has moved to 64-bit time_t, this is just in case we're 32-bit time_t. if (sizeof(time_t) < 8 && current_time > INT_MAX) { return rb_funcall(rb_cTime, Intern_at, 2, INT2NUM(current_time / 1000000), INT2NUM(current_time % 1000000)); } else { return rb_time_new(current_time / 1000000, current_time % 1000000); } }
static VALUE t_get_loop_time (VALUE self) { #ifndef HAVE_RB_TIME_NEW static VALUE cTime = rb_path2class("Time"); static ID at = rb_intern("at"); #endif uint64_t current_time = evma_get_current_loop_time(); if (current_time != 0) { #ifndef HAVE_RB_TIME_NEW return rb_funcall(cTime, at, 2, INT2NUM(current_time / 1000000), INT2NUM(current_time % 1000000)); #else return rb_time_new(current_time / 1000000, current_time % 1000000); #endif } return Qnil; }
static VALUE t_get_idle_time (VALUE self, VALUE from) { try { uint64_t current_time = evma_get_current_loop_time(); uint64_t time = evma_get_last_activity_time(NUM2ULONG (from)); if (current_time != 0 && time != 0) { if (time >= current_time) return ULONG2NUM(0); else { uint64_t diff = current_time - time; float seconds = diff / (1000.0*1000.0); return rb_float_new(seconds); } return Qnil; } } catch (std::runtime_error e) { rb_raise (EM_eConnectionError, "%s", e.what()); } return Qnil; }