私はここで少し困っています...最初に要件から始めます:
- データ (msg) をサーバーに送信してみる
- 失敗した場合は、ローカルのハードディスク ファイルに CSV エントリのリストとして保存します。
- あらかじめ決められた時点でメッセージ データをサーバーに送信してみてください。
- メッセージが正常に送信された場合は、ファイルから削除します
- サーバーへのデータ送信が失敗するまでプロセスを続行します。ステップ 2 に進みます
私がやった事:
- fstream オブジェクトを使用して、失敗したメッセージをローカル ファイルに書き込みました
- fstream オブジェクトを使用してこのファイルから読み取り、動的に作成された std::queue に格納します
- ファイルから読み取られたメッセージごとに、それをキューにプッシュします
- すべてのメッセージをプッシュした後、std::front() を使用して最初のメッセージを取得し、それをカスタム オブジェクト データ構造に読み込みます。
問題は次のとおり です。キューにプッシュする前後に、ハードディスクファイルから読み取ったメッセージを出力します。キューをプッシュする前に、メッセージ ボックス/テキスト ファイル ログに出力するデータは問題ありません。しかし、queue:front() を取得した後に同じデータを出力すると、すべてのジャンクが出力されます。*
私はキューと STL の専門家ではないので、ガイドが必要です。
コードは次のとおりです。
class CDFCQueueMsgs
{
public:
char chDFCMsg_1;
char chDFCMsg_2;
char chDFCMsg_3;
char chDFCMsg_4;
char chDFCMsg_5;
};
// This is how I created the fstream obj to read the file
fstream_IOData_Read.open(pChPersistingFileLocation, ios::in);
// The CSVs that I write to and read back from the file are like:
// 1111222233334444,1234,05,0011123456,20100102112233,1234567890,7,N
// Given below is how I write to the file:
void CDataQueueingAndPersisting::WriteQueueMsgsToFile(char *pchAppendMsgToPersistentFile)
{
char chWriteBuffer[512] = {0};
fstream_IOData_Write.flush();
sprintf(chWriteBuffer, "%s\r\n", pchAppendMsgToPersistentFile);
if(NULL != pchAppendMsgToPersistentFile) fstream_IOData_Write.write(chWriteBuffer,strlen(chWriteBuffer));
}
// Given below is how I read from the file:
while(fstream_IOData_Read >> chSingleDFCMsg)
{
bDataRead = ReplicateQueueInProcessMemory( (BYTE*) chSingleDFCMsg);
RtlZeroMemory(chSingleDFCMsg, sizeof(chSingleDFCMsg));
}
// ReplicateQueueInProcessMemory is like:
pChDelimitedStrPtr = strtok((char *)byteSingleRawQueueMsg, ",");
// to read every comma delimited field in the single line as shown above. I use multiple strtok()s to read all the fields of the string.
// After this I get the front message in the queue:
CDFCQueueMsgs oDfcQueueMsg_TopMsg;
CDFCQueueMsgs & refDfcQueueMsg_TopMsg = oDfcQueueMsg_TopMsg;
refDfcQueueMsg_TopMsg = *oCDataQueueingAndPersisting.poDFCMsgQUEUE.front();
// Now I get the respective member fields to the object type the queue holds:
strncpy(g_chBuffer, refDfcQueueMsg_TopMsg.chDFCMsg_1, sizeof(refDfcQueueMsg_TopMsg.chDFCMsg_1));
// Now I Log the "g_chBuffer" variable in my log files. I also log each field in my logs:
/*
Before Pushing into queue, I log the string from the read buffer, the fields get logged fine like this:
09:50:45:093 EVENT: chDFCMsg_1:1111222233334444
chDFCMsg_2:1234
chDFCMsg_3:05
chDFCMsg_4:0011123456
chDFCMsg_5:20100102112233
After pushing and gettting the Queue::front() I see the same fields like this:
10:45:54:495 EVENT: 2ÃÛ¬S
10:45:54:495 EVENT: ¬S
10:45:54:495 EVENT:
á
10:45:54:495 EVENT:
10:45:54:495 EVENT:
*/
ありがとう、ダニエル