Bug fix - when inserting timers into timer queue timer could go missing. Also clear next pointer on insert into tail and clear vrfy on free.
r1918 | dcl | 2007-04-24 17:18:57 +1000 (Tue, 24 Apr 2007) | 2 lines
This commit is contained in:
15
nwatch.c
15
nwatch.c
@@ -80,17 +80,19 @@ static int NetWatchTimerInsQue(pNetWatch self, pNWTimer handle)
|
||||
/* if the queue is empty, just stick new one in */
|
||||
if (self->tq_head == NULL) {
|
||||
self->tq_head = self->tq_tail = handle;
|
||||
handle->next = NULL;
|
||||
return 1;
|
||||
}
|
||||
/* if new one is later than latest one, insert after latest */
|
||||
/* if new one is not earlier than latest one, insert after latest */
|
||||
if (handle->tv.tv_sec > self->tq_tail->tv.tv_sec ||
|
||||
(handle->tv.tv_sec == self->tq_tail->tv.tv_sec &&
|
||||
handle->tv.tv_usec >= self->tq_tail->tv.tv_usec)) {
|
||||
self->tq_tail->next = handle;
|
||||
self->tq_tail = handle;
|
||||
handle->next = NULL;
|
||||
return 1;
|
||||
}
|
||||
/* if new one is earlier than earliest one, insert before earliest */
|
||||
/* if new one is not later than earliest one, insert before earliest */
|
||||
if (handle->tv.tv_sec < self->tq_head->tv.tv_sec ||
|
||||
(handle->tv.tv_sec == self->tq_head->tv.tv_sec &&
|
||||
handle->tv.tv_usec <= self->tq_head->tv.tv_usec)) {
|
||||
@@ -109,7 +111,7 @@ static int NetWatchTimerInsQue(pNetWatch self, pNWTimer handle)
|
||||
handle->tv.tv_usec > pNxt->next->tv.tv_usec)))
|
||||
pNxt = pNxt->next;
|
||||
/* slip new one in between this one and the next one */
|
||||
handle = pNxt->next;
|
||||
handle->next = pNxt->next;
|
||||
pNxt->next = handle ;
|
||||
}
|
||||
return 1;
|
||||
@@ -207,6 +209,7 @@ int NetWatchRemoveTimer(pNWTimer handle)
|
||||
if (!self || self->lMagic != NWMAGIC)\
|
||||
return 0;
|
||||
NetWatchTimerRemQue(self, handle);
|
||||
handle->vrfy = 0;
|
||||
free(handle);
|
||||
return 1;
|
||||
}
|
||||
@@ -263,7 +266,7 @@ static void NetWatchContextRemQue(pNetWatch self, pNWContext handle)
|
||||
if (handle == self->cq_tail) /* if last */
|
||||
self->cq_tail = pNxt;
|
||||
}
|
||||
return 1;
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -449,8 +452,10 @@ int NetWatchTask (void* pData)
|
||||
}
|
||||
NetWatchTimerInsQue(self, pNew);
|
||||
}
|
||||
else
|
||||
else {
|
||||
pNew->vrfy = 0;
|
||||
free(pNew);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user