Continued improvements to shutdown.

This commit is contained in:
barant committed 2020-04-23 14:25:41 -07:00
1 parent b4ab5fb86a
commit 28292e924a
55 files changed
+459 -367

No files matched your search

+27 -2
View File
@@ -30,8 +30,33 @@ namespace core {
void TCPSession::onConnected() {}
void TCPSession::onDataReceived(std::string data) {
protocol(data);
void TCPSession::onDataReceived(char *data, int len) {
if(len > 0) {
lineBuffer = (char *)realloc(lineBuffer, lineBufferSize + len);
memcpy(lineBuffer + lineBufferSize, data, len);
lineBufferSize += len;
while(lineBufferSize > 0) {
int lineLength = strcspn(lineBuffer, "\r\n");
if(lineLength == lineBufferSize)
break;
onLineReceived(std::string(lineBuffer, lineLength));
if(lineBuffer[lineLength] == '\r')
++lineLength;
if(lineBuffer[lineLength] == '\n')
++lineLength;
lineBufferSize -= lineLength;
if(lineBufferSize > 0)
memmove(lineBuffer, lineBuffer + lineLength, lineBufferSize);
coreutils::Log(coreutils::LOG_DEBUG_3) << "lineBufferSize=" << lineBufferSize << "; lineLength=" << lineLength << ";";
lineBuffer = (char *)realloc(lineBuffer, lineBufferSize);
// coreutils::Log(coreutils::LOG_DEBUG_3) << "lineBuffer=" << std::string(lineBuffer, lineBufferSize);
}
}
}
void TCPSession::onLineReceived(std::string line) {
coreutils::Log(coreutils::LOG_DEBUG_3) << "[" << line << "]";
protocol(line);
send();
}