Commit 1ffe212b authored by Per Cederqvist's avatar Per Cederqvist
Browse files

(sync_output_header): Extract the seconds from the current_time.

(sync_part): Return a struct timeval instead of a long.  Use
	struct timeval instead of a time_t.  Use timeval_remaining()
	to simplify the code.
(init_cache): Use a struct timeval instead of time_t.
(cache_sync_all): Adjusted to new API of sync_part().
parent 6700205b
/*
* $Id: simple-cache.c,v 0.102 2003/07/12 00:19:20 ceder Exp $
* $Id: simple-cache.c,v 0.103 2003/07/12 21:30:05 ceder Exp $
* Copyright (C) 1991-2002 Lysator Academic Computer Association.
*
* This file is part of the LysKOM server.
......@@ -88,6 +88,7 @@
#include "local-to-global.h"
#include "server-time.h"
#include "eintr.h"
#include "timeval-util.h"
#ifdef DEBUG_CALLS
# include "services.h"
......@@ -1741,7 +1742,7 @@ static void
sync_output_header(FILE* fp, const char *state)
{
fprintf(fp, "%s:%05ld\n", state, 2L); /* DIRTY-FLAG and VERSION*/
fprintf(fp, "%020lu\n", (unsigned long)current_time);
fprintf(fp, "%020lu\n", (unsigned long)current_time.tv_sec);
}
static void
......@@ -2431,13 +2432,13 @@ save_one_text(void)
* returns anything else, there is no need to call it again for that
* many seconds, but it is harmless to call it more often than that.
*/
long
struct timeval
sync_part(void)
{
static time_t last_sync_start = NO_TIME;
long timeleft;
static struct timeval last_sync_start = {0, 0};
struct timeval timeleft;
if ( last_sync_start == NO_TIME )
if (timeval_zero(last_sync_start))
{
last_sync_start = current_time;
sync_state = sync_idle;
......@@ -2465,21 +2466,19 @@ sync_part(void)
case sync_ready:
sync_state = sync_idle;
return 1;
return timeval_ctor(1, 0);
case sync_idle:
if (param.never_save)
{
return 60;
}
if ((timeleft = (60 * param.sync_interval
- ldifftime(current_time, last_sync_start))) > 0)
return timeval_ctor(60, 0);
if (timeval_remaining(&timeleft, param.sync_interval,
last_sync_start, current_time))
{
#ifdef LOGACCESSES
syncing_or_saving = 0;
#endif
return timeleft < 0 ? 0 : timeleft;
return timeleft;
}
last_sync_start = current_time;
......@@ -2488,13 +2487,13 @@ sync_part(void)
break;
case sync_wait:
if ((timeleft = (60 * param.sync_retry_interval
- ldifftime(current_time, last_sync_start))) > 0)
if (timeval_remaining(&timeleft, param.sync_retry_interval,
last_sync_start, current_time))
{
#ifdef LOGACCESSES
syncing_or_saving = 0;
#endif
return timeleft < 0 ? 0 : timeleft;
return timeleft;
}
last_sync_start = current_time;
......@@ -2538,7 +2537,7 @@ sync_part(void)
syncing_or_saving = 0;
#endif
return 0;
return timeval_ctor(0, 0);
}
......@@ -2572,7 +2571,7 @@ init_cache(void)
Bool read_text_no = FALSE;
Bool read_conf_no = FALSE;
int c = 0;
time_t saved_time = 0;
struct timeval saved_time;
small_conf_arr = smalloc(sizeof(*small_conf_arr) * param.max_conf);
pers_mcb = create_cache_node_mcb(100, param.max_conf);
......@@ -2670,13 +2669,14 @@ init_cache(void)
*/
fseek(file_a, 12, SEEK_SET);
saved_time = fparse_long(file_a);
if (saved_time > current_time)
saved_time.tv_sec = fparse_long(file_a);
saved_time.tv_usec = 0;
if (timeval_greater(saved_time, current_time))
{
restart_kom("Saved time is later than current time. Exiting.\n");
}
kom_log("Database saved on %s", /* ctime returns a trailing newline. */
ctime(&saved_time));
ctime(&saved_time.tv_sec));
break;
default:
restart_kom("Can't read database version %ld. Giving up.\n",
......@@ -2879,7 +2879,7 @@ cache_sync_all(void)
#endif
pre_sync();
while (sync_part() == 0)
while (timeval_zero(sync_part()))
;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment