- added new scriptcontext with devser
This commit is contained in:
22
ascon.c
22
ascon.c
@ -52,7 +52,9 @@ static int CreateSocketAdress(
|
||||
|
||||
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 micro)
|
||||
*/
|
||||
gettimeofday(&now, NULL);
|
||||
return now.tv_sec + now.tv_usec / 1e6;
|
||||
}
|
||||
@ -128,6 +130,7 @@ void AsconStdInit(Ascon *a, char *hostport) {
|
||||
a->fd = -1;
|
||||
a->state = AsconConnectStart;
|
||||
a->timeout = 2.0; /* sec */
|
||||
a->reconnectInterval = 10;
|
||||
a->hostport = strdup(hostport);
|
||||
}
|
||||
|
||||
@ -399,6 +402,9 @@ Ascon *AsconMake(SConnection *con, int argc, char *argv[]) {
|
||||
a->wrBuffer = CreateDynString(60, 63);
|
||||
a->errList.head = NULL;
|
||||
a->responseValid = 0;
|
||||
a->timeout = 2.0;
|
||||
a->reconnectInterval = 10;
|
||||
a->lastReconnect = 0;
|
||||
return a;
|
||||
}
|
||||
|
||||
@ -416,9 +422,10 @@ void AsconKill(Ascon *a) {
|
||||
free(a);
|
||||
}
|
||||
|
||||
AsconStatus AsconTask(Ascon *a) {
|
||||
a->handler(a);
|
||||
while (1) {
|
||||
AsconStatus AsconTask(Ascon *a) {
|
||||
double now;
|
||||
|
||||
while (a->handler(a)) {
|
||||
switch (a->state) {
|
||||
case AsconReading:
|
||||
case AsconWriting:
|
||||
@ -448,6 +455,11 @@ AsconStatus AsconTask(Ascon *a) {
|
||||
return AsconPending;
|
||||
case AsconFailed:
|
||||
if (a->state <= AsconConnectFailed) {
|
||||
now = DoubleTime();
|
||||
if (now > a->lastReconnect + a->reconnectInterval) {
|
||||
a->lastReconnect = now;
|
||||
a->state = AsconConnectStart;
|
||||
}
|
||||
return AsconUnconnected;
|
||||
}
|
||||
return AsconFailure;
|
||||
@ -458,8 +470,8 @@ AsconStatus AsconTask(Ascon *a) {
|
||||
return AsconReady;
|
||||
}
|
||||
}
|
||||
a->handler(a);
|
||||
}
|
||||
return AsconIdle;
|
||||
}
|
||||
|
||||
int AsconWrite(Ascon *a, char *command, int noResponse) {
|
||||
|
Reference in New Issue
Block a user