diff --git a/LibServer/Systems/recognizesystem.cpp b/LibServer/Systems/recognizesystem.cpp index 478d108..56671cf 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::sendDocs,Qt::AutoConnection); + connect(this,&RecognizeSystem::sigSendDocs,sendSystem,&SendSystem::slot_sendDocs,Qt::AutoConnection); } void RecognizeSystem::recognize() @@ -405,7 +405,7 @@ void RecognizeSystem::recognize() if (updateController->checkDuplicate(result[1])) { - sendSystem->sendNotify(commandDuplicateVerName); + sendSystem->slot_sendNotify(commandDuplicateVerName); packetType = PacketType::TYPE_NONE; break; } @@ -427,11 +427,11 @@ void RecognizeSystem::recognize() if (versionName == baseNameVersion) { - sendSystem->sendNotify(commandTryBaseDelete); + sendSystem->slot_sendNotify(commandTryBaseDelete); } else if (versionName == updateController->getCurrentVersionName()) { - sendSystem->sendNotify(commandTryActiveDelete); + sendSystem->slot_sendNotify(commandTryActiveDelete); } else { diff --git a/LibServer/Systems/sendsystem.cpp b/LibServer/Systems/sendsystem.cpp index 3434b7b..84fca20 100644 --- a/LibServer/Systems/sendsystem.cpp +++ b/LibServer/Systems/sendsystem.cpp @@ -1,25 +1,20 @@ #include "sendsystem.h" -SendSystem::SendSystem(QObject *parent) : QObject(parent) +SendSystem::SendSystem(QObject *parent) : + QObject(parent), + client(nullptr), + socket(nullptr), + dataParser(nullptr), + globalMutex(nullptr), + buffer(nullptr), + type(TypeClientAutorization::TYPE_GUI), + flSendingStopped(false), + flWaitWritenToSocket(false), + bytesWritedToSocket(0), + fileSize(0), + countSend(0) { - 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; - flWaitWriten = false; - - fileSize = 0; - countSend = 0; + qDebug() << "SendSystem init thread ID " << QThread::currentThreadId(); buffer = new char[sendFileBlockSize]; } @@ -30,17 +25,17 @@ SendSystem::~SendSystem() } -void SendSystem::initialize(DataParser *dataParser,QMutex *globalMutex) +void SendSystem::initialize(DataParser *dataParser, QMutex *globalMutex) { qDebug() << "SendSystem::initialize thread ID " << QThread::currentThreadId(); this->dataParser = dataParser; this->globalMutex = globalMutex; - connect(this,&SendSystem::sigSendNotify,dataParser->ClientAnswer(),&ClientAnswerParser::notify,Qt::DirectConnection); //потому что возвращает значение + 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(); @@ -49,24 +44,193 @@ void SendSystem::setClient(Client *client,QTcpSocket *socket) this->type = client->getClientType(); - isSendStopped = false; + flSendingStopped = false; } -void SendSystem::sendNotify(QString notify) +void SendSystem::updateFiles(QList fileSendList, QList deleteList) { - qDebug() << "SendSystem::sendNotify thread ID " << QThread::currentThreadId(); + QListIterator clientIterator(deleteList); - auto answer = emit sigSendNotify(notify); - sendXmlAnswer(answer); + while(clientIterator.hasNext()) + { + FileData data = clientIterator.next(); + + slot_sendDeleteBlock(data.path); + if(slot_getIsSendingStopped()) + { + Logger::instance().log("Client: " + client->getLogin() + " isSendStopped", LogLevel::ERROR); + return; + } + } + + QListIterator serverIterator(fileSendList); + + while(serverIterator.hasNext()) + { + FileData data = serverIterator.next(); + + if (data.hash == "FOLDER") + { + slot_sendFolderBlock(data.path); + } + else + { + slot_sendFileBlock_V3(data.path); + } + + if(slot_getIsSendingStopped()) + { + return; + } + } + + slot_sendPacketType(PacketType::UPDATE_FILES_COMPLETE); } -void SendSystem::sendFileBlock(QString path) +bool SendSystem::waitWrittenData(QString marker, int msec) +{ + bool success = socket->waitForBytesWritten(msec); + if(success) + { + //qInfo() << "Data sended OK. <" + marker + ">"; + } + else + { + qDebug() << "WaitForBytesWritten timeout. <" + marker + ">"; + } + return success; +} + + +void SendSystem::slot_BytesWrittenToSocket(qint64 bytes) +{ + flWaitWritenToSocket = false; + bytesWritedToSocket = bytes; +} + +bool SendSystem::slot_getIsSendingStopped() const +{ + return flSendingStopped; +} + +void SendSystem::slot_stopSending() +{ + flSendingStopped = true; +} + +void SendSystem::slot_socketClose() +{ + socket->close(); +} + + +void SendSystem::slot_sendVersion() +{ + QByteArray data = dataParser->ClientAnswer()->currentVersion(); + slot_sendXmlAnswer(data); +} + +void SendSystem::slot_sendNotify(QString notify) +{ + auto answer = emit sigSendNotify(notify); + slot_sendXmlAnswer(answer); +} + +void SendSystem::slot_sendPacketType(PacketType packetType) +{ + Logger::instance().log(" SEND TO: " + client->getLogin() + " " + enumToString(packetType), LogLevel::DEBUG); + if (client->getClientType() == TypeClientAutorization::TYPE_QT_CLIENT || + client->getClientType() == TypeClientAutorization::TYPE_GUI) + { + QDataStream stream(socket); + stream.setVersion(QDataStream::Qt_DefaultCompiledVersion); + stream << packetType; + + waitWrittenData("sendPacketType"); + } + else + { + QByteArray message; + int type = (int)packetType; + message.append(reinterpret_cast(&type), sizeof(int)); + socket->write(message); + } +} + +void SendSystem::slot_sendXmlAnswer(QByteArray array, PacketType packetType) +{ + Logger::instance().log("SEND TO: "+ client->getLogin() + " " + enumToString(packetType) + "\n Text: " + + QString(array), LogLevel::DEBUG); + + if (client->getClientType() == TypeClientAutorization::TYPE_QT_CLIENT || + client->getClientType() == TypeClientAutorization::TYPE_GUI) + { + QDataStream stream(socket); + stream.setVersion(QDataStream::Qt_DefaultCompiledVersion); + + stream << packetType; + stream << array; + + waitWrittenData("sendXmlAnswer"); + } + else + { + slot_sendPacketType(packetType); + QByteArray message; + int size = array.length(); + message.append(reinterpret_cast(&size), sizeof(int)); + socket->write(message); + socket->write(array); + } +} + +void SendSystem::slot_sendDocs(QString docsPath) +{ + slot_sendFileBlock(docsPath); +} + +void SendSystem::slot_sendNeedUpdate(bool flag, quint64 size, quint64 fileCount, quint64 deleteCount) +{ + QDataStream stream(socket); + stream.setVersion(QDataStream::Qt_DefaultCompiledVersion); + stream << PacketType::TYPE_NEEDUPDATE; + stream << flag; + stream << size; + stream << fileCount; + stream << deleteCount; + + waitWrittenData("sendNeedUpdate"); +} + +void SendSystem::slot_sendFolderBlock(QString path) +{ + QDataStream stream(socket); + stream.setVersion(QDataStream::Qt_DefaultCompiledVersion); + + stream << PacketType::TYPE_FOLDER; + stream << path; + + waitWrittenData("sendFolderBlock"); +} + +void SendSystem::slot_sendDeleteBlock(QString path) +{ + QDataStream stream(socket); + stream.setVersion(QDataStream::Qt_DefaultCompiledVersion); + + stream << PacketType::TYPE_DELETE; + stream << path; + + waitWrittenData("sendDeleteBlock"); +} + +void SendSystem::slot_sendFileBlock(QString path) { //qDebug() << "SendSystem::sendFileBlock path: " << path; - if(getIsSendStopped()) + if(slot_getIsSendingStopped()) { //Поведение на случай отключения клиента - Logger::instance().log("Client: " + client->getLogin() + " isSendStopped", LogLevel::ERROR); + Logger::instance().log("Client: " + client->getLogin() + " isSendingStopped", LogLevel::ERROR); return; } @@ -94,24 +258,24 @@ void SendSystem::sendFileBlock(QString path) QDataStream stream(socket); stream.setVersion(QDataStream::Qt_DefaultCompiledVersion); - stream << PacketType::TYPE_FILE; //Отправляем тип блока + stream << PacketType::TYPE_FILE; stream << path << fileSize; waitWrittenData("sendFileBlock:header " + fileInfo.fileName()); while(!file.atEnd()) { + if(socket->state() == QAbstractSocket::UnconnectedState) + { + Logger::instance().log("Client: " + client->getLogin() + " UnconnectedState", LogLevel::ERROR); + break; + } + QByteArray data = file.read(sendFileBlockSize); stream << data; 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++; } @@ -119,111 +283,13 @@ void SendSystem::sendFileBlock(QString path) 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) +void SendSystem::slot_sendFileBlock_V3(QString path) { //qDebug() << "SendSystem::sendFileBlock path: " << path; - if(getIsSendStopped()) + if(slot_getIsSendingStopped()) { //Поведение на случай отключения клиента - Logger::instance().log("Client: " + client->getLogin() + " isSendStopped", LogLevel::ERROR); + Logger::instance().log("Client: " + client->getLogin() + " isSendingStopped", LogLevel::ERROR); return; } @@ -251,7 +317,7 @@ void SendSystem::sendFileBlock_V3(QString path) QDataStream stream(socket); stream.setVersion(QDataStream::Qt_DefaultCompiledVersion); - stream << PacketType::TYPE_FILE; //Отправляем тип блока + stream << PacketType::TYPE_FILE; stream << path << fileSize; waitWrittenData("sendFileBlock:header " + fileInfo.fileName()); @@ -266,18 +332,19 @@ void SendSystem::sendFileBlock_V3(QString path) break; } - qint64 readBytes = file.read(buffer, /*sizeof(buffer)*/sendFileBlockSize); + qint64 readBytes = file.read(buffer, sendFileBlockSize); if(readBytes <= 0) break; - flWaitWriten = true; + flWaitWritenToSocket = true; + while(!socket->write(buffer, readBytes)) - { + { + qCritical() << "socket->write ERROR. size " + QString::number(readBytes); int i = 0; i++; - qCritical() << "socket->write ERROR. size " + QString::number(readBytes); } - while(flWaitWriten) + while(flWaitWritenToSocket) { QCoreApplication::processEvents(); // Обеспечиваем обработку сообщений int i = 0; @@ -295,7 +362,7 @@ void SendSystem::sendFileBlock_V3(QString path) countSend = 0; } -void SendSystem::sendFileBlockByteArray(QByteArray array, PacketType packetType) +void SendSystem::slot_sendFileBlockByteArray(QByteArray array, PacketType packetType) { if(client->getClientType() == TypeClientAutorization::TYPE_QT_CLIENT || client->getClientType() == TypeClientAutorization::TYPE_GUI) @@ -315,21 +382,21 @@ void SendSystem::sendFileBlockByteArray(QByteArray array, PacketType packetType) stream << packetType; //Отправляем тип блока stream << size; - socket->waitForBytesWritten(10); + waitWrittenData("sendFileBlockByteArray"); while (bytesSended < size) { - QByteArray chunk = array.mid(bytesSended,sendFileBlockSize); + QByteArray chunk = array.mid(bytesSended, sendFileBlockSize); stream << chunk; - socket->waitForBytesWritten(10); + waitWrittenData("sendFileBlockByteArray"); bytesSended += chunk.length(); } } else { - sendPacketType(packetType); + slot_sendPacketType(packetType); qint64 size = array.size(); qint64 bytesSended = 0; @@ -345,7 +412,7 @@ void SendSystem::sendFileBlockByteArray(QByteArray array, PacketType packetType) while (size > 0) { - QByteArray chunk = array.mid(bytesSended,sendFileBlockSize); + QByteArray chunk = array.mid(bytesSended, sendFileBlockSize); bytesSended = socket->write(chunk); size -= bytesSended; @@ -354,20 +421,9 @@ void SendSystem::sendFileBlockByteArray(QByteArray array, PacketType packetType) } } -void SendSystem::sendVersion() +void SendSystem::slot_sendFileBlockWithRename(QString path, QString newName) { - QByteArray data = dataParser->ClientAnswer()->currentVersion(); - sendXmlAnswer(data); -} - -void SendSystem::slot_BytesWrittenToSocket(qint64 bytes) -{ - flWaitWriten = false; -} - -void SendSystem::sendFileBlockWithRename(QString path, QString newName) -{ - qDebug() << "SendSystem::sendFileBlockWithRename thread ID " << QThread::currentThreadId(); + //qDebug() << "SendSystem::sendFileBlockWithRename thread ID " << QThread::currentThreadId(); QDataStream stream(socket); stream.setVersion(QDataStream::Qt_DefaultCompiledVersion); @@ -383,26 +439,24 @@ void SendSystem::sendFileBlockWithRename(QString path, QString newName) QString pathForSend = Tools::createFolderPath(path) + "/" + staticDataFolderName + newName; - stream << PacketType::TYPE_FILE; //Отправляем тип блока - + stream << PacketType::TYPE_FILE; stream << pathForSend << fileSize; - socket->waitForBytesWritten(10); + waitWrittenData("sendFileBlockWithRename"); - if(isSendStopped) { //Поведение на случай отключения клиента + if(slot_getIsSendingStopped()) { //Поведение на случай отключения клиента file.close(); return; } - //socket->waitForBytesWritten(); if(file.open(QFile::ReadOnly)){ while(!file.atEnd()){ QByteArray data = file.read(sendFileBlockSize); stream << data; - socket->waitForBytesWritten(10); + waitWrittenData("sendFileBlockWithRename"); countSend++; } @@ -411,181 +465,8 @@ void SendSystem::sendFileBlockWithRename(QString path, QString newName) file.close(); countSend = 0; - socket->waitForBytesWritten(10); + waitWrittenData("sendFileBlockWithRename"); //socket->waitForReadyRead(100); - sendNotify(commandHashCompleteClient); + slot_sendNotify(commandHashCompleteClient); } - -void SendSystem::sendFolderBlock(QString path) -{ - QDataStream stream(socket); - stream.setVersion(QDataStream::Qt_DefaultCompiledVersion); - - stream << PacketType::TYPE_FOLDER; - stream << path; - - waitWrittenData("sendFolderBlock"); -} - -void SendSystem::sendDeleteBlock(QString path) -{ - QDataStream stream(socket); - stream.setVersion(QDataStream::Qt_DefaultCompiledVersion); - - stream << PacketType::TYPE_DELETE; - stream << path; - - waitWrittenData("sendDeleteBlock"); -} - -void SendSystem::sendPacketType(PacketType packetType) -{ - Logger::instance().log(" SEND TO: " + client->getLogin() + " " + enumToString(packetType), LogLevel::DEBUG); - if (client->getClientType() == TypeClientAutorization::TYPE_QT_CLIENT || - client->getClientType() == TypeClientAutorization::TYPE_GUI) - { - QDataStream stream(socket); - stream.setVersion(QDataStream::Qt_DefaultCompiledVersion); - stream << packetType; - - waitWrittenData("sendPacketType"); - } - else - { - QByteArray message; - int type = (int)packetType; - message.append(reinterpret_cast(&type), sizeof(int)); - socket->write(message); - } - -} - -void SendSystem::sendXmlAnswer(QByteArray array, PacketType packetType) -{ - qDebug() << "SendSystem::sendXmlAnswer thread ID " << QThread::currentThreadId(); - - Logger::instance().log("SEND TO: "+ client->getLogin() + " " + enumToString(packetType) + "\n Text: " + - QString(array),LogLevel::DEBUG); - - if (client->getClientType() == TypeClientAutorization::TYPE_QT_CLIENT || - client->getClientType() == TypeClientAutorization::TYPE_GUI) - { - QDataStream stream(socket); - stream.setVersion(QDataStream::Qt_DefaultCompiledVersion); - - stream << packetType; - stream << array; - - waitWrittenData("sendXmlAnswer"); - } - else - { - sendPacketType(packetType); - QByteArray message; - int size = array.length(); - message.append(reinterpret_cast(&size), sizeof(int)); - socket->write(message); - socket->write(array); - } -} - -void SendSystem::sendNeedUpdate(bool flag,quint64 size,quint64 fileCount,quint64 deleteCount) -{ - QDataStream stream(socket); - stream.setVersion(QDataStream::Qt_DefaultCompiledVersion); - stream << PacketType::TYPE_NEEDUPDATE; - stream << flag; - stream << size; - stream << fileCount; - stream << deleteCount; - - waitWrittenData("sendNeedUpdate"); -} - -void SendSystem::updateFiles(QList fileSendList, QList deleteList) -{ - //globalMutex->lock(); - - QListIterator clientIterator(deleteList); - - while(clientIterator.hasNext()) - { - FileData data = clientIterator.next(); - - sendDeleteBlock(data.path); - if(getIsSendStopped()) - { - Logger::instance().log("Client: " + client->getLogin() + " isSendStopped", LogLevel::ERROR); - //globalMutex->unlock(); - return; - } - } - - QListIterator serverIterator(fileSendList); - - while(serverIterator.hasNext()) - { - FileData data = serverIterator.next(); - - if (data.hash == "FOLDER") - { - sendFolderBlock(data.path); - } - else - { - sendFileBlock_V3(data.path); - } - - if(getIsSendStopped()) - { - //globalMutex->unlock(); - return; - } - } - - sendPacketType(PacketType::UPDATE_FILES_COMPLETE); - - //globalMutex->unlock(); -} - - -void SendSystem::socketClose() -{ - socket->close(); -} - -void SendSystem::sendStop() -{ - isSendStopped = true; -} - -void SendSystem::sendCFI(QByteArray array) -{ - sendXmlAnswer(array,PacketType::TYPE_UPDATEDCFI); -} - -void SendSystem::sendDocs(QString docsPath) -{ - sendFileBlock(docsPath); -} - -bool SendSystem::getIsSendStopped() const -{ - return isSendStopped; -} - -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; -} - diff --git a/LibServer/Systems/sendsystem.h b/LibServer/Systems/sendsystem.h index 140f9c9..121afd9 100644 --- a/LibServer/Systems/sendsystem.h +++ b/LibServer/Systems/sendsystem.h @@ -13,9 +13,9 @@ class DataParser; class FileData; + class SendSystem : public QObject { - Q_OBJECT public: explicit SendSystem(QObject* parent = nullptr); @@ -24,58 +24,57 @@ public: void initialize(DataParser* dataParser,QMutex *globalMutex); void setClient(Client* client,QTcpSocket *socket); - void sendMessageBlock(QString message); - void sendFileBlock(QString path); - void sendFileBlock_V2(QString path); - void sendFileBlock_V3(QString path); - void sendFileBlockByteArray(QByteArray array, PacketType packetType); - void sendFileBlockWithRename(QString path,QString newName); - void sendFolderBlock(QString path); - void sendDeleteBlock(QString path); - void sendPacketType(PacketType packet); - void sendNotify(QString notify); - void sendStop(); - void sendCFI(QByteArray array); - void sendDocs(QString docPath); - void sendXmlAnswer(QByteArray array, PacketType packetType = PacketType::TYPE_XMLANSWER); - void sendNeedUpdate(bool flag,quint64 size,quint64 fileCount,quint64 deleteCount); - void updateFiles(QList fileSendList, QList deleteList); - bool getIsSendStopped() const; - - void updateFilesFULL(QList fileSendList, QList deleteList); - +private: bool waitWrittenData(QString marker, int msec = 500); -public slots: - void socketClose(); - void sendVersion(); - +public slots: void slot_BytesWrittenToSocket(qint64 bytes); + bool slot_getIsSendingStopped() const; + void slot_stopSending(); + + void slot_socketClose(); + + void slot_sendVersion(); + + void slot_sendNotify(QString notify); + void slot_sendPacketType(PacketType packet); + void slot_sendXmlAnswer(QByteArray array, PacketType packetType = PacketType::TYPE_XMLANSWER); + + void slot_sendDocs(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_sendFileBlockByteArray(QByteArray array, PacketType packetType); + void slot_sendFileBlockWithRename(QString path,QString newName); + signals: - void sigLoadHash(); - //QByteArray sigSendXMLmessage(QString loginFrom, QString loginTo, QString text, QString userType); //сигнал не используется QByteArray sigSendNotify(QString message); - //QByteArray sigSendVersion(); //сигнал не используется private: Client *client; QTcpSocket* socket; DataParser* dataParser; - QMutex *globalMutex; - QWaitCondition *waitCondition; + QMutex *globalMutex; //Не используется (но пока оставлен) char* buffer; TypeClientAutorization type; - bool isSendStopped; - bool flWaitWriten; + bool flSendingStopped; - quint64 fileSize; + bool flWaitWritenToSocket; + qint64 bytesWritedToSocket; + + qint64 fileSize; int countSend; }; diff --git a/LibServer/clienthandler/clienthandler.cpp b/LibServer/clienthandler/clienthandler.cpp index 7f4eb4c..8e0b7bb 100644 --- a/LibServer/clienthandler/clienthandler.cpp +++ b/LibServer/clienthandler/clienthandler.cpp @@ -42,21 +42,21 @@ void ClientHandler::initialize(int descriptor, connect(recognizeSystem,&RecognizeSystem::signal_updateDocsXML,this,&ClientHandler::signal_updateDocsXML); - connect(this,&ClientHandler::sigSendXmlAnswer,sendSystem,&SendSystem::sendXmlAnswer,Qt::AutoConnection); + 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::sendFileBlock,Qt::AutoConnection); - connect(this,&ClientHandler::sigFileBlockByteArray,sendSystem,&SendSystem::sendFileBlockByteArray,Qt::AutoConnection); - connect(this,&ClientHandler::sigFolderBlock,sendSystem,&SendSystem::sendFolderBlock,Qt::AutoConnection); - connect(this,&ClientHandler::sigGetIsSendStopped,sendSystem,&SendSystem::getIsSendStopped,/*Qt::AutoConnection*/Qt::DirectConnection); //Возвращает значение - connect(this,&ClientHandler::sigSendDeleteBlock,sendSystem,&SendSystem::sendDeleteBlock,Qt::AutoConnection); - connect(this,&ClientHandler::sigNeedUpdate,sendSystem,&SendSystem::sendNeedUpdate,Qt::AutoConnection); - connect(this,&ClientHandler::sigSendNotify,sendSystem,&SendSystem::sendNotify,Qt::AutoConnection); - connect(this,&ClientHandler::sigSendFileBlockWithRename,sendSystem,&SendSystem::sendFileBlockWithRename,Qt::AutoConnection); - connect(this,&ClientHandler::sigSendVersion,sendSystem,&SendSystem::sendVersion,Qt::AutoConnection); - connect(this,&ClientHandler::sigSocketClose,sendSystem,&SendSystem::socketClose,Qt::AutoConnection); + connect(this,&ClientHandler::sigFileBlock,sendSystem,&SendSystem::slot_sendFileBlock,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::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); //не используется - connect(this,&ClientHandler::sigSendPacketType,sendSystem,&SendSystem::sendPacketType,Qt::AutoConnection); - connect(this,&ClientHandler::sigSendStop,sendSystem,&SendSystem::sendStop,Qt::DirectConnection); + connect(this,&ClientHandler::sigSendPacketType,sendSystem,&SendSystem::slot_sendPacketType,Qt::AutoConnection); + connect(this,&ClientHandler::sigSendStop,sendSystem,&SendSystem::slot_stopSending,Qt::DirectConnection); connect(socket,&QTcpSocket::readyRead,this,&ClientHandler::initClientType,Qt::AutoConnection); initClientType();