Commit 9517e1c9 authored by Per Cederqvist's avatar Per Cederqvist
Browse files

(set_time): Use struct timeval instead of time_t.

(dump_statistics): Ditto.
(saver_callback): Ditto.
(setup_timer): Replaced the milliseconds argument with a struct
	timeval argument.
(garb_callback): Simplified the code.
parent a3175b59
/*
* $Id: connections.c,v 0.95 2003/07/12 13:49:40 ceder Exp $
* $Id: connections.c,v 0.96 2003/07/12 21:29:22 ceder Exp $
* Copyright (C) 1991-2002 Lysator Academic Computer Association.
*
* This file is part of the LysKOM server.
......@@ -91,6 +91,7 @@
#include "aux-items.h"
#include "eintr.h"
#include "text-garb.h"
#include "timeval-util.h"
oop_source_sys * kom_server_oop_src = NULL;
struct isc_mcb * kom_server_mcb = NULL;
......@@ -178,11 +179,21 @@ queue_remove(Connection *c)
static void
set_time(void)
{
time_t last_time;
struct timeval last_time;
static int limiter = 0;
last_time = current_time;
current_time = time(NULL);
if (current_time < last_time)
if (gettimeofday(&current_time, NULL) < 0)
{
if (limiter < 50)
{
kom_log("WARNING: gettimeofday failed: %s\n", strerror(errno));
if (++limiter == 50)
kom_log("WARNING: will not log the above message again.\n");
}
}
if (timeval_less(current_time, last_time))
{
kom_log("WARNING: Time is moving in the wrong direction.\n");
/* FIXME (bug 62): Should we take more decisive action here? */
......@@ -475,7 +486,7 @@ fexists(const char *filename)
void
dump_statistics(void)
{
static time_t last_dump = NO_TIME;
static struct timeval last_dump = {0, 0};
int i;
FILE *fp;
......@@ -486,14 +497,14 @@ dump_statistics(void)
return;
}
if (last_dump == NO_TIME)
if (timeval_zero(last_dump))
{
fprintf(fp, "RESTART\n");
last_dump = current_time;
}
fprintf(fp, "TIME: %s", ctime(&current_time));
fprintf(fp, "SECONDS: %d\n", (int)ldifftime(current_time, last_dump));
fprintf(fp, "TIME: %s", ctime(&current_time.tv_sec));
fprintf(fp, "SECONDS: %ld\n", timeval_diff_sec(current_time, last_dump));
fprintf(fp, "STATISTICS:");
/* The last entry corresponds to the dummy entry that is used to
......@@ -848,7 +859,7 @@ read_from_connection(Connection *conn)
static void
setup_timer(struct timeval *tv,
long milliseconds)
struct timeval interval)
{
static int errcnt = 0;
......@@ -867,8 +878,8 @@ setup_timer(struct timeval *tv,
}
else
{
tv->tv_sec += milliseconds / 1000;
tv->tv_usec += 1000 * (milliseconds % 1000);
tv->tv_sec += interval.tv_sec;
tv->tv_usec += interval.tv_usec;
if (tv->tv_usec > 1000000)
{
tv->tv_usec -= 1000000;
......@@ -938,12 +949,7 @@ garb_callback(oop_source *UNUSED(source),
if (garb_text() == FALSE)
setup_timer(next_timer, param.garbtimeout);
else
{
if (gettimeofday(next_timer, NULL) < 0)
*next_timer = OOP_TIME_NOW;
else
next_timer->tv_sec += 60 * param.garb_interval;
}
setup_timer(next_timer, param.garb_interval);
}
else
setup_timer(next_timer, param.garb_busy_postponement);
......@@ -957,7 +963,7 @@ saver_callback(oop_source *UNUSED(source),
struct timeval UNUSED(tv),
void *user)
{
long timeout;
struct timeval timeout;
struct timeval *next_timer = user;
timeout = end_of_atomic();
......
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