Write up to nMax characters of the prepared (by DoSrv) response lines. Returns the number of characters sent, including null. Zero returned if and only if there's nothing else to send.
| 101 | // Returns the number of characters sent, including null. |
| 102 | // Zero returned if and only if there's nothing else to send. |
| 103 | int DoSrvMore(char *pOut, size_t nMax) |
| 104 | { |
| 105 | wxASSERT(currentLine >= 0); |
| 106 | wxASSERT(currentPosition >= 0); |
| 107 | |
| 108 | size_t totalLines = aStr.GetCount(); |
| 109 | while (currentLine < totalLines) |
| 110 | { |
| 111 | wxCharBuffer lineString = aStr[currentLine].ToUTF8(); |
| 112 | size_t lineLength = lineString.length(); |
| 113 | size_t charsLeftInLine = lineLength - currentPosition; |
| 114 | |
| 115 | wxASSERT(charsLeftInLine >= 0); |
| 116 | |
| 117 | if (charsLeftInLine == 0) |
| 118 | { |
| 119 | // Move to next line |
| 120 | ++currentLine; |
| 121 | currentPosition = 0; |
| 122 | } |
| 123 | else |
| 124 | { |
| 125 | // Write as much of the rest of the line as will fit in the buffer |
| 126 | size_t charsToWrite = smin(charsLeftInLine, nMax - 1); |
| 127 | memcpy(pOut, |
| 128 | &(lineString.data()[currentPosition]), |
| 129 | charsToWrite); |
| 130 | pOut[charsToWrite] = '\0'; |
| 131 | currentPosition += charsToWrite; |
| 132 | // Need to cast to prevent compiler warnings |
| 133 | int charsWritten = static_cast<int>(charsToWrite + 1); |
| 134 | // (Check cast was safe) |
| 135 | wxASSERT(static_cast<size_t>(charsWritten) == charsToWrite + 1); |
| 136 | return charsWritten; |
| 137 | } |
| 138 | } |
| 139 | return 0; |
| 140 | } |
| 141 | |
| 142 | } // End extern "C" |
no test coverage detected