Beispiel #1
0
bool watchdog::run()
{
  getmilliseconds();
  if (last_fire + this->major_threshold < clock_tick) {
    CStat::globalStat(CStat::E_WATCHDOG_MAJOR);
    last_trigger = clock_tick;
    WARNING("The major watchdog timer %dms has been tripped (%d), %d trips remaining.", major_threshold, clock_tick - last_fire, major_maxtriggers - major_triggers);
    if ((this->major_maxtriggers != -1) && (++major_triggers > this->major_maxtriggers)) {
      REPORT_ERROR("The watchdog timer has tripped the major threshold of %dms too many times (%d out of %d allowed) (%d out of %d minor %dms timeouts tripped)\n", major_threshold, major_triggers, major_maxtriggers, minor_threshold, minor_triggers, minor_maxtriggers);
    }
  } else if (last_fire + this->minor_threshold < clock_tick) {
    last_trigger = clock_tick;
    CStat::globalStat(CStat::E_WATCHDOG_MINOR);
    WARNING("The minor watchdog timer %dms has been tripped (%d), %d trips remaining.", minor_threshold, clock_tick - last_fire, minor_maxtriggers - minor_triggers);
    if ((this->minor_maxtriggers != -1) && (++minor_triggers > this->minor_maxtriggers)) {
      REPORT_ERROR("The watchdog timer has tripped the minor threshold of %dms too many times (%d out of %d allowed) (%d out of %d major %dms timeouts tripped)\n", minor_threshold, minor_triggers, minor_maxtriggers, major_threshold, major_triggers, major_maxtriggers);
    }
  }

  if (reset_interval && (major_triggers || minor_triggers) && (last_trigger + reset_interval < clock_tick)) {
    WARNING("Resetting watchdog timer trigger counts, as it has not been triggered in over %dms.", clock_tick - last_trigger);
    major_triggers = minor_triggers = 0;
  }

  last_fire = clock_tick;
  setPaused();
  return true;
}
Beispiel #2
0
watchdog::watchdog(int interval, int reset_interval, int major_threshold, int major_maxtriggers, int minor_threshold, int minor_maxtriggers)
{
    this->interval = interval;
    this->reset_interval = reset_interval;
    this->major_threshold = major_threshold;
    this->major_maxtriggers = major_maxtriggers;
    this->minor_threshold = minor_threshold;
    this->minor_maxtriggers = minor_maxtriggers;
    major_triggers = 0;
    minor_triggers = 0;
    last_trigger = last_fire = getmilliseconds();
}
Beispiel #3
0
    static size_t contentcallback(void *data, size_t size, size_t nmemb, http_t *http)
    {
        request_t *req = http->request;

        if (req->callback && data && !http->uninstallrequest()) // no need to store data if there is no callback anyway
        {
            if (!http->downloadstart)
                http->downloadstart = getmilliseconds();

            size_t realsize = size*nmemb;
            size_t size = min<size_t>(realsize, req->maxdatalen-http->data.length());
            http->data.add(data, size);

            int speedlimit;
            getspeedlimit(speedlimit);

            if (http->speedlimit != speedlimit)
            {
                http->speedlimit = speedlimit;
                curl_easy_setopt(http->curl, CURLOPT_MAX_RECV_SPEED_LARGE, (curl_off_t)http->speedlimit);
            }

            if (req->contentcallback)
            {
                if (req->nullterminatorneeded)
                    http->data.add('\0');

                int v = req->contentcallback(http->getrequestid(), req->callbackdata, http->data.getbuf(), http->data.length()-1);

                if (req->nullterminatorneeded)
                    http->data.pop();

                switch (v)
                {
                    case 0: return 0;
                    case 2: http->data.setsize(0);
                }
            }

            if (size == realsize)
                return realsize;
        }

        return 0;
    }
Beispiel #4
0
bool watchdog::run()
{
  getmilliseconds();

  unsigned expected_major_trigger_time = last_fire + this->major_threshold;
  unsigned expected_minor_trigger_time = last_fire + this->minor_threshold;

  bool major_watchdog_tripped = clock_tick > expected_major_trigger_time;
  bool minor_watchdog_tripped = clock_tick > expected_minor_trigger_time;

    // Check if either watchdog has taken longer than expected to run,
    // and if so, warn that we are overloaded.
    if (major_watchdog_tripped) {
        major_triggers++;
        CStat::globalStat(CStat::E_WATCHDOG_MAJOR);
        last_trigger = clock_tick;
        WARNING("Overload warning: the major watchdog timer %dms has been tripped (%d), %d trips remaining.",
                major_threshold,
                clock_tick - last_fire,
                major_maxtriggers - major_triggers);
    } else if (minor_watchdog_tripped) {
        minor_triggers++;
        last_trigger = clock_tick;
        CStat::globalStat(CStat::E_WATCHDOG_MINOR);
        WARNING("Overload warning: the minor watchdog timer %dms has been tripped (%d), %d trips remaining.",
                minor_threshold,
                clock_tick - last_fire,
                minor_maxtriggers - minor_triggers);
    }

    bool major_watchdog_failure = ((this->major_maxtriggers != -1) &&
                                   (major_triggers > this->major_maxtriggers));
    bool minor_watchdog_failure = ((this->minor_maxtriggers != -1) &&
                                   (minor_triggers > this->minor_maxtriggers));

    // If the watchdogs have tripped too many times, end the SIPp run.
    if (major_watchdog_failure) {
        ERROR("Overload error: the watchdog timer has tripped the major threshold of %dms too many times (%d out of %d allowed) (%d out of %d minor %dms timeouts tripped)\n",
              major_threshold,
              major_triggers,
              major_maxtriggers,
              minor_triggers,
              minor_maxtriggers,
              minor_threshold);
    } else if (minor_watchdog_failure) {
        ERROR("Overload error: the watchdog timer has tripped the minor threshold of %dms too many times (%d out of %d allowed) (%d out of %d major %dms timeouts tripped)\n",
              minor_threshold,
              minor_triggers,
              minor_maxtriggers,
              major_triggers,
              major_maxtriggers,
              major_threshold);
    }



    if ((reset_interval > 0) &&
        (major_triggers || minor_triggers) &&
        (clock_tick > (last_trigger + reset_interval))) {
      WARNING("Resetting watchdog timer trigger counts, as it has not been triggered in over %dms.",
              clock_tick - last_trigger);
      major_triggers = minor_triggers = 0;
    }

    last_fire = clock_tick;
    setPaused(); // Return this task to a paused state
    return true;
}
Beispiel #5
0
 static int downloadstatuscallback(http_t *http, double downloadsize, double downloaded, double uploadsize, double uploaded)
 {
     request_t *req = http->request;
     ullong elapsed = http->downloadstart ? getmilliseconds()-http->downloadstart : 0;
     return req->statuscallback(http->getrequestid(), req->callbackdata, downloadsize, downloaded, elapsed) ? 0 : -1;
 }