diff options
author | schmidt <douglascraigschmidt@users.noreply.github.com> | 2003-01-19 17:47:56 +0000 |
---|---|---|
committer | schmidt <douglascraigschmidt@users.noreply.github.com> | 2003-01-19 17:47:56 +0000 |
commit | 440924f1e326e1069d15beb10167143de944c3fa (patch) | |
tree | c3b9679a69e99b04d60f66e1c7ae852c690290e6 /ace/NT_Service.cpp | |
parent | d3269e48beba8e3434f49bd0e379e6ba26fe048b (diff) | |
download | ATCD-440924f1e326e1069d15beb10167143de944c3fa.tar.gz |
ChangeLogTag:Sun Jan 19 11:40:10 2003 Douglas C. Schmidt <schmidt@macarena.cs.wustl.edu>
Diffstat (limited to 'ace/NT_Service.cpp')
-rw-r--r-- | ace/NT_Service.cpp | 68 |
1 files changed, 62 insertions, 6 deletions
diff --git a/ace/NT_Service.cpp b/ace/NT_Service.cpp index 7014d3f0502..20b490694cc 100644 --- a/ace/NT_Service.cpp +++ b/ace/NT_Service.cpp @@ -543,12 +543,68 @@ void ACE_NT_Service::wait_for_service_state (DWORD desired_state, ACE_Time_Value *wait_time) { - // Doing the right thing with these needs to be added. - ACE_UNUSED_ARG (desired_state); - ACE_UNUSED_ARG (wait_time); - - QueryServiceStatus (this->svc_sc_handle_, - &this->svc_status_); + DWORD last_state, last_check_point; + int first_time = 1; + int service_ok; + + ACE_Time_Value time_out = ACE_OS::gettimeofday (); + if (wait_time != 0) + time_out += *wait_time; + + // Poll until the service reaches the desired state. + for (;;) + { + service_ok = 0 != QueryServiceStatus (this->svc_sc_handle_, + &this->svc_status_); + + // If we cannot query the service, we are done. + if (!service_ok) + break; + + // If the service has the desired state, we are done. + if (desired_state == this->svc_status_.dwCurrentState) + break; + + // If we time-out, we are done + if (wait_time != 0 && ACE_OS::gettimeofday () > time_out ) + { + errno = ETIME; + break; + } + + if (first_time) + { + // remember the service state, the first time we wait + last_state = this->svc_status_.dwCurrentState; + last_check_point = this->svc_status_.dwCheckPoint; + first_time = 0; + } + else + { + // update the state change. + if (last_state != this->svc_status_.dwCurrentState) + { + last_state = this->svc_status_.dwCurrentState; + last_check_point = this->svc_status_.dwCheckPoint; + } + else + { + // The check-point should have increased + if (this->svc_status_.dwCheckPoint > last_check_point) + last_check_point = this->svc_status_.dwCheckPoint; + else + { + // Service control failure, we are done. + service_ok = 0; + break; + } + } + } + + ::Sleep (this->svc_status_.dwWaitHint); + } + + return service_ok == 0 ? -1 : 0; } #endif /* ACE_WIN32 && !ACE_HAS_PHARLAP */ |