bool Timer::is_same_day(ACE_Date_Time &old_dt, ACE_Date_Time &new_dt) { if (old_dt.year() != new_dt.year()) { return false; } else if (old_dt.month() != new_dt.month()) { return false; } else if (old_dt.day() != new_dt.day()) { return false; } return true; }
void set_system_time(const ACE_Time_Value& tv) { # if defined (ACE_WIN32) ACE_Date_Time curdt (tv); SYSTEMTIME sys_time; sys_time.wDay = ACE_Utils::truncate_cast <WORD> (curdt.day ()); sys_time.wMonth = ACE_Utils::truncate_cast <WORD> (curdt.month ()); sys_time.wYear = ACE_Utils::truncate_cast <WORD> (curdt.year ()); sys_time.wHour = ACE_Utils::truncate_cast <WORD> (curdt.hour ()); sys_time.wMinute = ACE_Utils::truncate_cast <WORD> (curdt.minute ()); sys_time.wSecond = ACE_Utils::truncate_cast <WORD> (curdt.second ()); sys_time.wMilliseconds = ACE_Utils::truncate_cast <WORD> (curdt.microsec () / 1000); if (!::SetLocalTime (&sys_time)) # else timespec_t curts; curts = tv; if (ACE_OS::clock_settime (CLOCK_REALTIME, &curts) != 0) # endif { ACE_DEBUG((LM_INFO, "(%P|%t) Unable to reset OS time. Insufficient privileges or not supported.\n")); } }
bool test_timer (ACE_Condition_Thread_Mutex& condition_, ACE_Time_Value& waittime, bool monotonic = false) { bool status = true; MyTask task1; task1.create_reactor (); task1.start (1); TestHandler test_handler (task1.get_reactor ()); // The second reactor that uses a hrtimer will trigger a timeout in // 5 seconds. At the same moment we calculate a timeout for the condition // 3 seconds in the future. Than we set the time 4 seconds back. // at the moment now the condition timeouts the trigger should have not // been executed. This is because with hrtime the trigger will call in 5 // seconds and the condition in 3 seconds, independent of any time change // meaning that the timeout should trigger if (!test_handler.trigger_in (ACE_Time_Value (5, 0))) ACE_ERROR_RETURN ((LM_ERROR, "(%P|%t) Unable to schedule trigger.\n"), false); waittime += ACE_Time_Value (3,0); // reset system clock 4 seconds backwards ACE_Time_Value curtime = ACE_OS::gettimeofday (); curtime -= ACE_Time_Value (4, 0); # if defined (ACE_WIN32) ACE_Date_Time curdt (curtime); SYSTEMTIME sys_time; sys_time.wDay = ACE_Utils::truncate_cast <WORD> (curdt.day ()); sys_time.wMonth = ACE_Utils::truncate_cast <WORD> (curdt.month ()); sys_time.wYear = ACE_Utils::truncate_cast <WORD> (curdt.year ()); sys_time.wHour = ACE_Utils::truncate_cast <WORD> (curdt.hour ()); sys_time.wMinute = ACE_Utils::truncate_cast <WORD> (curdt.minute ()); sys_time.wSecond = ACE_Utils::truncate_cast <WORD> (curdt.second ()); sys_time.wMilliseconds = ACE_Utils::truncate_cast <WORD> (curdt.microsec () / 1000); if (!::SetLocalTime (&sys_time)) # else timespec_t curts; curts = curtime; if (ACE_OS::clock_settime (CLOCK_REALTIME, &curts) != 0) # endif { ACE_DEBUG((LM_INFO, "(%P|%t) Unable to reset OS time. Insufficient privileges or not supported.\n")); } else { ACE_DEBUG((LM_INFO, "(%P|%t) Going to wait on condition until %#T.\n", &waittime)); if (condition_.wait (&waittime) != -1 || errno != ETIME) { ACE_ERROR ((LM_ERROR, "ERROR: No errno or return -1\n")); status = 1; } ACE_DEBUG((LM_INFO, "(%P|%t) Condition wait returned at %#T.\n", &waittime)); if (test_handler.timeout_triggered ()) { if (monotonic) { ACE_ERROR ((LM_ERROR, "(%P|%t) ERROR: timer handler shouldn't have " "triggered because we used monotonic condition timing!\n")); status = false; } else ACE_DEBUG ((LM_INFO, "(%P|%t) timer handler " "triggered because we used non-monotonic condition timing!\n")); } else { if (!monotonic) { ACE_ERROR ((LM_ERROR, "(%P|%t) ERROR: timer handler should have " "triggered because we used non-monotonic condition timing!\n")); status = false; } else ACE_DEBUG ((LM_INFO, "(%P|%t) timer handler has not " "triggered because we used monotonic condition timing!\n")); } // reset system clock to correct time curtime = ACE_OS::gettimeofday (); curtime += ACE_Time_Value (4, 0); # if defined (ACE_WIN32) curdt.update (curtime); SYSTEMTIME sys_time; sys_time.wDay = ACE_Utils::truncate_cast <WORD> (curdt.day ()); sys_time.wMonth = ACE_Utils::truncate_cast <WORD> (curdt.month ()); sys_time.wYear = ACE_Utils::truncate_cast <WORD> (curdt.year ()); sys_time.wHour = ACE_Utils::truncate_cast <WORD> (curdt.hour ()); sys_time.wMinute = ACE_Utils::truncate_cast <WORD> (curdt.minute ()); sys_time.wSecond = ACE_Utils::truncate_cast <WORD> (curdt.second ()); sys_time.wMilliseconds = ACE_Utils::truncate_cast <WORD> (curdt.microsec () / 1000); if (!::SetLocalTime (&sys_time)) # else curts = curtime; if (ACE_OS::clock_settime (CLOCK_REALTIME, &curts) != 0) # endif { ACE_DEBUG((LM_INFO, "(%P|%t) Unable to reset OS time. Insufficient privileges or not supported.\n")); } } ACE_DEBUG((LM_INFO, "(%P|%t) Asking worker thread to finish.\n")); task1.stop (); ACE_Thread_Manager::instance ()->wait (); return status; }