[英]Postgresql and libpq . Query getting dropped from randrom number of child processes
我從父級分叉了 4 個客戶端進程。 出於測試目的,當我收到有效輸入時,我在子進程中執行 sql 查詢。
我的調試顯示我在所有子進程中都收到了有效字符串。 在大多數情況下,PQsendquery 被發送出去。 Epoll 收到 postgres 回復的通知,但不確定我在使用 PQResult 時做錯了什么。
有沒有人能指出我的錯誤在哪里。 非常感謝。
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
上面的代碼是工作版本。 早些時候,我在外部 while 之前將底部的“中斷”放錯了位置。 現在我把它放在內部 WHILE 之后。
感謝 Laurenz Albe 的反饋。 我在進行縮進時發現了錯誤。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.