- move DoubleTime to nserver.c
- extend wait command to fraction of seconds
This commit is contained in:
27
nserver.c
27
nserver.c
@ -20,6 +20,7 @@
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
#include "sics.h"
|
||||
#include "network.h"
|
||||
#include "ifile.h"
|
||||
@ -377,13 +378,12 @@ void RunServer(pServer self)
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
typedef struct {
|
||||
time_t tFinish;
|
||||
double dFinish;
|
||||
int iEnd;
|
||||
} WaitStruct, *pWaitStruct;
|
||||
/*-------------------------------------------------------------------------*/
|
||||
static int WaitTask(void *pData)
|
||||
{
|
||||
time_t tNow;
|
||||
pWaitStruct self = NULL;
|
||||
|
||||
self = (pWaitStruct) pData;
|
||||
@ -391,8 +391,7 @@ static int WaitTask(void *pData)
|
||||
return 0;
|
||||
}
|
||||
|
||||
tNow = time(NULL);
|
||||
if (tNow >= self->tFinish) {
|
||||
if (DoubleTime() >= self->dFinish) {
|
||||
return 0; /* done */
|
||||
} else {
|
||||
return 1;
|
||||
@ -428,7 +427,6 @@ int UserWait(SConnection * pCon, SicsInterp * pSics, void *pData,
|
||||
char pBueffel[80];
|
||||
float fVal;
|
||||
Status eOld;
|
||||
time_t tNow;
|
||||
WaitStruct sWait;
|
||||
pTaskMan pTask;
|
||||
long lID;
|
||||
@ -460,8 +458,7 @@ int UserWait(SConnection * pCon, SicsInterp * pSics, void *pData,
|
||||
|
||||
eOld = GetStatus();
|
||||
SetStatus(eUserWait);
|
||||
tNow = time(NULL);
|
||||
sWait.tFinish = tNow + (time_t) fVal;
|
||||
sWait.dFinish = DoubleTime() + (double)fVal;
|
||||
sWait.iEnd = 0;
|
||||
lID = TaskRegister(pTask, WaitTask, WaitSignal, NULL, &sWait, 1);
|
||||
TaskWait(pTask, lID);
|
||||
@ -478,7 +475,6 @@ int SicsWaitOld(long lTime)
|
||||
{
|
||||
WaitStruct sWait;
|
||||
pTaskMan pTasker = NULL;
|
||||
time_t tNow;
|
||||
long lID;
|
||||
|
||||
if (pServ->simMode) {
|
||||
@ -486,8 +482,7 @@ int SicsWaitOld(long lTime)
|
||||
}
|
||||
|
||||
pTasker = GetTasker();
|
||||
tNow = time(NULL);
|
||||
sWait.tFinish = tNow + lTime;
|
||||
sWait.dFinish = DoubleTime() + lTime;
|
||||
sWait.iEnd = 0;
|
||||
lID = TaskRegister(pTasker, WaitTask, WaitSignal, NULL, &sWait, 1);
|
||||
TaskWait(pTasker, lID);
|
||||
@ -530,3 +525,15 @@ int ServerIsStarting(pServer self)
|
||||
{
|
||||
return self->pReader == NULL;
|
||||
}
|
||||
/*-------------------------------------------------------------------------*/
|
||||
double DoubleTime(void)
|
||||
{
|
||||
struct timeval now;
|
||||
/* the resolution of this function is usec, if the machine supports this
|
||||
and the mantissa of a double is 51 bits or more (31 for sec and 20 for mic$
|
||||
*/
|
||||
gettimeofday(&now, NULL);
|
||||
return now.tv_sec + now.tv_usec / 1e6;
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user