diff --git a/LibServer/Systems/processingsystem.cpp b/LibServer/Systems/processingsystem.cpp index 7e6f7ad..0f101e2 100644 --- a/LibServer/Systems/processingsystem.cpp +++ b/LibServer/Systems/processingsystem.cpp @@ -652,7 +652,7 @@ void ProcessingSystem::processingClientQueryTasksXML(ClientHandler *client, Clie nameFile = tasksFIMfileName; pathFile = updateController->getPathAdditionalFile(nameFile); Logger::instance().log(pathFile); - client->sendFileBlock(pathFile); + client->sendFileBlock_forGUI(pathFile); client->sendPacketType(PacketType::TYPE_XMLANSWER_QUERY_TASKS_XML_FIM); } else if(clientQueryTasksXML.Type == "amm") @@ -660,7 +660,7 @@ void ProcessingSystem::processingClientQueryTasksXML(ClientHandler *client, Clie nameFile = tasksAMMfileName; pathFile = updateController->getPathAdditionalFile(nameFile); docsUpdater->lockAccessToDocsXML(); - client->sendFileBlock(pathFile); + client->sendFileBlock_forGUI(pathFile); client->sendPacketType(PacketType::TYPE_XMLANSWER_QUERY_TASKS_XML_AMM); docsUpdater->unLockAccessToDocsXML(); } diff --git a/LibServer/Systems/recognizesystem.cpp b/LibServer/Systems/recognizesystem.cpp index 56671cf..f7ecf3f 100644 --- a/LibServer/Systems/recognizesystem.cpp +++ b/LibServer/Systems/recognizesystem.cpp @@ -31,7 +31,7 @@ void RecognizeSystem::initialize(UpdateController *updateController,DataParser* connect(this,&RecognizeSystem::sigCopyVersion,updateController,&UpdateController::createCopyVersion,Qt::AutoConnection); connect(this,&RecognizeSystem::sigXmlParser,dataParser->getProcessParser(),&ProcessParser::slot_read,Qt::AutoConnection); //connect(this,&RecognizeSystem::sigRecalculateDocs,server,&ServerLMSWidget::slot_UpdateDocs,Qt::AutoConnection); - connect(this,&RecognizeSystem::sigSendDocs,sendSystem,&SendSystem::slot_sendDocs,Qt::AutoConnection); + connect(this,&RecognizeSystem::sigSendDocs_forQtClient,sendSystem,&SendSystem::slot_sendDocs_forQtClient,Qt::AutoConnection); } void RecognizeSystem::recognize() @@ -454,8 +454,7 @@ void RecognizeSystem::recognize() if(packetType == PacketType::GET_DOCS) { - emit sigSendDocs(updateController->getPathAdditionalFile(tasksAMMfileName)); - //globalMutex->unlock(); + emit sigSendDocs_forQtClient(updateController->getPathAdditionalFile(tasksAMMfileName)); } if (packetType == PacketType::SEND_HASH) diff --git a/LibServer/Systems/recognizesystem.h b/LibServer/Systems/recognizesystem.h index f450e99..ba93219 100644 --- a/LibServer/Systems/recognizesystem.h +++ b/LibServer/Systems/recognizesystem.h @@ -34,7 +34,7 @@ signals: void sigDeleteVersion(QString versionName); void sigCopyVersion(QString versionName,QString newVersionName,QString author); //void sigRecalculateDocs(); - void sigSendDocs(QString docsPath); + void sigSendDocs_forQtClient(QString docsPath); void signal_updateDocsXML(); diff --git a/LibServer/Systems/sendsystem.cpp b/LibServer/Systems/sendsystem.cpp index 84fca20..e67fd94 100644 --- a/LibServer/Systems/sendsystem.cpp +++ b/LibServer/Systems/sendsystem.cpp @@ -75,7 +75,7 @@ void SendSystem::updateFiles(QList fileSendList, QList delet } else { - slot_sendFileBlock_V3(data.path); + slot_sendFileBlock_forQtClient(data.path); } if(slot_getIsSendingStopped()) @@ -184,9 +184,9 @@ void SendSystem::slot_sendXmlAnswer(QByteArray array, PacketType packetType) } } -void SendSystem::slot_sendDocs(QString docsPath) +void SendSystem::slot_sendDocs_forQtClient(QString docsPath) { - slot_sendFileBlock(docsPath); + slot_sendFileBlock_forQtClient(docsPath); } void SendSystem::slot_sendNeedUpdate(bool flag, quint64 size, quint64 fileCount, quint64 deleteCount) @@ -224,7 +224,7 @@ void SendSystem::slot_sendDeleteBlock(QString path) waitWrittenData("sendDeleteBlock"); } -void SendSystem::slot_sendFileBlock(QString path) +void SendSystem::slot_sendFileBlock_forGUI(QString path) { //qDebug() << "SendSystem::sendFileBlock path: " << path; @@ -283,7 +283,7 @@ void SendSystem::slot_sendFileBlock(QString path) countSend = 0; } -void SendSystem::slot_sendFileBlock_V3(QString path) +void SendSystem::slot_sendFileBlock_forQtClient(QString path) { //qDebug() << "SendSystem::sendFileBlock path: " << path; @@ -421,51 +421,85 @@ void SendSystem::slot_sendFileBlockByteArray(QByteArray array, PacketType packet } } -void SendSystem::slot_sendFileBlockWithRename(QString path, QString newName) +void SendSystem::slot_sendFileBlockWithRename_Hash_forQtClient(QString path, QString newName) { //qDebug() << "SendSystem::sendFileBlockWithRename thread ID " << QThread::currentThreadId(); - QDataStream stream(socket); - stream.setVersion(QDataStream::Qt_DefaultCompiledVersion); + if(slot_getIsSendingStopped()) + { //Поведение на случай отключения клиента + Logger::instance().log("Client: " + client->getLogin() + " isSendingStopped", LogLevel::ERROR); + return; + } QFile file(Tools::createRootPath(path)); QFileInfo fileInfo(file); fileSize = fileInfo.size(); - if(fileSize == 0){ - Logger::instance().log("Client: " + client->getLogin() + " WARNING! Zero size " + fileInfo.fileName(),LogLevel::ERROR); + if (fileSize == 0) + { + Logger::instance().log("Client: " + client->getLogin() + " ERROR! File zero size " + fileInfo.fileName(), LogLevel::ERROR); + Logger::instance().log(path, LogLevel::ERROR); + return; + } + + if(!file.open(QFile::ReadOnly)) + { + Logger::instance().log("Client: " + client->getLogin() + " ERROR! File not open: " + fileInfo.fileName(), LogLevel::ERROR); + Logger::instance().log(path, LogLevel::ERROR); return; } QString pathForSend = Tools::createFolderPath(path) + "/" + staticDataFolderName + newName; + countSend = 0; + + QDataStream stream(socket); + stream.setVersion(QDataStream::Qt_DefaultCompiledVersion); + stream << PacketType::TYPE_FILE; stream << pathForSend << fileSize; waitWrittenData("sendFileBlockWithRename"); - if(slot_getIsSendingStopped()) { //Поведение на случай отключения клиента + connect(this->socket, &QTcpSocket::bytesWritten, this, &SendSystem::slot_BytesWrittenToSocket); - file.close(); - return; - } - - //socket->waitForBytesWritten(); - - if(file.open(QFile::ReadOnly)){ - while(!file.atEnd()){ - QByteArray data = file.read(sendFileBlockSize); - stream << data; - waitWrittenData("sendFileBlockWithRename"); - countSend++; + while(!file.atEnd()) + { + if(socket->state() == QAbstractSocket::UnconnectedState) + { + Logger::instance().log("Client: " + client->getLogin() + " UnconnectedState", LogLevel::ERROR); + break; } - Logger::instance().log("Send file " + fileInfo.fileName()); + qint64 readBytes = file.read(buffer, sendFileBlockSize); + if(readBytes <= 0) + break; + + flWaitWritenToSocket = true; + + while(!socket->write(buffer, readBytes)) + { + qCritical() << "socket->write ERROR. size " + QString::number(readBytes); + int i = 0; + i++; + } + while(flWaitWritenToSocket) + { + QCoreApplication::processEvents(); // Обеспечиваем обработку сообщений + int i = 0; + i++; + } + + waitWrittenData(QString("sendFileBlock:data (readBytes %1, num %2) ").arg(QString::number(readBytes), QString::number(countSend)) + fileInfo.fileName()); + + countSend++; } + disconnect(this->socket, &QTcpSocket::bytesWritten, this, &SendSystem::slot_BytesWrittenToSocket); + file.close(); countSend = 0; - waitWrittenData("sendFileBlockWithRename"); + //waitWrittenData("sendFileBlockWithRename"); //socket->waitForReadyRead(100); slot_sendNotify(commandHashCompleteClient); diff --git a/LibServer/Systems/sendsystem.h b/LibServer/Systems/sendsystem.h index 121afd9..9e04cb5 100644 --- a/LibServer/Systems/sendsystem.h +++ b/LibServer/Systems/sendsystem.h @@ -43,17 +43,17 @@ public slots: void slot_sendPacketType(PacketType packet); void slot_sendXmlAnswer(QByteArray array, PacketType packetType = PacketType::TYPE_XMLANSWER); - void slot_sendDocs(QString docPath); + void slot_sendDocs_forQtClient(QString docPath); void slot_sendNeedUpdate(bool flag,quint64 size,quint64 fileCount,quint64 deleteCount); void slot_sendFolderBlock(QString path); void slot_sendDeleteBlock(QString path); - void slot_sendFileBlock(QString path); - void slot_sendFileBlock_V3(QString path); + void slot_sendFileBlock_forGUI(QString path); + void slot_sendFileBlock_forQtClient(QString path); void slot_sendFileBlockByteArray(QByteArray array, PacketType packetType); - void slot_sendFileBlockWithRename(QString path,QString newName); + void slot_sendFileBlockWithRename_Hash_forQtClient(QString path,QString newName); signals: QByteArray sigSendNotify(QString message); diff --git a/LibServer/Systems/updatecontroller.cpp b/LibServer/Systems/updatecontroller.cpp index 1f34f20..3b3eae7 100644 --- a/LibServer/Systems/updatecontroller.cpp +++ b/LibServer/Systems/updatecontroller.cpp @@ -54,10 +54,12 @@ void UpdateController::changeAssetVersion(QString versionName) currentStreamingPath = assetManager->setVersion(versionName); setUpCurrentServerHash(); - emit sigUpdateDocsXML(); + commonClientHandler->slot_sendPacketToAllClients(PacketType::HASH_READY, false); commonClientHandler->sendCurrentVersionToAllClient(); + emit sigUpdateDocsXML(); + //commonClientHandler->slot_sendPacketToAllClients(PacketType::FREE); res = emit signal_BlockAutorization(false, "SERVER", "ChangeAssetVersion"); } diff --git a/LibServer/clienthandler/clienthandler.cpp b/LibServer/clienthandler/clienthandler.cpp index 8e0b7bb..d40e976 100644 --- a/LibServer/clienthandler/clienthandler.cpp +++ b/LibServer/clienthandler/clienthandler.cpp @@ -44,14 +44,14 @@ void ClientHandler::initialize(int descriptor, connect(this,&ClientHandler::sigSendXmlAnswer,sendSystem,&SendSystem::slot_sendXmlAnswer,Qt::AutoConnection); //connect(this,&ClientHandler::sigInitSender,sendSystem,&SendSystem::initialize,Qt::AutoConnection/*Qt::DirectConnection*/); - connect(this,&ClientHandler::sigFileBlock,sendSystem,&SendSystem::slot_sendFileBlock,Qt::AutoConnection); + connect(this,&ClientHandler::sigFileBlock_forGUI,sendSystem,&SendSystem::slot_sendFileBlock_forGUI,Qt::AutoConnection); connect(this,&ClientHandler::sigFileBlockByteArray,sendSystem,&SendSystem::slot_sendFileBlockByteArray,Qt::AutoConnection); connect(this,&ClientHandler::sigFolderBlock,sendSystem,&SendSystem::slot_sendFolderBlock,Qt::AutoConnection); connect(this,&ClientHandler::sigGetIsSendStopped,sendSystem,&SendSystem::slot_getIsSendingStopped,/*Qt::AutoConnection*/Qt::DirectConnection); //Возвращает значение connect(this,&ClientHandler::sigSendDeleteBlock,sendSystem,&SendSystem::slot_sendDeleteBlock,Qt::AutoConnection); connect(this,&ClientHandler::sigNeedUpdate,sendSystem,&SendSystem::slot_sendNeedUpdate,Qt::AutoConnection); connect(this,&ClientHandler::sigSendNotify,sendSystem,&SendSystem::slot_sendNotify,Qt::AutoConnection); - connect(this,&ClientHandler::sigSendFileBlockWithRename,sendSystem,&SendSystem::slot_sendFileBlockWithRename,Qt::AutoConnection); + connect(this,&ClientHandler::sigSendFileBlockWithRename_Hash_forQtClient,sendSystem,&SendSystem::slot_sendFileBlockWithRename_Hash_forQtClient,Qt::AutoConnection); connect(this,&ClientHandler::sigSendVersion,sendSystem,&SendSystem::slot_sendVersion,Qt::AutoConnection); connect(this,&ClientHandler::sigSocketClose,sendSystem,&SendSystem::slot_socketClose,Qt::AutoConnection); //connect(this,&ClientHandler::sigSocketFlush,sendSystem,&SendSystem::socketFlush,Qt::AutoConnection); //не используется @@ -101,7 +101,7 @@ void ClientHandler::initClientType() void ClientHandler::sendHash() { QString path = "\\" + hashFileName; - emit sigSendFileBlockWithRename(path,"/serverHash.xml"); + emit sigSendFileBlockWithRename_Hash_forQtClient(path,"/serverHash.xml"); //emit sigSendNotify("HASHSENDCOMPLETE"); } @@ -135,9 +135,9 @@ void ClientHandler::sendXmlAnswer(QByteArray array, PacketType packetType) emit sigSendXmlAnswer(array, packetType); } -void ClientHandler::sendFileBlock(QString path) +void ClientHandler::sendFileBlock_forGUI(QString path) { - emit sigFileBlock(path); + emit sigFileBlock_forGUI(path); } void ClientHandler::sendFileBlockByteArray(QByteArray array, PacketType packetType) diff --git a/LibServer/clienthandler/clienthandler.h b/LibServer/clienthandler/clienthandler.h index 491a311..2c32f06 100644 --- a/LibServer/clienthandler/clienthandler.h +++ b/LibServer/clienthandler/clienthandler.h @@ -27,7 +27,7 @@ public: void initSender(DataParser *dataParser); void sendXmlAnswer(QByteArray array, PacketType packetType = PacketType::TYPE_XMLANSWER); void sendFolderBlock(QString path); - void sendFileBlock(QString path); + void sendFileBlock_forGUI(QString path); void sendFileBlockByteArray(QByteArray array, PacketType packetType); bool getIsSendStopped(); void sendDeleteBlock(QString path); @@ -53,7 +53,7 @@ signals: void sigSendXmlAnswer(QByteArray array, PacketType packetType); //void sigInitSender (DataParser *dataParse, QMutex *mutex); void sigFolderBlock(QString path); - void sigFileBlock(QString path); + void sigFileBlock_forGUI(QString path); void sigFileBlockByteArray(QByteArray array, PacketType packetType); bool sigGetIsSendStopped(); void sigSendDeleteBlock(QString path); @@ -62,7 +62,7 @@ signals: void sigSendHash(); void sigRecognize(ClientHandler *handler); void sigSendNotify(QString notify); - void sigSendFileBlockWithRename (QString path,QString newName); + void sigSendFileBlockWithRename_Hash_forQtClient (QString path,QString newName); void sigSocketClose(); //bool sigSocketFlush(); //не используется void sigSendVersion();