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);
|
QDataStream stream(socket);
|
||||||
stream.setVersion(QDataStream::Qt_DefaultCompiledVersion);
|
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)
|
if (socket->state() != QTcpSocket::ConnectedState)
|
||||||
{
|
{
|
||||||
qDebug() << "RecognizeSystem::recognize socket->state() != QTcpSocket::ConnectedState";
|
qDebug() << "RecognizeSystem::recognize socket->state() != QTcpSocket::ConnectedState";
|
||||||
@@ -45,10 +57,7 @@ void RecognizeSystem::recognize(QTcpSocket *socket)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
if(packetType == PacketType::TYPE_NONE) //определение первичного пакета
|
||||||
switch ((int)packetType)
|
|
||||||
{
|
|
||||||
case PacketType::TYPE_NONE: //определение первичного пакета
|
|
||||||
{
|
{
|
||||||
stream.startTransaction();
|
stream.startTransaction();
|
||||||
stream >> packetType;
|
stream >> packetType;
|
||||||
@@ -59,9 +68,15 @@ void RecognizeSystem::recognize(QTcpSocket *socket)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
//qDebug() << Tools::GetTime() << "CLIENT: type: " << packetType;
|
//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: //создание папок
|
case PacketType::TYPE_FOLDER: //создание папок
|
||||||
{
|
{
|
||||||
stream.startTransaction();
|
stream.startTransaction();
|
||||||
@@ -69,6 +84,7 @@ void RecognizeSystem::recognize(QTcpSocket *socket)
|
|||||||
|
|
||||||
if(!stream.commitTransaction())
|
if(!stream.commitTransaction())
|
||||||
{
|
{
|
||||||
|
socket->waitForReadyRead(TCP_READ_TIMEOUT);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,6 +116,7 @@ void RecognizeSystem::recognize(QTcpSocket *socket)
|
|||||||
if(!stream.commitTransaction())
|
if(!stream.commitTransaction())
|
||||||
{
|
{
|
||||||
emit sigSendDebugLog(Tools::getTime() + "CLIENT: filePath, fileSize - FAIL commitTransaction");
|
emit sigSendDebugLog(Tools::getTime() + "CLIENT: filePath, fileSize - FAIL commitTransaction");
|
||||||
|
socket->waitForReadyRead(TCP_READ_TIMEOUT);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,7 +125,7 @@ void RecognizeSystem::recognize(QTcpSocket *socket)
|
|||||||
emit sigSendDebugLog("CLIENT: filesize: " + QString::number(fileSize));
|
emit sigSendDebugLog("CLIENT: filesize: " + QString::number(fileSize));
|
||||||
emit sigSendDebugLog("CLIENT: filePath: " + filePath);
|
emit sigSendDebugLog("CLIENT: filePath: " + filePath);
|
||||||
|
|
||||||
//socket->waitForReadyRead(100);
|
socket->waitForReadyRead(10);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,7 +140,7 @@ void RecognizeSystem::recognize(QTcpSocket *socket)
|
|||||||
file.remove(); //удаление файла, если он уже есть, но необходимо обновить
|
file.remove(); //удаление файла, если он уже есть, но необходимо обновить
|
||||||
emit sigSendDebugLog(Tools::getTime() + "Delete exist file: " + filePath);
|
emit sigSendDebugLog(Tools::getTime() + "Delete exist file: " + filePath);
|
||||||
|
|
||||||
//socket->waitForReadyRead(100);
|
//socket->waitForReadyRead(10);
|
||||||
}
|
}
|
||||||
|
|
||||||
tmpBlock.clear();
|
tmpBlock.clear();
|
||||||
@@ -140,12 +157,16 @@ void RecognizeSystem::recognize(QTcpSocket *socket)
|
|||||||
|
|
||||||
while(true)
|
while(true)
|
||||||
{
|
{
|
||||||
|
|
||||||
if(socket->bytesAvailable() <= 0)
|
if(socket->bytesAvailable() <= 0)
|
||||||
{
|
{
|
||||||
socket->waitForReadyRead(TCP_READ_TIMEOUT);
|
socket->waitForReadyRead(10);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//if(!socket->waitForReadyRead(TCP_READ_TIMEOUT))
|
||||||
|
//continue;
|
||||||
|
|
||||||
if(fileSize - sizeReceiveData >= BLOCK_SIZE)
|
if(fileSize - sizeReceiveData >= BLOCK_SIZE)
|
||||||
tmpBlock = socket->read(BLOCK_SIZE);
|
tmpBlock = socket->read(BLOCK_SIZE);
|
||||||
else
|
else
|
||||||
@@ -155,7 +176,7 @@ void RecognizeSystem::recognize(QTcpSocket *socket)
|
|||||||
|
|
||||||
if(bytesReceived <= 0)
|
if(bytesReceived <= 0)
|
||||||
{
|
{
|
||||||
QMessageBox::critical(nullptr, "P3", "bytesReceived <= 0. File: " + file.fileName());
|
//QMessageBox::critical(nullptr, "P3", "bytesReceived <= 0. File: " + file.fileName());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -207,6 +228,7 @@ void RecognizeSystem::recognize(QTcpSocket *socket)
|
|||||||
|
|
||||||
if(!stream.commitTransaction())
|
if(!stream.commitTransaction())
|
||||||
{
|
{
|
||||||
|
socket->waitForReadyRead(TCP_READ_TIMEOUT);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -248,6 +270,7 @@ void RecognizeSystem::recognize(QTcpSocket *socket)
|
|||||||
|
|
||||||
if(!stream.commitTransaction())
|
if(!stream.commitTransaction())
|
||||||
{
|
{
|
||||||
|
socket->waitForReadyRead(TCP_READ_TIMEOUT);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -263,6 +286,7 @@ void RecognizeSystem::recognize(QTcpSocket *socket)
|
|||||||
|
|
||||||
if(!stream.commitTransaction())
|
if(!stream.commitTransaction())
|
||||||
{
|
{
|
||||||
|
socket->waitForReadyRead(TCP_READ_TIMEOUT);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -315,6 +339,8 @@ void RecognizeSystem::recognize(QTcpSocket *socket)
|
|||||||
qCritical() << "RecognizeSystem::recognize packetType unknown!";
|
qCritical() << "RecognizeSystem::recognize packetType unknown!";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//socket->waitForReadyRead(10);
|
||||||
|
|
||||||
packetType = PacketType::TYPE_NONE;
|
packetType = PacketType::TYPE_NONE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user