download delay.cpp
Language: C++
License: GPL
Copyright: (C) 2001 Grub, Inc. *
LOC: 33
Project Info
grub.org - Distributed Internet Crawler(grub)
Server: SourceForge
Type: cvs
...ge\g\grub\grub\client\util\
   alt_ftw.c
   alt_ftw.h
   bin_test_util.dsp
   clog.cpp
   clog.h
   ConfigFileInfo.h
   crc.h
   crc_32.c
   crc_32.cpp
   crc_32.h
   crc_test.c
   crc_test.cpp
   crc32.c
   crc32.h
   dbl_list.c
   dbl_list.h
   delay.cpp
   delay.h
   diagnose.h
   fc32.c
   file_data.c
   file_data.h
   getopt.c
   getopt.h
   grubconf.c
   grubconf.h
   GrubExp.cpp
   GrubExp.h
   Gui.cpp
   Gui.h
   intl.h
   lib_util.dsp
   lockfile.cpp
   lockfile.h
   Makefile.am
   parsecfg.c
   parsecfg.h
   platform.h
   rmfiles.c
   rmfiles.h
   ServerSettings.cpp
   ServerSettings.h
   sniptype.h
   StatusInterface.cpp
   StatusInterface.h
   strip_url.c
   strip_url.h
   test_util.cpp

/**************************************************************************
 *                                                                        *
 *   Copyright (C) 2001 Grub, Inc.                                        *
 *   delay.cpp - a delay function                                         *
 *   Authors: Lawrence Kincheloe &                                        *
 *            Philip McCauley                                             *
 *                                                                        *
 *   This program is free software; you can redistribute it and/or modify *
 *   it under the terms of the GNU General Public License as published by *
 *   the Free Software Foundation; either version 2, or (at your option)  *
 *   any later version.                                                   *
 *                                                                        *
 *   This program is distributed in the hope that it will be useful,      *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of       *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
 *   GNU General Public License for more details.                         *
 *                                                                        *
 *   You should have received a copy of the GNU General Public License    *
 *   along with this program; if not, write to the Free Software          *
 *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.            *
 *                                                                        *
 *                                                                        *
 **************************************************************************/ 

#include <stdlib.h>
#include <stdio.h>
#include <iostream.h>
#include <time.h>
#ifdef GRUB_UNIX
#include <unistd.h>
#endif
#include <math.h>
#include "delay.h"
extern "C" {
 #include <verbose.h>
}

//using namespace std;

#include "StatusInterface.h"

// void Retry_Delay(int x)
// Retry_Delay is called with the number of failures received when
// attempting to contact the Grub server.  Its function is to sleep
// an amount that is scaled to the amount of failures.  Probabale max
// sleep time is around a day or so with a 100 failures.  Of course
// this amount would only be achieved if the server was down for more
// than a month.
//
// function uses y = 8 * x^2 as its computation

void Retry_Delay(int failcnt)

{
	double wait_time = 0;   //retry delay time in seconds
	double drift, failures, final;
	int final_sleep;
	srand(time(NULL));
	failures = (double) failcnt;
	wait_time = 8 * pow( failures, 2.0);
	drift = rand() / ( ( RAND_MAX / ( wait_time * .40 ) ) );
	final = wait_time - ( wait_time * .20 ) + drift;	
	final_sleep = (int) final;
        Verboseprintf("\nClient sleeping for %d seconds!\n", final_sleep );

	/* Posting to the windows GUI */	
	Crawler_Status.PostSleep( final_sleep );

#ifdef GRUB_UNIX
	sleep(final_sleep);
#else  /* GRUB_UNIX */
	Sleep(final_sleep * 1000);
#endif /* ! GRUB_UNIX */
	return;
}

About Koders | Resources | Downloads | Support | Black Duck | Submit Project | Terms of Service | DMCA | Privacy Policy | Site Map| Contact Us