mirror of
https://gitea.msk.dinamika-avia.ru/Constanta-Design/RRJServer.git
synced 2026-03-28 19:55:48 +03:00
sendFileBlock_V3
This commit is contained in:
@@ -1,7 +1,8 @@
|
|||||||
#include "recognizesystem.h"
|
#include "recognizesystem.h"
|
||||||
|
|
||||||
RecognizeSystem::RecognizeSystem(QObject *parent):
|
RecognizeSystem::RecognizeSystem(QObject *parent):
|
||||||
QObject(parent)
|
QObject(parent),
|
||||||
|
globalMutex(nullptr)
|
||||||
{
|
{
|
||||||
packetType = PacketType::TYPE_NONE;
|
packetType = PacketType::TYPE_NONE;
|
||||||
filePath.clear();
|
filePath.clear();
|
||||||
@@ -13,7 +14,7 @@ QObject(parent)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RecognizeSystem::initialize(UpdateController *updateController,DataParser* dataParser,SendSystem *sendSystem, ClientHandler *handler)
|
void RecognizeSystem::initialize(UpdateController *updateController,DataParser* dataParser, QMutex *globalMutex,SendSystem *sendSystem, ClientHandler *handler)
|
||||||
{
|
{
|
||||||
qDebug() << "RecognizeSystem::initialize thread ID " << QThread::currentThreadId();
|
qDebug() << "RecognizeSystem::initialize thread ID " << QThread::currentThreadId();
|
||||||
|
|
||||||
@@ -22,6 +23,7 @@ void RecognizeSystem::initialize(UpdateController *updateController,DataParser*
|
|||||||
this->clientHandler = handler;
|
this->clientHandler = handler;
|
||||||
this->sendSystem = sendSystem;
|
this->sendSystem = sendSystem;
|
||||||
socket = handler->getSocket();
|
socket = handler->getSocket();
|
||||||
|
this->globalMutex = globalMutex;
|
||||||
|
|
||||||
connect(this,&RecognizeSystem::sigCalculateHash,updateController,&UpdateController::calculateFullHashWithSetup,Qt::AutoConnection);
|
connect(this,&RecognizeSystem::sigCalculateHash,updateController,&UpdateController::calculateFullHashWithSetup,Qt::AutoConnection);
|
||||||
connect(this,&RecognizeSystem::sigChangeVersion,updateController,&UpdateController::changeAssetVersion,Qt::AutoConnection);
|
connect(this,&RecognizeSystem::sigChangeVersion,updateController,&UpdateController::changeAssetVersion,Qt::AutoConnection);
|
||||||
@@ -453,6 +455,7 @@ void RecognizeSystem::recognize()
|
|||||||
if(packetType == PacketType::GET_DOCS)
|
if(packetType == PacketType::GET_DOCS)
|
||||||
{
|
{
|
||||||
emit sigSendDocs(updateController->getPathAdditionalFile(tasksAMMfileName));
|
emit sigSendDocs(updateController->getPathAdditionalFile(tasksAMMfileName));
|
||||||
|
//globalMutex->unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (packetType == PacketType::SEND_HASH)
|
if (packetType == PacketType::SEND_HASH)
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ class RecognizeSystem : public QObject
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
RecognizeSystem(QObject *parent = nullptr);
|
RecognizeSystem(QObject *parent = nullptr);
|
||||||
void initialize(UpdateController *updateController,DataParser *dataParser, SendSystem *sendSystem, ClientHandler *handler);
|
void initialize(UpdateController *updateController,DataParser *dataParser, QMutex *globalMutex, SendSystem *sendSystem, ClientHandler *handler);
|
||||||
void recognize();
|
void recognize();
|
||||||
~RecognizeSystem();
|
~RecognizeSystem();
|
||||||
|
|
||||||
@@ -47,6 +47,7 @@ private:
|
|||||||
QString filePath;
|
QString filePath;
|
||||||
ClientHandler *clientHandler;
|
ClientHandler *clientHandler;
|
||||||
QMutex *mutex;
|
QMutex *mutex;
|
||||||
|
QMutex *globalMutex;
|
||||||
|
|
||||||
QTcpSocket *socket;
|
QTcpSocket *socket;
|
||||||
|
|
||||||
|
|||||||
@@ -2,26 +2,53 @@
|
|||||||
|
|
||||||
SendSystem::SendSystem(QObject *parent) : QObject(parent)
|
SendSystem::SendSystem(QObject *parent) : QObject(parent)
|
||||||
{
|
{
|
||||||
|
qDebug() << "SendSystem init thread ID " << QThread::currentThreadId();
|
||||||
|
|
||||||
|
client = nullptr;
|
||||||
|
socket = nullptr;
|
||||||
|
dataParser = nullptr;
|
||||||
|
|
||||||
|
globalMutex = nullptr;
|
||||||
|
waitCondition = nullptr;
|
||||||
|
|
||||||
|
buffer = nullptr;
|
||||||
|
|
||||||
|
type = TypeClientAutorization::TYPE_GUI;
|
||||||
|
|
||||||
isSendStopped = false;
|
isSendStopped = false;
|
||||||
|
flWaitWriten = false;
|
||||||
|
|
||||||
|
fileSize = 0;
|
||||||
|
countSend = 0;
|
||||||
|
|
||||||
|
buffer = new char[sendFileBlockSize];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SendSystem::~SendSystem()
|
||||||
|
{
|
||||||
|
delete buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void SendSystem::initialize(DataParser *dataParser,QMutex *globalMutex)
|
void SendSystem::initialize(DataParser *dataParser,QMutex *globalMutex)
|
||||||
{
|
{
|
||||||
qDebug() << "SendSystem::initialize thread ID " << QThread::currentThreadId();
|
qDebug() << "SendSystem::initialize thread ID " << QThread::currentThreadId();
|
||||||
|
|
||||||
this->dataParser = dataParser;
|
this->dataParser = dataParser;
|
||||||
//connect(this,&SendSystem::sigSendXMLmessage,dataParser->ClientAnswer(),&ClientAnswerParser::message,Qt::AutoConnection); //сигнал не используется
|
this->globalMutex = globalMutex;
|
||||||
connect(this,&SendSystem::sigSendNotify,dataParser->ClientAnswer(),&ClientAnswerParser::notify,Qt::DirectConnection); //потому что возвращает значение
|
|
||||||
//connect(this,&SendSystem::sigSendVersion,dataParser->ClientAnswer(),&ClientAnswerParser::currentVersion,Qt::AutoConnection); //сигнал не используется
|
|
||||||
|
|
||||||
mutex = globalMutex;
|
connect(this,&SendSystem::sigSendNotify,dataParser->ClientAnswer(),&ClientAnswerParser::notify,Qt::DirectConnection); //потому что возвращает значение
|
||||||
}
|
}
|
||||||
|
|
||||||
void SendSystem::setClient(Client *client,QTcpSocket *socket)
|
void SendSystem::setClient(Client *client,QTcpSocket *socket)
|
||||||
{
|
{
|
||||||
|
qDebug() << "SendSystem::setClient thread ID " << QThread::currentThreadId();
|
||||||
|
|
||||||
this->socket = socket;
|
this->socket = socket;
|
||||||
this->type = client->getClientType();
|
|
||||||
this->client = client;
|
this->client = client;
|
||||||
|
|
||||||
|
this->type = client->getClientType();
|
||||||
|
|
||||||
isSendStopped = false;
|
isSendStopped = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,46 +62,235 @@ void SendSystem::sendNotify(QString notify)
|
|||||||
|
|
||||||
void SendSystem::sendFileBlock(QString path)
|
void SendSystem::sendFileBlock(QString path)
|
||||||
{
|
{
|
||||||
QFile file(path);
|
//qDebug() << "SendSystem::sendFileBlock path: " << path;
|
||||||
QFileInfo fileInfo(file);
|
|
||||||
|
|
||||||
if(isSendStopped)
|
if(getIsSendStopped())
|
||||||
{ //Поведение на случай отключения клиента
|
{ //Поведение на случай отключения клиента
|
||||||
file.close();
|
Logger::instance().log("Client: " + client->getLogin() + " isSendStopped", LogLevel::ERROR);
|
||||||
Logger::instance().log("UNLOCK STOP MUTEX : " + client->getLogin(),LogLevel::ERROR);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QDataStream stream(socket);
|
QFile file(path);
|
||||||
stream.setVersion(QDataStream::Qt_DefaultCompiledVersion);
|
QFileInfo fileInfo(file);
|
||||||
|
|
||||||
fileSize = file.size();
|
fileSize = file.size();
|
||||||
|
|
||||||
if (fileSize == 0)
|
if (fileSize == 0)
|
||||||
{
|
{
|
||||||
Logger::instance().log("Client: " + client->getLogin() + " WARNING! Zero size " + fileInfo.fileName(),LogLevel::ERROR);
|
Logger::instance().log("Client: " + client->getLogin() + " ERROR! File zero size " + fileInfo.fileName(), LogLevel::ERROR);
|
||||||
Logger::instance().log(path, LogLevel::ERROR);
|
Logger::instance().log(path, LogLevel::ERROR);
|
||||||
return;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
countSend = 0;
|
||||||
|
|
||||||
|
QDataStream stream(socket);
|
||||||
|
stream.setVersion(QDataStream::Qt_DefaultCompiledVersion);
|
||||||
|
|
||||||
stream << PacketType::TYPE_FILE; //Отправляем тип блока
|
stream << PacketType::TYPE_FILE; //Отправляем тип блока
|
||||||
stream << path << fileSize;
|
stream << path << fileSize;
|
||||||
|
|
||||||
if(file.open(QFile::ReadOnly))
|
waitWrittenData("sendFileBlock:header " + fileInfo.fileName());
|
||||||
{
|
|
||||||
while(!file.atEnd())
|
while(!file.atEnd())
|
||||||
{
|
{
|
||||||
QByteArray data = file.read(sendFileBlockSize);
|
QByteArray data = file.read(sendFileBlockSize);
|
||||||
stream << data;
|
stream << data;
|
||||||
//socket->waitForBytesWritten(10);
|
|
||||||
|
|
||||||
if(socket->state() == QAbstractSocket::UnconnectedState) break;
|
waitWrittenData(QString("sendFileBlock:data (size %1) ").arg(data.size()) + fileInfo.fileName());
|
||||||
|
|
||||||
|
if(socket->state() == QAbstractSocket::UnconnectedState)
|
||||||
|
{
|
||||||
|
Logger::instance().log("Client: " + client->getLogin() + " UnconnectedState", LogLevel::ERROR);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
countSend++;
|
countSend++;
|
||||||
}
|
}
|
||||||
|
|
||||||
//emit sigSendToLogger(Tools::getTime() + " send file " + fileInfo.fileName());
|
file.close();
|
||||||
|
countSend = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SendSystem::sendFileBlock_V2(QString path)
|
||||||
|
{
|
||||||
|
QFile file(path);
|
||||||
|
if(!file.open(QIODevice::ReadOnly))
|
||||||
|
{
|
||||||
|
Logger::instance().log("ERROR open file: " + path, LogLevel::ERROR);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
countSend = 0;
|
||||||
|
fileSize = file.size();
|
||||||
|
|
||||||
|
if (fileSize == 0)
|
||||||
|
{
|
||||||
|
Logger::instance().log("Client: " + client->getLogin() + " WARNING! Zero size " +file.fileName(), LogLevel::ERROR);
|
||||||
|
Logger::instance().log(path, LogLevel::ERROR);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString type = QString::number(PacketType::TYPE_FILE);
|
||||||
|
QString fileSizeStr = QString::number(fileSize);
|
||||||
|
|
||||||
|
qDebug() << "SendSystem::sendFileBlock_V2 file " << file.fileName() << " size " << fileSizeStr;
|
||||||
|
|
||||||
|
QDataStream stream(socket);
|
||||||
|
stream.setVersion(QDataStream::Qt_DefaultCompiledVersion);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//mutexWriten.lock();
|
||||||
|
//flWaitWriten = true;
|
||||||
|
|
||||||
|
stream << PacketType::TYPE_FILE; //Отправляем тип блока
|
||||||
|
stream << path << fileSize;
|
||||||
|
|
||||||
|
socket->waitForBytesWritten(10);
|
||||||
|
|
||||||
|
/*
|
||||||
|
while(flWaitWriten)
|
||||||
|
{
|
||||||
|
QCoreApplication::processEvents(); // Обеспечиваем обработку сообщений
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
//socket->waitForBytesWritten(10);
|
||||||
|
|
||||||
|
//socket->write(type.toUtf8());
|
||||||
|
//socket->write(fileSizeStr.toUtf8());
|
||||||
|
|
||||||
|
connect(this->socket, &QTcpSocket::bytesWritten, this, &SendSystem::slot_BytesWrittenToSocket);
|
||||||
|
|
||||||
|
|
||||||
|
while(true)
|
||||||
|
{
|
||||||
|
if(socket->state() == QAbstractSocket::UnconnectedState)
|
||||||
|
break;
|
||||||
|
|
||||||
|
countSend++;
|
||||||
|
|
||||||
|
qint64 readBytes = file.read(buffer, /*sizeof(buffer)*/sendFileBlockSize);
|
||||||
|
if(readBytes <= 0)
|
||||||
|
break;
|
||||||
|
|
||||||
|
flWaitWriten = true;
|
||||||
|
while(!socket->write(buffer, readBytes))
|
||||||
|
{
|
||||||
|
int i = 0;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
while(flWaitWriten)
|
||||||
|
{
|
||||||
|
QCoreApplication::processEvents(); // Обеспечиваем обработку сообщений
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
while(!socket->flush())
|
||||||
|
{
|
||||||
|
int i = 0;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
// Завершаем отправку
|
||||||
|
//socket->flush();
|
||||||
|
//socket->waitForBytesWritten(10);
|
||||||
|
}
|
||||||
|
|
||||||
|
disconnect(this->socket, &QTcpSocket::bytesWritten, this, &SendSystem::slot_BytesWrittenToSocket);
|
||||||
|
|
||||||
|
//socket->flush();
|
||||||
|
/*
|
||||||
|
while(!socket->flush())
|
||||||
|
{
|
||||||
|
int i = 0;
|
||||||
|
i++;
|
||||||
|
}*/
|
||||||
|
|
||||||
|
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SendSystem::sendFileBlock_V3(QString path)
|
||||||
|
{
|
||||||
|
//qDebug() << "SendSystem::sendFileBlock path: " << path;
|
||||||
|
|
||||||
|
if(getIsSendStopped())
|
||||||
|
{ //Поведение на случай отключения клиента
|
||||||
|
Logger::instance().log("Client: " + client->getLogin() + " isSendStopped", LogLevel::ERROR);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QFile file(path);
|
||||||
|
QFileInfo fileInfo(file);
|
||||||
|
|
||||||
|
fileSize = file.size();
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
countSend = 0;
|
||||||
|
|
||||||
|
QDataStream stream(socket);
|
||||||
|
stream.setVersion(QDataStream::Qt_DefaultCompiledVersion);
|
||||||
|
|
||||||
|
stream << PacketType::TYPE_FILE; //Отправляем тип блока
|
||||||
|
stream << path << fileSize;
|
||||||
|
|
||||||
|
waitWrittenData("sendFileBlock:header " + fileInfo.fileName());
|
||||||
|
|
||||||
|
connect(this->socket, &QTcpSocket::bytesWritten, this, &SendSystem::slot_BytesWrittenToSocket);
|
||||||
|
|
||||||
|
while(!file.atEnd())
|
||||||
|
{
|
||||||
|
if(socket->state() == QAbstractSocket::UnconnectedState)
|
||||||
|
{
|
||||||
|
Logger::instance().log("Client: " + client->getLogin() + " UnconnectedState", LogLevel::ERROR);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
qint64 readBytes = file.read(buffer, /*sizeof(buffer)*/sendFileBlockSize);
|
||||||
|
if(readBytes <= 0)
|
||||||
|
break;
|
||||||
|
|
||||||
|
flWaitWriten = true;
|
||||||
|
while(!socket->write(buffer, readBytes))
|
||||||
|
{
|
||||||
|
int i = 0;
|
||||||
|
i++;
|
||||||
|
qCritical() << "socket->write ERROR. size " + QString::number(readBytes);
|
||||||
|
}
|
||||||
|
while(flWaitWriten)
|
||||||
|
{
|
||||||
|
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();
|
file.close();
|
||||||
countSend = 0;
|
countSend = 0;
|
||||||
}
|
}
|
||||||
@@ -99,11 +315,15 @@ void SendSystem::sendFileBlockByteArray(QByteArray array, PacketType packetType)
|
|||||||
stream << packetType; //Отправляем тип блока
|
stream << packetType; //Отправляем тип блока
|
||||||
stream << size;
|
stream << size;
|
||||||
|
|
||||||
|
socket->waitForBytesWritten(10);
|
||||||
|
|
||||||
while (bytesSended < size)
|
while (bytesSended < size)
|
||||||
{
|
{
|
||||||
QByteArray chunk = array.mid(bytesSended,sendFileBlockSize);
|
QByteArray chunk = array.mid(bytesSended,sendFileBlockSize);
|
||||||
stream << chunk;
|
stream << chunk;
|
||||||
|
|
||||||
|
socket->waitForBytesWritten(10);
|
||||||
|
|
||||||
bytesSended += chunk.length();
|
bytesSended += chunk.length();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -140,6 +360,11 @@ void SendSystem::sendVersion()
|
|||||||
sendXmlAnswer(data);
|
sendXmlAnswer(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SendSystem::slot_BytesWrittenToSocket(qint64 bytes)
|
||||||
|
{
|
||||||
|
flWaitWriten = false;
|
||||||
|
}
|
||||||
|
|
||||||
void SendSystem::sendFileBlockWithRename(QString path, QString newName)
|
void SendSystem::sendFileBlockWithRename(QString path, QString newName)
|
||||||
{
|
{
|
||||||
qDebug() << "SendSystem::sendFileBlockWithRename thread ID " << QThread::currentThreadId();
|
qDebug() << "SendSystem::sendFileBlockWithRename thread ID " << QThread::currentThreadId();
|
||||||
@@ -162,6 +387,8 @@ void SendSystem::sendFileBlockWithRename(QString path, QString newName)
|
|||||||
|
|
||||||
stream << pathForSend << fileSize;
|
stream << pathForSend << fileSize;
|
||||||
|
|
||||||
|
socket->waitForBytesWritten(10);
|
||||||
|
|
||||||
if(isSendStopped) { //Поведение на случай отключения клиента
|
if(isSendStopped) { //Поведение на случай отключения клиента
|
||||||
|
|
||||||
file.close();
|
file.close();
|
||||||
@@ -169,13 +396,13 @@ void SendSystem::sendFileBlockWithRename(QString path, QString newName)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
socket->waitForBytesWritten();
|
//socket->waitForBytesWritten();
|
||||||
|
|
||||||
if(file.open(QFile::ReadOnly)){
|
if(file.open(QFile::ReadOnly)){
|
||||||
while(!file.atEnd()){
|
while(!file.atEnd()){
|
||||||
QByteArray data = file.read(sendFileBlockSize);
|
QByteArray data = file.read(sendFileBlockSize);
|
||||||
stream << data;
|
stream << data;
|
||||||
socket->waitForBytesWritten();
|
socket->waitForBytesWritten(10);
|
||||||
countSend++;
|
countSend++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -184,8 +411,8 @@ void SendSystem::sendFileBlockWithRename(QString path, QString newName)
|
|||||||
|
|
||||||
file.close();
|
file.close();
|
||||||
countSend = 0;
|
countSend = 0;
|
||||||
socket->waitForBytesWritten();
|
socket->waitForBytesWritten(10);
|
||||||
socket->waitForReadyRead(100);
|
//socket->waitForReadyRead(100);
|
||||||
|
|
||||||
sendNotify(commandHashCompleteClient);
|
sendNotify(commandHashCompleteClient);
|
||||||
}
|
}
|
||||||
@@ -197,6 +424,8 @@ void SendSystem::sendFolderBlock(QString path)
|
|||||||
|
|
||||||
stream << PacketType::TYPE_FOLDER;
|
stream << PacketType::TYPE_FOLDER;
|
||||||
stream << path;
|
stream << path;
|
||||||
|
|
||||||
|
waitWrittenData("sendFolderBlock");
|
||||||
}
|
}
|
||||||
|
|
||||||
void SendSystem::sendDeleteBlock(QString path)
|
void SendSystem::sendDeleteBlock(QString path)
|
||||||
@@ -206,8 +435,8 @@ void SendSystem::sendDeleteBlock(QString path)
|
|||||||
|
|
||||||
stream << PacketType::TYPE_DELETE;
|
stream << PacketType::TYPE_DELETE;
|
||||||
stream << path;
|
stream << path;
|
||||||
qDebug() << "DELETE: " + path;
|
|
||||||
socket->waitForReadyRead(10);
|
waitWrittenData("sendDeleteBlock");
|
||||||
}
|
}
|
||||||
|
|
||||||
void SendSystem::sendPacketType(PacketType packetType)
|
void SendSystem::sendPacketType(PacketType packetType)
|
||||||
@@ -216,11 +445,11 @@ void SendSystem::sendPacketType(PacketType packetType)
|
|||||||
if (client->getClientType() == TypeClientAutorization::TYPE_QT_CLIENT ||
|
if (client->getClientType() == TypeClientAutorization::TYPE_QT_CLIENT ||
|
||||||
client->getClientType() == TypeClientAutorization::TYPE_GUI)
|
client->getClientType() == TypeClientAutorization::TYPE_GUI)
|
||||||
{
|
{
|
||||||
|
|
||||||
QDataStream stream(socket);
|
QDataStream stream(socket);
|
||||||
stream.setVersion(QDataStream::Qt_DefaultCompiledVersion);
|
stream.setVersion(QDataStream::Qt_DefaultCompiledVersion);
|
||||||
stream << packetType;
|
stream << packetType;
|
||||||
socket->waitForReadyRead(100);
|
|
||||||
|
waitWrittenData("sendPacketType");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -247,7 +476,8 @@ void SendSystem::sendXmlAnswer(QByteArray array, PacketType packetType)
|
|||||||
|
|
||||||
stream << packetType;
|
stream << packetType;
|
||||||
stream << array;
|
stream << array;
|
||||||
socket->waitForBytesWritten();
|
|
||||||
|
waitWrittenData("sendXmlAnswer");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -269,11 +499,14 @@ void SendSystem::sendNeedUpdate(bool flag,quint64 size,quint64 fileCount,quint64
|
|||||||
stream << size;
|
stream << size;
|
||||||
stream << fileCount;
|
stream << fileCount;
|
||||||
stream << deleteCount;
|
stream << deleteCount;
|
||||||
|
|
||||||
|
waitWrittenData("sendNeedUpdate");
|
||||||
}
|
}
|
||||||
|
|
||||||
void SendSystem::updateFiles(QList<FileData> fileSendList, QList<FileData> deleteList){
|
void SendSystem::updateFiles(QList<FileData> fileSendList, QList<FileData> deleteList)
|
||||||
|
{
|
||||||
|
//globalMutex->lock();
|
||||||
|
|
||||||
QMutexLocker locker(mutex);
|
|
||||||
QListIterator<FileData> clientIterator(deleteList);
|
QListIterator<FileData> clientIterator(deleteList);
|
||||||
|
|
||||||
while(clientIterator.hasNext())
|
while(clientIterator.hasNext())
|
||||||
@@ -283,6 +516,8 @@ void SendSystem::updateFiles(QList<FileData> fileSendList, QList<FileData> delet
|
|||||||
sendDeleteBlock(data.path);
|
sendDeleteBlock(data.path);
|
||||||
if(getIsSendStopped())
|
if(getIsSendStopped())
|
||||||
{
|
{
|
||||||
|
Logger::instance().log("Client: " + client->getLogin() + " isSendStopped", LogLevel::ERROR);
|
||||||
|
//globalMutex->unlock();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -296,20 +531,22 @@ void SendSystem::updateFiles(QList<FileData> fileSendList, QList<FileData> delet
|
|||||||
if (data.hash == "FOLDER")
|
if (data.hash == "FOLDER")
|
||||||
{
|
{
|
||||||
sendFolderBlock(data.path);
|
sendFolderBlock(data.path);
|
||||||
socket->waitForBytesWritten();
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
sendFileBlock(data.path);
|
sendFileBlock_V3(data.path);
|
||||||
socket->waitForBytesWritten();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(isSendStopped)
|
if(getIsSendStopped())
|
||||||
{
|
{
|
||||||
|
//globalMutex->unlock();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sendPacketType(PacketType::UPDATE_FILES_COMPLETE);
|
sendPacketType(PacketType::UPDATE_FILES_COMPLETE);
|
||||||
|
|
||||||
|
//globalMutex->unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -333,7 +570,17 @@ bool SendSystem::getIsSendStopped() const
|
|||||||
return isSendStopped;
|
return isSendStopped;
|
||||||
}
|
}
|
||||||
|
|
||||||
SendSystem::~SendSystem()
|
bool SendSystem::waitWrittenData(QString marker, int msec)
|
||||||
{
|
{
|
||||||
|
bool success = socket->waitForBytesWritten(msec);
|
||||||
|
if(success)
|
||||||
|
{
|
||||||
|
//qInfo() << "Data sended OK. <" + marker + ">";
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
qCritical() << "Data sended ERROR. <" + marker + ">";
|
||||||
|
}
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,11 +19,15 @@ class SendSystem : public QObject
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit SendSystem(QObject* parent = nullptr);
|
explicit SendSystem(QObject* parent = nullptr);
|
||||||
|
~SendSystem();
|
||||||
|
|
||||||
void initialize(DataParser* dataParser,QMutex *globalMutex);
|
void initialize(DataParser* dataParser,QMutex *globalMutex);
|
||||||
void setClient(Client* client,QTcpSocket *socket);
|
void setClient(Client* client,QTcpSocket *socket);
|
||||||
|
|
||||||
void sendMessageBlock(QString message);
|
void sendMessageBlock(QString message);
|
||||||
void sendFileBlock(QString path);
|
void sendFileBlock(QString path);
|
||||||
|
void sendFileBlock_V2(QString path);
|
||||||
|
void sendFileBlock_V3(QString path);
|
||||||
void sendFileBlockByteArray(QByteArray array, PacketType packetType);
|
void sendFileBlockByteArray(QByteArray array, PacketType packetType);
|
||||||
void sendFileBlockWithRename(QString path,QString newName);
|
void sendFileBlockWithRename(QString path,QString newName);
|
||||||
void sendFolderBlock(QString path);
|
void sendFolderBlock(QString path);
|
||||||
@@ -34,18 +38,21 @@ public:
|
|||||||
void sendDocs(QString docPath);
|
void sendDocs(QString docPath);
|
||||||
void sendXmlAnswer(QByteArray array, PacketType packetType = PacketType::TYPE_XMLANSWER);
|
void sendXmlAnswer(QByteArray array, PacketType packetType = PacketType::TYPE_XMLANSWER);
|
||||||
void sendNeedUpdate(bool flag,quint64 size,quint64 fileCount,quint64 deleteCount);
|
void sendNeedUpdate(bool flag,quint64 size,quint64 fileCount,quint64 deleteCount);
|
||||||
|
|
||||||
void updateFiles(QList<FileData> fileSendList, QList<FileData> deleteList);
|
void updateFiles(QList<FileData> fileSendList, QList<FileData> deleteList);
|
||||||
|
|
||||||
bool getIsSendStopped() const;
|
bool getIsSendStopped() const;
|
||||||
|
|
||||||
~SendSystem();
|
|
||||||
|
|
||||||
|
|
||||||
void updateFilesFULL(QList<FileData> fileSendList, QList<FileData> deleteList);
|
void updateFilesFULL(QList<FileData> fileSendList, QList<FileData> deleteList);
|
||||||
|
|
||||||
|
bool waitWrittenData(QString marker, int msec = 500);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void socketClose();
|
void socketClose();
|
||||||
void sendVersion();
|
void sendVersion();
|
||||||
|
|
||||||
|
void slot_BytesWrittenToSocket(qint64 bytes);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void sigLoadHash();
|
void sigLoadHash();
|
||||||
//QByteArray sigSendXMLmessage(QString loginFrom, QString loginTo, QString text, QString userType); //сигнал не используется
|
//QByteArray sigSendXMLmessage(QString loginFrom, QString loginTo, QString text, QString userType); //сигнал не используется
|
||||||
@@ -56,12 +63,19 @@ private:
|
|||||||
Client *client;
|
Client *client;
|
||||||
QTcpSocket* socket;
|
QTcpSocket* socket;
|
||||||
DataParser* dataParser;
|
DataParser* dataParser;
|
||||||
quint64 fileSize;
|
|
||||||
QMutex *mutex;
|
QMutex *globalMutex;
|
||||||
QWaitCondition *waitCondition;
|
QWaitCondition *waitCondition;
|
||||||
int countSend;
|
|
||||||
bool isSendStopped;
|
char* buffer;
|
||||||
|
|
||||||
TypeClientAutorization type;
|
TypeClientAutorization type;
|
||||||
|
|
||||||
|
bool isSendStopped;
|
||||||
|
bool flWaitWriten;
|
||||||
|
|
||||||
|
quint64 fileSize;
|
||||||
|
int countSend;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SENDSYSTEM_H
|
#endif // SENDSYSTEM_H
|
||||||
|
|||||||
@@ -57,7 +57,8 @@ static const QString commandGetTasks = "GETTASKS";
|
|||||||
static const QString commandeGetOfflineMessages = "GETOFFLINEMESSAGE";
|
static const QString commandeGetOfflineMessages = "GETOFFLINEMESSAGE";
|
||||||
|
|
||||||
//static quint64 fileBlockSize = 1460;
|
//static quint64 fileBlockSize = 1460;
|
||||||
static quint64 sendFileBlockSize = 256000;
|
const int BLOCK_SIZE = 1024 * 1024; // Размер блока
|
||||||
|
static quint64 sendFileBlockSize = /*256000*/BLOCK_SIZE;
|
||||||
static quint64 readFileBlockSize = 65535;
|
static quint64 readFileBlockSize = 65535;
|
||||||
//1025*250
|
//1025*250
|
||||||
|
|
||||||
|
|||||||
@@ -14,14 +14,15 @@ ClientHandler::ClientHandler( QObject *parent):
|
|||||||
void ClientHandler::initialize(int descriptor,
|
void ClientHandler::initialize(int descriptor,
|
||||||
UpdateController *updateController,DataParser *dataParser, QMutex *mutex)
|
UpdateController *updateController,DataParser *dataParser, QMutex *mutex)
|
||||||
{
|
{
|
||||||
this->socket = new QTcpSocket;
|
qDebug() << "ClientHandler::initialize thread ID " << QThread::currentThreadId();
|
||||||
this->thread = new QThread;
|
|
||||||
|
|
||||||
|
socket = new QTcpSocket;
|
||||||
|
thread = new QThread;
|
||||||
|
|
||||||
|
QIODevice::OpenMode openMode = socket->openMode();
|
||||||
socket->setParent(nullptr);
|
socket->setParent(nullptr);
|
||||||
socket->setSocketDescriptor(descriptor);
|
socket->setSocketDescriptor(descriptor);
|
||||||
|
|
||||||
qDebug() << "ClientHandler::initialize thread ID " << QThread::currentThreadId();
|
|
||||||
|
|
||||||
sendSystem = new SendSystem;
|
sendSystem = new SendSystem;
|
||||||
recognizeSystem = new RecognizeSystem;
|
recognizeSystem = new RecognizeSystem;
|
||||||
|
|
||||||
@@ -42,7 +43,7 @@ void ClientHandler::initialize(int descriptor,
|
|||||||
connect(recognizeSystem,&RecognizeSystem::signal_updateDocsXML,this,&ClientHandler::signal_updateDocsXML);
|
connect(recognizeSystem,&RecognizeSystem::signal_updateDocsXML,this,&ClientHandler::signal_updateDocsXML);
|
||||||
|
|
||||||
connect(this,&ClientHandler::sigSendXmlAnswer,sendSystem,&SendSystem::sendXmlAnswer,Qt::AutoConnection);
|
connect(this,&ClientHandler::sigSendXmlAnswer,sendSystem,&SendSystem::sendXmlAnswer,Qt::AutoConnection);
|
||||||
connect(this,&ClientHandler::sigInitSender,sendSystem,&SendSystem::initialize,Qt::AutoConnection/*Qt::DirectConnection*/);
|
//connect(this,&ClientHandler::sigInitSender,sendSystem,&SendSystem::initialize,Qt::AutoConnection/*Qt::DirectConnection*/);
|
||||||
connect(this,&ClientHandler::sigFileBlock,sendSystem,&SendSystem::sendFileBlock,Qt::AutoConnection);
|
connect(this,&ClientHandler::sigFileBlock,sendSystem,&SendSystem::sendFileBlock,Qt::AutoConnection);
|
||||||
connect(this,&ClientHandler::sigFileBlockByteArray,sendSystem,&SendSystem::sendFileBlockByteArray,Qt::AutoConnection);
|
connect(this,&ClientHandler::sigFileBlockByteArray,sendSystem,&SendSystem::sendFileBlockByteArray,Qt::AutoConnection);
|
||||||
connect(this,&ClientHandler::sigFolderBlock,sendSystem,&SendSystem::sendFolderBlock,Qt::AutoConnection);
|
connect(this,&ClientHandler::sigFolderBlock,sendSystem,&SendSystem::sendFolderBlock,Qt::AutoConnection);
|
||||||
@@ -60,9 +61,10 @@ void ClientHandler::initialize(int descriptor,
|
|||||||
connect(socket,&QTcpSocket::readyRead,this,&ClientHandler::initClientType,Qt::AutoConnection);
|
connect(socket,&QTcpSocket::readyRead,this,&ClientHandler::initClientType,Qt::AutoConnection);
|
||||||
initClientType();
|
initClientType();
|
||||||
|
|
||||||
recognizeSystem->initialize(updateController,dataParser,sendSystem, this);
|
recognizeSystem->initialize(updateController,dataParser, mutex,sendSystem, this);
|
||||||
sendSystem->setClient(client,socket);
|
sendSystem->setClient(client,socket);
|
||||||
emit sigInitSender(dataParser, mutex);
|
sendSystem->initialize(dataParser, mutex);
|
||||||
|
//emit sigInitSender(dataParser, mutex);
|
||||||
|
|
||||||
Logger::instance().log("SERVER: Client connected");
|
Logger::instance().log("SERVER: Client connected");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ public:
|
|||||||
|
|
||||||
signals:
|
signals:
|
||||||
void sigSendXmlAnswer(QByteArray array, PacketType packetType);
|
void sigSendXmlAnswer(QByteArray array, PacketType packetType);
|
||||||
void sigInitSender (DataParser *dataParse, QMutex *mutex);
|
//void sigInitSender (DataParser *dataParse, QMutex *mutex);
|
||||||
void sigFolderBlock(QString path);
|
void sigFolderBlock(QString path);
|
||||||
void sigFileBlock(QString path);
|
void sigFileBlock(QString path);
|
||||||
void sigFileBlockByteArray(QByteArray array, PacketType packetType);
|
void sigFileBlockByteArray(QByteArray array, PacketType packetType);
|
||||||
@@ -71,6 +71,10 @@ signals:
|
|||||||
|
|
||||||
void signal_updateDocsXML();
|
void signal_updateDocsXML();
|
||||||
|
|
||||||
|
private:
|
||||||
|
void initClientType();
|
||||||
|
void packetTypeInit(PacketType packet, Client *client);
|
||||||
|
|
||||||
public :
|
public :
|
||||||
QThread *thread;
|
QThread *thread;
|
||||||
QTcpSocket *socket;
|
QTcpSocket *socket;
|
||||||
@@ -82,11 +86,7 @@ private:
|
|||||||
UpdateController *updateController;
|
UpdateController *updateController;
|
||||||
RecognizeSystem *recognizeSystem;
|
RecognizeSystem *recognizeSystem;
|
||||||
Client *client;
|
Client *client;
|
||||||
|
|
||||||
SendSystem *sendSystem;
|
SendSystem *sendSystem;
|
||||||
|
|
||||||
void initClientType();
|
|
||||||
void packetTypeInit(PacketType packet, Client *client);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CLIENTHANDLER_H
|
#endif // CLIENTHANDLER_H
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ MultiThreadServer::MultiThreadServer(UpdateController *updateController, DocsUpd
|
|||||||
DataParser *dataParser,qint16 hostPort, QObject *parent ):
|
DataParser *dataParser,qint16 hostPort, QObject *parent ):
|
||||||
QTcpServer(parent),
|
QTcpServer(parent),
|
||||||
mutex(nullptr),
|
mutex(nullptr),
|
||||||
|
clientsMap(nullptr),
|
||||||
hostPort(hostPort),
|
hostPort(hostPort),
|
||||||
processingSystem(processingSystem),
|
processingSystem(processingSystem),
|
||||||
updateController(updateController),
|
updateController(updateController),
|
||||||
@@ -23,6 +24,7 @@ MultiThreadServer::MultiThreadServer(UpdateController *updateController, DocsUpd
|
|||||||
MultiThreadServer::~MultiThreadServer()
|
MultiThreadServer::~MultiThreadServer()
|
||||||
{
|
{
|
||||||
delete mutex;
|
delete mutex;
|
||||||
|
delete clientsMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MultiThreadServer::incomingConnection(qintptr socketDesriptor)
|
void MultiThreadServer::incomingConnection(qintptr socketDesriptor)
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ public:
|
|||||||
{
|
{
|
||||||
return stateBlockAutorization;
|
return stateBlockAutorization;
|
||||||
}
|
}
|
||||||
EStateServer getStateServer()
|
EStateServer getStateServer() const
|
||||||
{
|
{
|
||||||
return stateServer;
|
return stateServer;
|
||||||
}
|
}
|
||||||
@@ -58,6 +58,9 @@ private:
|
|||||||
emit signal_StateServer(stateServer, stateBlockAutorization);
|
emit signal_StateServer(stateServer, stateBlockAutorization);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void removeClient(int idSocket);
|
||||||
|
void addClient(qintptr descriptor, ClientHandler *client);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
//void sigInitClient(int descriptor, ServerLMSWidget *serverWidget,
|
//void sigInitClient(int descriptor, ServerLMSWidget *serverWidget,
|
||||||
// UpdateController *updateController, DataParser *dataParser, QMutex *mutex);
|
// UpdateController *updateController, DataParser *dataParser, QMutex *mutex);
|
||||||
@@ -96,9 +99,6 @@ private:
|
|||||||
EStateServer stateServer;
|
EStateServer stateServer;
|
||||||
EStateBlockAutorization stateBlockAutorization;
|
EStateBlockAutorization stateBlockAutorization;
|
||||||
QMap<QString, QString> blockersMap;
|
QMap<QString, QString> blockersMap;
|
||||||
|
|
||||||
void removeClient(int idSocket);
|
|
||||||
void addClient(qintptr descriptor, ClientHandler *client);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MULTITHREADSERVER_H
|
#endif // MULTITHREADSERVER_H
|
||||||
|
|||||||
Reference in New Issue
Block a user