瀏覽代碼

HPCC-22490 CStreamLineReader returns eof even if data returned

Signed-off-by: Shamser Ahmed <shamser.ahmed@lexisnexis.co.uk>
Shamser Ahmed 6 年之前
父節點
當前提交
e00cbdc926
共有 3 個文件被更改,包括 32 次插入46 次删除
  1. 2 7
      esp/services/ws_workunits/ws_workunitsHelpers.cpp
  2. 9 28
      system/jlib/jio.cpp
  3. 21 11
      testing/unittests/jlibtests.cpp

+ 2 - 7
esp/services/ws_workunits/ws_workunitsHelpers.cpp

@@ -1910,7 +1910,6 @@ void WsWuInfo::getWorkunitEclAgentLog(const char* fileName, const char* agentPid
     }
 
     StringBuffer line;
-    bool eof = false;
     bool wuidFound = false;
 
     StringBuffer pidstr;
@@ -1931,10 +1930,8 @@ void WsWuInfo::getWorkunitEclAgentLog(const char* fileName, const char* agentPid
     char const * pidchars = pidstr.str();
     size32_t pidLen = pidstr.length();
     unsigned pidOffset = 0;//offset of PID in logfile entry
-    while(!eof)
+    while(!lineReader->readLine(line.clear()))
     {
-        eof = lineReader->readLine(line.clear());
-
         //Retain all rows that match a unique program instance - by retaining all rows that match a pid
         const char * pPid = strstr(line.str() + pidOffset, pidchars);
         if (pPid)
@@ -2063,7 +2060,6 @@ void WsWuInfo::readWorkunitLog(IFile* sourceFile, MemoryBuffer& buf, const char*
     VStringBuffer startwuid("Started wuid=%s", wuid.str());
     VStringBuffer endwuid("Finished wuid=%s", wuid.str());
 
-    bool eof = false;
     bool outputThisLine = false;
     unsigned processID = 0;
     StringBuffer line;
@@ -2076,9 +2072,8 @@ void WsWuInfo::readWorkunitLog(IFile* sourceFile, MemoryBuffer& buf, const char*
     }
 
     Owned<IStreamLineReader> lineReader = createLineReader(ios, true);
-    while (!eof)
+    while (!lineReader->readLine(line.clear()))
     {
-        eof = lineReader->readLine(line.clear());
         if (outputThisLine)
         {
             //If the slave is restarted before WU is finished, we cannot find out the "Finished wuid=...".

+ 9 - 28
system/jlib/jio.cpp

@@ -1387,42 +1387,23 @@ public:
                 {
                     ++currentPtr;
                     out.append(currentPtr-startPtr-(preserveEols?0:1), startPtr);
-                    if (currentPtr == endPtr)
-                        return !refill();
                     return false;
                 }
                 case '\r':
                 {
                     ++currentPtr;
-                    // check for \n
-                    if (currentPtr < endPtr)
-                    {
-                        if ('\n' == *currentPtr) // i.e. \r\n
-                        {
-                            ++currentPtr;
-                            out.append(currentPtr-startPtr-(preserveEols?0:2), startPtr);
-                        }
-                        else // i.e. \r only
-                            out.append(currentPtr-startPtr-(preserveEols?0:1), startPtr);
-                        if (currentPtr == endPtr)
-                            return !refill();
-                        return false;
-                    }
-                    else // must output what we have and read 1 more byte to check for \n
-                    {
-                        out.append(currentPtr-startPtr-(preserveEols?0:1), startPtr);
-                        if (!refill())
-                            return true;
-                        else if ('\n' != *currentPtr)
-                            return false;
-                        ++currentPtr;
+                    out.append(currentPtr-startPtr-(preserveEols?0:1), startPtr);
 
+                    // Check for '\n'
+                    if (currentPtr == endPtr)
+                        refill();
+                    if (currentPtr < endPtr && '\n' == *currentPtr)
+                    {
                         if (preserveEols)
                             out.append('\n');
-
-                        // it's possible that refill found 1 char (the \n), if so, we have now hit eos
-                        return currentPtr == endPtr; // condition is same as eos
+                        ++currentPtr;
                     }
+                    return false;
                 }
                 default:
                 {
@@ -1431,7 +1412,7 @@ public:
                     {
                         out.append(currentPtr-startPtr, startPtr); // output what we have so far
                         if (!refill())
-                            return true;
+                            return false;
                     }
                     break;
                 }

+ 21 - 11
testing/unittests/jlibtests.cpp

@@ -1692,7 +1692,7 @@ public:
             {
                 const char *testTxt = " : Some random text for test line";
                 OwnedIFile iFile = createIFile("JlibIOTest.txt");
-                CRC32 writeCrc;
+                CRC32 writeCrc, readCrc;
                 {
                     OwnedIFileIO iFileIO = iFile->open(IFOcreate);
                     OwnedIFileIOStream stream = createIOStream(iFileIO);
@@ -1708,24 +1708,34 @@ public:
                     OwnedIFileIO iFileIO = iFile->open(IFOread);
                     OwnedIFileIOStream stream = createIOStream(iFileIO); // NB: unbuffered
                     Owned<IStreamLineReader> lineReader = createLineReader(stream, 0==pEol, strlen(testTxt)); // NB: deliberately make chunkSize small so will end up having to read more
-                    CRC32 crc;
                     while (true)
                     {
                         StringBuffer line;
-                        bool eos = lineReader->readLine(line);
-                        CPPUNIT_ASSERT(line.length() != 0);
+                        if (!lineReader->readLine(line))
+                        {
     #ifdef _DEBUG
-                        printf("%s\n", line.str());
+                            printf("JlibIOTest::test readLines");
+                            for(const char *p = line.str(); *p; ++p)
+                            {
+                                switch(*p)
+                                {
+                                case '\n': printf("\\n"); break;
+                                case '\t': printf("\\t"); break;
+                                case '\r': printf("\\r"); break;
+                                default: putchar(*p);break;
+                                }
+                            }
+                            putchar('\n');
     #endif
-                        if (pEol != 0)
-                            line.append(newlines[nl]);
-
-                        crc.tally(line.length(), line.str());
-                        if (eos)
+                            if (pEol==1)
+                                line.append(newlines[nl]);
+                            readCrc.tally(line.length(), line.str());
+                        }
+                        else 
                             break;
                     }
-                    CPPUNIT_ASSERT(writeCrc.get() == crc.get());
                 }
+                CPPUNIT_ASSERT(writeCrc.get() == readCrc.get());
             }
         }
     }