- make reconnectInterval changeable (0: no automatic reconnection)
This commit is contained in:
9
ascon.c
9
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;
|
||||
}
|
||||
|
8
ascon.h
8
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
|
||||
|
6
devser.c
6
devser.c
@ -265,6 +265,8 @@ static int DevQueueTask(void *ds)
|
||||
if(replyData != NULL){
|
||||
LogResponse(devser,0);
|
||||
}
|
||||
} else if (devser->status == AsconOffline) {
|
||||
replyData = "ASCERR: offline";
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
@ -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);
|
||||
}
|
||||
|
9
devser.h
9
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
|
||||
|
@ -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) {
|
||||
if (strncmp(result, "ERROR: ", 7) == 0) {
|
||||
/* remove "ERROR: ", as it will be added later */
|
||||
result += 6;
|
||||
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);
|
||||
|
||||
|
Reference in New Issue
Block a user