mirror of
https://gitea.msk.dinamika-avia.ru/Constanta-Design/RRJClient.git
synced 2026-03-28 05:25:39 +03:00
Работает сокет стрим
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user