Changeset 701


Ignore:
Timestamp:
Mar 18, 2010, 3:54:07 PM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

tools/assistant: Fixed: Would only recognize the first of two or more commands read in one batch in remote control mode [kind of vendor bug].

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified trunk/tools/assistant/tools/assistant/remotecontrol.cpp

    r651 r701  
    7979{
    8080    char chBuf[4096];
     81    size_t pos = 0;
    8182    ULONG ulRead;
    8283
     
    8687
    8788    while (arc == NO_ERROR) {
    88         arc = DosRead(hStdinDup, chBuf, sizeof(chBuf), &ulRead);
    89         if (arc == NO_ERROR && ulRead != 0)
    90             emit receivedCommand(QString::fromLocal8Bit(chBuf));
     89        arc = DosRead(hStdinDup, chBuf + pos, sizeof(chBuf) - pos, &ulRead);
     90        if (arc == NO_ERROR && ulRead != 0) {
     91            size_t totalRead = pos + ulRead;
     92            size_t len = ulRead;
     93            char *start = chBuf, *zero = chBuf + pos;
     94            // send all complete commands
     95            while (len && (zero = static_cast<char *>(memchr(zero, '\0', len)))) {
     96                emit receivedCommand(QString::fromLocal8Bit(start));
     97                start = ++zero;
     98                len = totalRead - (start - chBuf);
     99            }
     100            if (start != chBuf) {
     101                // move the incomplete portion to the beginning
     102                memcpy(chBuf, start, len);
     103                pos = len;
     104            } else {
     105                pos = totalRead;
     106                if (pos == sizeof(chBuf)) {
     107                    // buffer full, emit the command anyway and start over
     108                    QByteArray cmd(chBuf, sizeof(chBuf));
     109                    emit receivedCommand(QString::fromLocal8Bit(cmd));
     110                    pos = 0;
     111                }
     112            }
     113        }
    91114    }
    92115
     
    118141    hStdinDup = stdin;
    119142#endif
     143
     144    // ### do the same as in the OS/2 version above
    120145
    121146    while (ok) {
Note: See TracChangeset for help on using the changeset viewer.