- bug fixes

SKIPPED:
	psi/haakedriv.c
This commit is contained in:
zolliker
2010-02-01 11:29:46 +00:00
parent 820db0b52a
commit 3e8938e986
4 changed files with 26 additions and 23 deletions

View File

@ -180,7 +180,7 @@ int AsconReadGarbage(int fd)
if (l > 0) { if (l > 0) {
/* swallow */ /* swallow */
garbage[l] = '\0'; garbage[l] = '\0';
printf("(((%s)))\n", garbage); /* printf("(((%s)))\n", garbage); */
result += l; result += l;
} else if (l == 0) { } else if (l == 0) {
errno = ECONNRESET; errno = ECONNRESET;

View File

@ -1,3 +1,4 @@
#include <stdio.h>
#include <math.h> #include <math.h>
#include "ascon.h" #include "ascon.h"
#include "devser.h" #include "devser.h"
@ -57,7 +58,7 @@ static void DevFreeActionList(DevAction * actions)
} }
} }
static double nextTime(double last, static double nextTime(double due,
double lastInterval, double lastInterval,
double now, double now,
double interval) { double interval) {
@ -66,12 +67,12 @@ static double nextTime(double last,
* following rules: * following rules:
* (1) result > now * (1) result > now
* (2) result is a multiple of interval * (2) result is a multiple of interval
* (3) result > last + min(lastInterval,interval) * 0.99 * (3) result >= due OR result >= due - lastInterval + interval
*/ */
if (interval > lastInterval) { if (interval > lastInterval) {
base = last + lastInterval * 0.99; base = due - lastInterval * 0.01;
} else { } else {
base = last + interval * 0.99; base = due - lastInterval + interval * 0.99;
} }
if (now > base) { if (now > base) {
base = now; base = now;
@ -79,6 +80,7 @@ static double nextTime(double last,
return (floor(base / interval) + 1) * interval; return (floor(base / interval) + 1) * interval;
} }
static DevAction *DevNextAction(DevSer * devser) static DevAction *DevNextAction(DevSer * devser)
{ {
/* the action queue is primarily ordered by priority (high prioirty first), /* the action queue is primarily ordered by priority (high prioirty first),
@ -104,8 +106,7 @@ static DevAction *DevNextAction(DevSer * devser)
action->timeDue = now; action->timeDue = now;
} else { } else {
/* increase timeDue according to interval */ /* increase timeDue according to interval */
action->timeDue = nextTime(action->timeDue, action->interval, action->timeDue = nextTime(0, 0, now, action->interval);
now, action->interval);
} }
prio = action->prio; prio = action->prio;
@ -280,7 +281,7 @@ int DevSchedule(DevSer * devser, void *actionData,
for (ptr2prev = &devser->actions, action = devser->actions; for (ptr2prev = &devser->actions, action = devser->actions;
action != NULL; action != NULL;
ptr2prev = &action->next, action = action->next) { action = action->next) {
if (action->prio < prio && ptr2insertPos == NULL) { if (action->prio < prio && ptr2insertPos == NULL) {
ptr2insertPos = ptr2prev; ptr2insertPos = ptr2prev;
} }
@ -292,21 +293,28 @@ int DevSchedule(DevSer * devser, void *actionData,
&& matchFunc(actionData, action->data)) { && matchFunc(actionData, action->data)) {
if (prio == action->prio && interval < 0) { if (prio == action->prio && interval < 0) {
/* do not move an action with equal prio */ /* do not move an action with equal prio */
killFunc(actionData); if (killFunc) {
return 0; killFunc(actionData);
}
return 0; /* not queued */
} }
/* remove action from list */ /* remove action from list */
*ptr2prev = action->next; *ptr2prev = action->next;
foundAction = action; foundAction = action;
} else {
ptr2prev = &action->next;
} }
} }
/* create if needed */
if (foundAction != NULL) { if (foundAction != NULL) {
/* a similar action was found */
action = foundAction; action = foundAction;
if (killFunc) {
killFunc(actionData);
}
ret = 0; ret = 0;
killFunc(actionData);
} else { } else {
/* create if needed */
action = calloc(1, sizeof(*action)); action = calloc(1, sizeof(*action));
assert(action); assert(action);
action->data = actionData; action->data = actionData;
@ -335,7 +343,7 @@ int DevSchedule(DevSer * devser, void *actionData,
} }
action->interval = interval; action->interval = interval;
} }
return ret; return ret; /* when 0, actionData was killed */
} }
int DevQueue(DevSer * devser, void *actionData, DevPrio prio, int DevQueue(DevSer * devser, void *actionData, DevPrio prio,

View File

@ -77,7 +77,7 @@ void DevDisconnect(DevSer * devser);
* after the action has finished, i.e. when hdl returned NULL) * after the action has finished, i.e. when hdl returned NULL)
* or NULL if no kill function is needed. * or NULL if no kill function is needed.
* \return 1 when this was a new action, 0 when an action was overwritten * \return 1 when this was a new action, 0 when an action was overwritten
* in the second case the actionData's kill Function is called * in the second case the actionData's kill Function is immediately called
*/ */
int DevQueue(DevSer * devser, void *actionData, DevPrio prio, int DevQueue(DevSer * devser, void *actionData, DevPrio prio,
DevActionHandler * hdl, DevActionMatch * matchFunc, DevActionHandler * hdl, DevActionMatch * matchFunc,
@ -95,7 +95,7 @@ int DevQueue(DevSer * devser, void *actionData, DevPrio prio,
* \param matchFunc a match function with two arguments of the same type * \param matchFunc a match function with two arguments of the same type
* \param killFunc the action data kill function or NULL if no kill function is needed. * \param killFunc the action data kill function or NULL if no kill function is needed.
* \return 1 when this was a new action, 0 when an action was overwritten * \return 1 when this was a new action, 0 when an action was overwritten
* in the second case the actionData's kill Function is called * in the second case the actionData's kill Function is immediately called
*/ */
int DevSchedule(DevSer * devser, void *actionData, int DevSchedule(DevSer * devser, void *actionData,
DevPrio prio, double interval, DevPrio prio, double interval,

View File

@ -1008,13 +1008,8 @@ void SctQueueNode(SctController * controller, Hdb * node,
data->conCtx = NULL; data->conCtx = NULL;
data->answered = 1; data->answered = 1;
if (!DevQueue(data->controller->devser, data, prio, if (DevQueue(data->controller->devser, data, prio,
SctWriteHandler, SctMatch, SctKillData)) { SctWriteHandler, SctMatch, SctKillData)) {
if (data->name != NULL) {
free(data->name);
}
free(data);
} else {
if (con != NULL) { if (con != NULL) {
data->conCtx = SCCopyConnection(con); data->conCtx = SCCopyConnection(con);
} }