Run ghttp_process in async mode, call TaskYield and add an abort action
This commit is contained in:
@@ -79,12 +79,48 @@ typedef struct {
|
|||||||
pICallBack pCall;
|
pICallBack pCall;
|
||||||
}anstoHttp, *pAnstoHttp;
|
}anstoHttp, *pAnstoHttp;
|
||||||
/*------------------------------------------------------------------*/
|
/*------------------------------------------------------------------*/
|
||||||
|
static ghttp_status anstoLocalProcess(pAnstoHttp self) {
|
||||||
|
ghttp_status httpStatus;
|
||||||
|
pTaskMan pTasker = GetTasker();
|
||||||
|
if(self->asyncRunning) {
|
||||||
|
httpStatus = ghttp_process(self->syncRequest);
|
||||||
|
/*
|
||||||
|
* Service other SICS tasks while we wait,
|
||||||
|
* but do not run the taskloop during initialisation
|
||||||
|
*/
|
||||||
|
if (pTasker == NULL)
|
||||||
|
pTasker = GetTasker();
|
||||||
|
if (pTasker && (pServ->dummyCon != NULL))
|
||||||
|
TaskYield(pTasker);
|
||||||
|
return httpStatus;
|
||||||
|
} else {
|
||||||
|
ghttp_set_sync(self->syncRequest, ghttp_async);
|
||||||
|
do {
|
||||||
|
httpStatus = ghttp_process(self->syncRequest);
|
||||||
|
|
||||||
|
if (httpStatus != ghttp_not_done)
|
||||||
|
break;
|
||||||
|
/*
|
||||||
|
* Service other SICS tasks while we wait,
|
||||||
|
* but do not run the taskloop during initialisation
|
||||||
|
*/
|
||||||
|
if (pTasker == NULL)
|
||||||
|
pTasker = GetTasker();
|
||||||
|
if (pTasker && (pServ->dummyCon != NULL))
|
||||||
|
TaskYield(pTasker);
|
||||||
|
} while(1);
|
||||||
|
|
||||||
|
ghttp_set_sync(self->syncRequest, ghttp_sync);
|
||||||
|
return httpStatus;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*------------------------------------------------------------------*/
|
||||||
static int anstoHttpGetPrepare(pAnstoHttp self, char *request){
|
static int anstoHttpGetPrepare(pAnstoHttp self, char *request){
|
||||||
char url[512];
|
char url[512];
|
||||||
ghttp_status httpStatus;
|
ghttp_status httpStatus;
|
||||||
|
|
||||||
if(self->asyncRunning){
|
if(self->asyncRunning){
|
||||||
while((httpStatus = ghttp_process(self->syncRequest))
|
while((httpStatus = anstoLocalProcess(self))
|
||||||
== ghttp_not_done){
|
== ghttp_not_done){
|
||||||
}
|
}
|
||||||
self->asyncRunning = 0;
|
self->asyncRunning = 0;
|
||||||
@@ -147,13 +183,13 @@ static int anstoHttpGet(pAnstoHttp self, char *request){
|
|||||||
* try two times: a reconnect is no error
|
* try two times: a reconnect is no error
|
||||||
*/
|
*/
|
||||||
ghttp_prepare(self->syncRequest);
|
ghttp_prepare(self->syncRequest);
|
||||||
httpStatus = ghttp_process(self->syncRequest);
|
httpStatus = anstoLocalProcess(self);
|
||||||
if(httpStatus != ghttp_done){
|
if(httpStatus != ghttp_done){
|
||||||
ghttp_close(self->syncRequest);
|
ghttp_close(self->syncRequest);
|
||||||
if (!anstoHttpGetPrepare(self,request))
|
if (!anstoHttpGetPrepare(self,request))
|
||||||
return 0; // MJL return here if failed
|
return 0; // MJL return here if failed
|
||||||
ghttp_prepare(self->syncRequest); // MJL be sure to call ghttp_prepare before each ghttp_process
|
ghttp_prepare(self->syncRequest); // MJL be sure to call ghttp_prepare before each ghttp_process
|
||||||
httpStatus = ghttp_process(self->syncRequest);
|
httpStatus = anstoLocalProcess(self);
|
||||||
}
|
}
|
||||||
if(httpStatus != ghttp_done){
|
if(httpStatus != ghttp_done){
|
||||||
strncpy(self->hmError,"Reconnect", 511);
|
strncpy(self->hmError,"Reconnect", 511);
|
||||||
@@ -254,7 +290,7 @@ static int AnstoHttpConfigure(pHistDriver self, SConnection *pCon,
|
|||||||
pPriv->passWord);
|
pPriv->passWord);
|
||||||
ghttp_set_sync(pPriv->syncRequest,ghttp_sync);
|
ghttp_set_sync(pPriv->syncRequest,ghttp_sync);
|
||||||
status = ghttp_prepare(pPriv->syncRequest);
|
status = ghttp_prepare(pPriv->syncRequest);
|
||||||
httpStatus = ghttp_process(pPriv->syncRequest);
|
httpStatus = anstoLocalProcess(pPriv);
|
||||||
confData = (char *)ghttp_get_body(pPriv->syncRequest);
|
confData = (char *)ghttp_get_body(pPriv->syncRequest);
|
||||||
if(httpStatus != ghttp_done){
|
if(httpStatus != ghttp_done){
|
||||||
/* we may need to reconnect.....
|
/* we may need to reconnect.....
|
||||||
@@ -409,14 +445,14 @@ static int AnstoHttpStatus_Base(pHistDriver self,SConnection *pCon,int *pextrast
|
|||||||
}
|
}
|
||||||
pPriv->asyncRunning = 1;
|
pPriv->asyncRunning = 1;
|
||||||
}
|
}
|
||||||
httpStatus = ghttp_process(pPriv->syncRequest);
|
httpStatus = anstoLocalProcess(pPriv);
|
||||||
switch(httpStatus){
|
switch(httpStatus){
|
||||||
case ghttp_error:
|
case ghttp_error:
|
||||||
ghttp_close(pPriv->syncRequest);
|
ghttp_close(pPriv->syncRequest);
|
||||||
pPriv->asyncRunning = 0; // MJL bug fix 9/03/07 moved by DFC
|
pPriv->asyncRunning = 0; // MJL bug fix 9/03/07 moved by DFC
|
||||||
anstoHttpGetPrepare(pPriv,statusdaq);
|
anstoHttpGetPrepare(pPriv,statusdaq);
|
||||||
ghttp_prepare(pPriv->syncRequest);
|
ghttp_prepare(pPriv->syncRequest);
|
||||||
httpStatus = ghttp_process(pPriv->syncRequest);
|
httpStatus = anstoLocalProcess(pPriv);
|
||||||
if(httpStatus != ghttp_done){
|
if(httpStatus != ghttp_done){
|
||||||
strncpy(pPriv->hmError,"Reconnect", 511);
|
strncpy(pPriv->hmError,"Reconnect", 511);
|
||||||
pPriv->errorCode = SERVERERROR;
|
pPriv->errorCode = SERVERERROR;
|
||||||
@@ -991,6 +1027,16 @@ pHistDriver CreateAnstoHttpDriver(pStringDict pOption){
|
|||||||
SCSendOK(pCon);
|
SCSendOK(pCon);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
if(strcmp(argv[1],"abort") == 0) {
|
||||||
|
pAnstoHttp pPriv = NULL;
|
||||||
|
if(!SCMatchRights(pCon,usUser)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
pPriv = (pAnstoHttp)self->pDriv->pPriv;
|
||||||
|
ghttp_close(pPriv->syncRequest);
|
||||||
|
SCSendOK(pCon);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
return HistAction(pCon, pSics, pData, argc, argv);
|
return HistAction(pCon, pSics, pData, argc, argv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user