Files
sics/site_ansto/hardsup/sct_velselprot.c
Ferdi Franceschini c09968b72e Attempt a reconnect for astvels protocol if a command times out.
This lets us re-use the astvel protovol to support SICS-601 so that HTTP
connections will reconnect after the connection times out.
2013-05-05 21:19:05 +10:00

51 lines
980 B
C

#include <errno.h>
#include <ascon.h>
#include <ascon.i>
#include <dynstring.h>
int VelSelReading(Ascon *a)
{
int ret;
char chr=0;
ret = AsconReadChar(a->fd, &chr);
if (chr == 0) {
if (a->timeout > 0) {
if (DoubleTime() - a->start > a->timeout) {
AsconError(a, "read timeout", 0);
}
}
return 0;
}
DynStringConcatChar(a->rdBuffer, chr);
while ((ret = AsconReadChar(a->fd, &chr)) > 0) {
DynStringConcatChar(a->rdBuffer, chr);
}
a->state = AsconReadDone;
DynStringConcatChar(a->rdBuffer, '\0');
return 0;
}
int VelSelProtHandler(Ascon *a)
{
int ret;
switch(a->state){
case AsconReading:
return VelSelReading(a);
break;
default:
return AsconStdHandler(a);
}
}
void AddVelSelProtocol()
{
AsconProtocol *prot = NULL;
prot = calloc(sizeof(AsconProtocol), 1);
prot->name = strdup("astvelsel");
prot->init = AsconStdInit;
prot->handler = VelSelProtHandler;
AsconInsertProtocol(prot);
}