diff --git a/ascon.c b/ascon.c index d5d5f96a..6b5f3e25 100644 --- a/ascon.c +++ b/ascon.c @@ -773,7 +773,7 @@ AsconStatus AsconTask(Ascon * a) lastClose = now; a->fd = -1; } - if (now > a->lastReconnect + a->reconnectInterval) { + if (a->reconnectInterval > 0 && now > a->lastReconnect + a->reconnectInterval) { a->lastReconnect = now; a->state = AsconConnectStart; } @@ -840,3 +840,10 @@ double AsconGetSetTimeout(Ascon *a, double timeout, int setmode) { } return a->timeout; } + +int AsconReconnectInterval(Ascon *a, int interval) { + if (interval >= 0) { + a->reconnectInterval = interval; + } + return a->reconnectInterval; +} diff --git a/ascon.h b/ascon.h index 1065e23e..c7f81933 100644 --- a/ascon.h +++ b/ascon.h @@ -117,4 +117,12 @@ char *AsconHostport(Ascon *a); */ double AsconGetSetTimeout(Ascon *a, double timeout, int setmode); +/** + * \brief set reconnectInterval + * \param a the Ascon + * \param interval the interval to set (0: no reconnect, -1: read value) + * \return the value + */ +int AsconReconnectInterval(Ascon *a, int interval); + #endif diff --git a/devser.c b/devser.c index 81ebcc66..b16bf8fe 100644 --- a/devser.c +++ b/devser.c @@ -256,17 +256,19 @@ static int DevQueueTask(void *ds) * TODO: this may be a place to record the end time */ if(devser->startTime > 0){ - LogResponse(devser,1); + LogResponse(devser,1); } else { - /* This is a follow up error and should not go into statistics */ + /* This is a follow up error and should not go into statistics */ } } else if (devser->status == AsconReady) { replyData = AsconRead(devser->ascon); if(replyData != NULL){ - LogResponse(devser,0); + LogResponse(devser,0); } + } else if (devser->status == AsconOffline) { + replyData = "ASCERR: offline"; } else { - return 1; + return 1; } if (devser->steps > 0) { /* debugging mode */ devser->steps--; @@ -602,3 +604,7 @@ char *DevStatus(DevSer *devser) { double DevGetSetTimeout(DevSer *devser, double timeout, int setmode) { return AsconGetSetTimeout(devser->ascon, timeout, setmode); } + +int DevReconnectInterval(DevSer *devser, int interval) { + return AsconReconnectInterval(devser->ascon, interval); +} diff --git a/devser.h b/devser.h index b91e8f51..7a927037 100644 --- a/devser.h +++ b/devser.h @@ -207,4 +207,13 @@ char *DevStatus(DevSer *devser); */ double DevGetSetTimeout(DevSer *devser, double timeout, int setmode); +/** + * \brief set reconnectInterval + * \param a the Ascon + * \param interval the interval to set (0: no reconnect, -1: read value) + * \return the value + */ +int DevReconnectInterval(DevSer *devser, int interval); + + #endif diff --git a/scriptcontext.c b/scriptcontext.c index 9befb6e5..929fb294 100644 --- a/scriptcontext.c +++ b/scriptcontext.c @@ -352,9 +352,9 @@ int SctCallInContext(SConnection * con, char *script, Hdb * node, ret = Tcl_EvalEx(pTcl, script, l, 0); result = (char *) Tcl_GetStringResult(pTcl); if (ret != TCL_OK && result[0] != '\0') { - if (strncmp(result, "ERROR:", 6) == 0) { - /* remove "ERROR:", as it will be added later */ - result += 6; + if (strncmp(result, "ERROR: ", 7) == 0) { + /* remove "ERROR: ", as it will be added later */ + result += 7; if (result[0] == ' ') { result++; } @@ -1378,6 +1378,13 @@ typedef struct SctTransact { SctController *controller; } SctTransact, *pSctTransact; +static char * SctTransactInfo(void *d) +{ + SctTransact *st = d; + return strdup(st->command); +} + + static void KillSctTransact(void *data) { pSctTransact self = (pSctTransact) data; @@ -1480,7 +1487,7 @@ static int SctTransactCmd(pSICSOBJ ccmd, SConnection * con, st->reply = NULL; DevQueue(c->devser, st, WritePRIO, - TransactionHandler, SctTransactMatch, NULL, NULL); + TransactionHandler, SctTransactMatch, NULL, SctTransactInfo); while (st->sent != 2) { TaskYield(pServ->pTasker); } @@ -1520,7 +1527,7 @@ static int SctSendCmd(pSICSOBJ ccmd, SConnection * con, SetHdbProperty(c->node, "reply", ""); DevQueue(c->devser, st, prio, - SendHandler, SctTransactMatch, KillSctTransact, NULL); + SendHandler, SctTransactMatch, KillSctTransact, SctTransactInfo); return 1; } @@ -1539,8 +1546,14 @@ static int SctReconnect(pSICSOBJ ccmd, SConnection * con, { SctController *c; char *reconnectScript, *result; + char *hostport; c = (SctController *) ccmd->pPrivate; + hostport = ParText(cmdNode, "hostport", nPar, ""); + if (strcmp(hostport, "unconnected") == 0) { + DevDisconnect(c->devser); + return 1; + } DevReconnect(c->devser, ParText(cmdNode, "hostport", nPar, "")); reconnectScript = GetProp(c->node, c->node, "reconnect_script"); if (reconnectScript && reconnectScript[0] != '\0') { @@ -1614,6 +1627,25 @@ static int SctTimeout(pSICSOBJ ccmd, SConnection * con, return 1; } +static int SctReconnectInterval(pSICSOBJ ccmd, SConnection * con, + Hdb * cmdNode, Hdb * par[], int nPar) +{ + SctController *c; + char *result; + hdbValue *v = &cmdNode->child->value; + int interval; + + c = (SctController *) ccmd->pPrivate; + if (nPar == 0) { + interval = -1; /* read only */ + } else { + interval = v->v.intValue; + } + v->v.intValue = DevReconnectInterval(c->devser, interval); + SCPrintf(con, eValue, "%d", v->v.intValue); + return 1; +} + static int SctStatus(pSICSOBJ ccmd, SConnection * con, Hdb * cmdNode, Hdb * par[], int nPar) { @@ -1850,6 +1882,10 @@ static int SctMakeController(SConnection * con, SicsInterp * sics, "timeout", usSpy, MakeSICSFunc(SctTimeout)); AddSICSHdbPar(cmd, "value", usUser, MakeHdbFloat(-1.0)); + cmd = AddSICSHdbPar(controller->node, + "reconnectinterval", usSpy, MakeSICSFunc(SctReconnectInterval)); + AddSICSHdbPar(cmd, "value", usUser, MakeHdbInt(-1)); + /* get the actual timeout value */ SctTimeout(ccmd, con, cmd, &par, 0);