I have forked 4 client process from parent. For testing purpose, i execute an sql query in the child process when i receive valid input.
My debug show that i received the valid string in all the child process. In most cases, PQsendquery is sent out. Epoll receives notification that postgres replied but not sure what i am doing wrong in consuming the PQResult.
Would anyone be kind enough to point to me where is my mistake. Thank you very much.
if(ttlevents[i].data.fd == pgsock)
{
while(1)
{
int rc = PQconsumeInput(conn);
if(rc != 0)
{
if(PQisBusy(conn) == 0)
{
while((result = PQgetResult(conn)) != NULL)
{
if(PQresultStatus(result) == PGRES_TUPLES_OK)
{
int nFields = PQnfields(result);
char rowdata[1024];
for(int i=0;i<PQntuples(result);i++)
{
memset(rowdata,0,sizeof(rowdata));
for(int j=0;j<nFields;j++)
{
strcat(rowdata,PQgetvalue(result,i,j));
strcat(rowdata,"|");
}
int fifo_count = cpushfd();
if(fifo_count != -1)
{
memset(cfifo[fifo_count].buffer,0,sizeof(cfifo[fifo_count].buffer));
memcpy(cfifo[fifo_count].buffer,rowdata,sizeof(rowdata));
}
}//for
}
else
{
printf("ERROR PGSOCK\n");
}
PQclear(result);
}//While
break; //THIS BREAK WAS MISPLACED AT THE BOTTOM EARLIER.
PQclear(result);
}//isBusy
}//rc!=0
}//While
write(c2p_var,stflag,sizeof stflag);
} // == pgsock