From 6bde215bbe9d0b288189ac3b5ad935c0fdf2cec2 Mon Sep 17 00:00:00 2001 From: krivoshein Date: Thu, 26 Feb 2026 17:58:05 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=D0=B5?= =?UTF-8?q?=D1=82=20=D1=81=D0=BE=D0=BA=D0=B5=D1=82=20=D1=81=D1=82=D1=80?= =?UTF-8?q?=D0=B8=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Core/recognizesystem.cpp | 46 +++++++++++++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 10 deletions(-) diff --git a/Core/recognizesystem.cpp b/Core/recognizesystem.cpp index 55f82df..72e7095 100644 --- a/Core/recognizesystem.cpp +++ b/Core/recognizesystem.cpp @@ -31,8 +31,20 @@ void RecognizeSystem::recognize(QTcpSocket *socket) QDataStream stream(socket); stream.setVersion(QDataStream::Qt_DefaultCompiledVersion); - while(socket->bytesAvailable()) + int cntBytesAvl = 0; + while((cntBytesAvl = socket->bytesAvailable()) > 0) { + + /* + if(cntBytesAvl < 4) + { + //if(!socket->waitForReadyRead(TCP_READ_TIMEOUT)) + //return; + socket->waitForReadyRead(TCP_READ_TIMEOUT); + continue; + } + */ + if (socket->state() != QTcpSocket::ConnectedState) { qDebug() << "RecognizeSystem::recognize socket->state() != QTcpSocket::ConnectedState"; @@ -45,10 +57,7 @@ void RecognizeSystem::recognize(QTcpSocket *socket) continue; } */ - - switch ((int)packetType) - { - case PacketType::TYPE_NONE: //определение первичного пакета + if(packetType == PacketType::TYPE_NONE) //определение первичного пакета { stream.startTransaction(); stream >> packetType; @@ -59,9 +68,15 @@ void RecognizeSystem::recognize(QTcpSocket *socket) continue; } //qDebug() << Tools::GetTime() << "CLIENT: type: " << packetType; + if(packetType == PacketType::TYPE_FILE) + socket->waitForReadyRead(10); + else + socket->waitForReadyRead(100); } - continue; + //continue; + switch ((int)packetType) + { case PacketType::TYPE_FOLDER: //создание папок { stream.startTransaction(); @@ -69,6 +84,7 @@ void RecognizeSystem::recognize(QTcpSocket *socket) if(!stream.commitTransaction()) { + socket->waitForReadyRead(TCP_READ_TIMEOUT); continue; } @@ -100,6 +116,7 @@ void RecognizeSystem::recognize(QTcpSocket *socket) if(!stream.commitTransaction()) { emit sigSendDebugLog(Tools::getTime() + "CLIENT: filePath, fileSize - FAIL commitTransaction"); + socket->waitForReadyRead(TCP_READ_TIMEOUT); continue; } @@ -108,7 +125,7 @@ void RecognizeSystem::recognize(QTcpSocket *socket) emit sigSendDebugLog("CLIENT: filesize: " + QString::number(fileSize)); emit sigSendDebugLog("CLIENT: filePath: " + filePath); - //socket->waitForReadyRead(100); + socket->waitForReadyRead(10); break; } @@ -123,7 +140,7 @@ void RecognizeSystem::recognize(QTcpSocket *socket) file.remove(); //удаление файла, если он уже есть, но необходимо обновить emit sigSendDebugLog(Tools::getTime() + "Delete exist file: " + filePath); - //socket->waitForReadyRead(100); + //socket->waitForReadyRead(10); } tmpBlock.clear(); @@ -140,12 +157,16 @@ void RecognizeSystem::recognize(QTcpSocket *socket) while(true) { + if(socket->bytesAvailable() <= 0) { - socket->waitForReadyRead(TCP_READ_TIMEOUT); + socket->waitForReadyRead(10); continue; } + //if(!socket->waitForReadyRead(TCP_READ_TIMEOUT)) + //continue; + if(fileSize - sizeReceiveData >= BLOCK_SIZE) tmpBlock = socket->read(BLOCK_SIZE); else @@ -155,7 +176,7 @@ void RecognizeSystem::recognize(QTcpSocket *socket) if(bytesReceived <= 0) { - QMessageBox::critical(nullptr, "P3", "bytesReceived <= 0. File: " + file.fileName()); + //QMessageBox::critical(nullptr, "P3", "bytesReceived <= 0. File: " + file.fileName()); continue; } @@ -207,6 +228,7 @@ void RecognizeSystem::recognize(QTcpSocket *socket) if(!stream.commitTransaction()) { + socket->waitForReadyRead(TCP_READ_TIMEOUT); continue; } @@ -248,6 +270,7 @@ void RecognizeSystem::recognize(QTcpSocket *socket) if(!stream.commitTransaction()) { + socket->waitForReadyRead(TCP_READ_TIMEOUT); continue; } @@ -263,6 +286,7 @@ void RecognizeSystem::recognize(QTcpSocket *socket) if(!stream.commitTransaction()) { + socket->waitForReadyRead(TCP_READ_TIMEOUT); continue; } @@ -315,6 +339,8 @@ void RecognizeSystem::recognize(QTcpSocket *socket) qCritical() << "RecognizeSystem::recognize packetType unknown!"; } + //socket->waitForReadyRead(10); + packetType = PacketType::TYPE_NONE; } }