It works!!!
This commit is contained in:
1 parent
20d5c99517
commit
b7398afc05
16 files changed
+160
-197
No files matched your search
+36
-35
@@ -14,7 +14,7 @@ namespace core {
|
||||
data << "|" << ipAddress.getClientAddressAndPort();
|
||||
}
|
||||
|
||||
void TCPSession::protocol(coreutils::ZString data) {
|
||||
void TCPSession::protocol(coreutils::ZString &data) {
|
||||
if(!server.commands.processRequest(data, *this))
|
||||
if(data.getLength() != 0)
|
||||
server.sessionErrorHandler("Invalid data received.", out);
|
||||
@@ -22,7 +22,8 @@ namespace core {
|
||||
|
||||
void TCPSession::onRegistered() {
|
||||
onConnected();
|
||||
protocol(coreutils::ZString(""));
|
||||
coreutils::ZString nothing("");
|
||||
protocol(nothing);
|
||||
send();
|
||||
if(term)
|
||||
shutdown("termination requested");
|
||||
@@ -30,50 +31,50 @@ namespace core {
|
||||
|
||||
void TCPSession::onConnected() {}
|
||||
|
||||
void TCPSession::onDataReceived(coreutils::ZString data) {
|
||||
void TCPSession::onDataReceived(coreutils::ZString &data) {
|
||||
if(data.getLength() > 0) {
|
||||
lineBuffer = (char *)realloc(lineBuffer, lineBufferSize + data.getLength());
|
||||
memcpy(lineBuffer + lineBufferSize, data.getData(), data.getLength());
|
||||
lineBufferSize += data.getLength();
|
||||
while(lineBufferSize > 0) {
|
||||
if(blockSize == 0) {
|
||||
lineLength = strcspn(lineBuffer, "\r\n");
|
||||
if(lineLength == lineBufferSize)
|
||||
break;
|
||||
onLineReceived(coreutils::ZString(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(coreutils::ZString(lineBuffer, blockLength));
|
||||
lineBufferSize -= blockLength;
|
||||
if(lineBufferSize > 0)
|
||||
memmove(lineBuffer, lineBuffer + blockLength, lineBufferSize);
|
||||
lineBuffer = (char *)realloc(lineBuffer, lineBufferSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
lineBuffer = (char *)realloc(lineBuffer, lineBufferSize + data.getLength());
|
||||
memcpy(lineBuffer + lineBufferSize, data.getData(), data.getLength());
|
||||
lineBufferSize += data.getLength();
|
||||
while(lineBufferSize > 0) {
|
||||
if(blockSize == 0) {
|
||||
lineLength = strcspn(lineBuffer, "\r\n");
|
||||
if(lineLength == lineBufferSize)
|
||||
break;
|
||||
coreutils::ZString zLine(lineBuffer, lineLength);
|
||||
onLineReceived(zLine);
|
||||
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) {
|
||||
coreutils::ZString zBlock(lineBuffer, blockLength);
|
||||
onBlockReceived(zBlock);
|
||||
lineBufferSize -= blockLength;
|
||||
if(lineBufferSize > 0)
|
||||
memmove(lineBuffer, lineBuffer + blockLength, lineBufferSize);
|
||||
lineBuffer = (char *)realloc(lineBuffer, lineBufferSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void TCPSession::setBlockSize(int blockSize) {
|
||||
this->blockSize = blockSize;
|
||||
}
|
||||
|
||||
void TCPSession::onLineReceived(coreutils::ZString line) {
|
||||
|
||||
void TCPSession::onLineReceived(coreutils::ZString &line) {
|
||||
protocol(line);
|
||||
send();
|
||||
if(term)
|
||||
shutdown("termination requested");
|
||||
}
|
||||
|
||||
void TCPSession::onBlockReceived(coreutils::ZString block) {
|
||||
void TCPSession::onBlockReceived(coreutils::ZString &block) {
|
||||
coreutils::Log(coreutils::LOG_DEBUG_3) << "[" << block.getLength() << "]";
|
||||
if(term)
|
||||
shutdown("termination requested");
|
||||
|
||||
Reference in new issue
Block a user