Got it compiling and somewhat working, except post.
This commit is contained in:
1 parent
7ee13e87d2
commit
bcea21cf96
12 files changed
+373
-133
No files matched your search
+28
-33
@@ -33,46 +33,41 @@ namespace core {
|
||||
|
||||
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) {
|
||||
switch(mode) {
|
||||
case LINE:
|
||||
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);
|
||||
lineBuffer = (char *)realloc(lineBuffer, lineBufferSize);
|
||||
break;
|
||||
case BLOCK:
|
||||
if(lineBufferSize >= blockLength) {
|
||||
onBlockReceived(std::string(lineBuffer, blockLength));
|
||||
lineBufferSize -= blockLength;
|
||||
if(lineBufferSize > 0)
|
||||
memmove(lineBuffer, lineBuffer + blockLength, lineBufferSize);
|
||||
lineBuffer = (char *)realloc(lineBuffer, lineBufferSize);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
lineBuffer = (char *)realloc(lineBuffer, lineBufferSize + len);
|
||||
memcpy(lineBuffer + lineBufferSize, data, len);
|
||||
lineBufferSize += len;
|
||||
while(lineBufferSize > 0) {
|
||||
if(blockSize == 0) {
|
||||
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);
|
||||
lineBuffer = (char *)realloc(lineBuffer, lineBufferSize);
|
||||
} else {
|
||||
if(lineBufferSize >= blockLength) {
|
||||
onBlockReceived(std::string(lineBuffer, blockLength));
|
||||
lineBufferSize -= blockLength;
|
||||
if(lineBufferSize > 0)
|
||||
memmove(lineBuffer, lineBuffer + blockLength, lineBufferSize);
|
||||
lineBuffer = (char *)realloc(lineBuffer, lineBufferSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TCPSession::setMode(core::Mode mode, int blockSize) {
|
||||
this->mode = mode;
|
||||
void TCPSession::setBlockSize(int blockSize) {
|
||||
this->blockSize = blockSize;
|
||||
}
|
||||
|
||||
void TCPSession::onLineReceived(std::string line) {
|
||||
coreutils::Log(coreutils::LOG_DEBUG_3) << "[" << line << "]";
|
||||
protocol(line);
|
||||
send();
|
||||
if(term)
|
||||
|
||||
Reference in new issue
Block a user