This lets us re-use the astvel protovol to support SICS-601 so that HTTP connections will reconnect after the connection times out.
51 lines
980 B
C
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);
|
|
}
|