quickfix: connection

This commit is contained in:
semenov
2025-08-07 14:38:40 +03:00
parent 34dddad3cd
commit 28ea4338e0
4 changed files with 19 additions and 16 deletions

View File

@@ -4,7 +4,7 @@
Logger::Logger() Logger::Logger()
{ {
connect(this,&Logger::sigAddToLogger, this, &Logger::handleLog,Qt::QueuedConnection); connect(this,&Logger::sigAddToLogger, this, &Logger::handleLog,Qt::AutoConnection);
createDirectory(); createDirectory();
} }

View File

@@ -14,7 +14,6 @@ void SendSystem::initialize(DataParser *dataParser,QMutex *globalMutex)
qDebug() << "SendSystem thread: " << QThread::currentThreadId(); qDebug() << "SendSystem thread: " << QThread::currentThreadId();
mutex = globalMutex; mutex = globalMutex;
} }
void SendSystem::setClient(Client *client,QTcpSocket *socket) void SendSystem::setClient(Client *client,QTcpSocket *socket)
@@ -33,12 +32,10 @@ void SendSystem::sendMessageBlock(QString message)
void SendSystem::sendFileBlock(QString path) void SendSystem::sendFileBlock(QString path)
{ {
//qDebug() << "sendFileBlock thread: " << QThread::currentThreadId();
Logger::instance().log("TRY LOCK MUTEX : " + client->getLogin(),LogLevel::WARNING);
QMutexLocker locker(mutex);
Logger::instance().log("LOCK MUTEX " + client->getLogin(),LogLevel::WARNING);
QFile file(path); QFile file(path);
QFileInfo fileInfo(file); QFileInfo fileInfo(file);
if(file.isOpen()) Logger::instance().log("ALREADY OPEN FILE : " + client->getLogin() + " " + fileInfo.filePath());
Logger::instance().log("OPEN FILE : " + client->getLogin() + " " + fileInfo.fileName()); Logger::instance().log("OPEN FILE : " + client->getLogin() + " " + fileInfo.fileName());
if(isSendStopped) if(isSendStopped)
@@ -84,13 +81,11 @@ void SendSystem::sendFileBlock(QString path)
file.close(); file.close();
Logger::instance().log("CLOSE FILE : " + client->getLogin() + " " + fileInfo.fileName()); Logger::instance().log("CLOSE FILE : " + client->getLogin() + " " + fileInfo.fileName());
countSend = 0; countSend = 0;
Logger::instance().log("UNLOCK MUTEX : " + client->getLogin(),LogLevel::WARNING);
} }
void SendSystem::sendFileBlockByteArray(QByteArray array, PacketType packetType) void SendSystem::sendFileBlockByteArray(QByteArray array, PacketType packetType)
{ {
qDebug() << "sendFileBlockByteArray thread: " << QThread::currentThreadId(); qDebug() << "sendFileBlockByteArray thread: " << QThread::currentThreadId();
QMutexLocker locker(mutex);
if(client->GETTYPE() == TypeClientAutorization::TYPE_QT_CLIENT || if(client->GETTYPE() == TypeClientAutorization::TYPE_QT_CLIENT ||
client->GETTYPE() == TypeClientAutorization::TYPE_GUI) client->GETTYPE() == TypeClientAutorization::TYPE_GUI)
{ {
@@ -129,7 +124,6 @@ void SendSystem::sendVersion()
void SendSystem::sendFileBlockWithRename(QString path, QString newName) void SendSystem::sendFileBlockWithRename(QString path, QString newName)
{ {
QMutexLocker locker(mutex);
qDebug() << "sendFileBlockWithRename thread: " << QThread::currentThreadId(); qDebug() << "sendFileBlockWithRename thread: " << QThread::currentThreadId();
QDataStream stream(socket); QDataStream stream(socket);
@@ -201,7 +195,6 @@ void SendSystem::sendDeleteBlock(QString path)
void SendSystem::sendPacketType(PacketType packetType) void SendSystem::sendPacketType(PacketType packetType)
{ {
QMutexLocker locker(mutex);
if (client->GETTYPE() == TypeClientAutorization::TYPE_QT_CLIENT || if (client->GETTYPE() == TypeClientAutorization::TYPE_QT_CLIENT ||
client->GETTYPE() == TypeClientAutorization::TYPE_GUI) client->GETTYPE() == TypeClientAutorization::TYPE_GUI)
{ {
@@ -227,7 +220,6 @@ void SendSystem::sendHello()
void SendSystem::sendNotify(QString notify) void SendSystem::sendNotify(QString notify)
{ {
QMutexLocker locker(mutex);
qDebug() << "SendNotify thread: " << QThread::currentThreadId(); qDebug() << "SendNotify thread: " << QThread::currentThreadId();
auto answer = emit sigSendNotify(notify);//"END"); auto answer = emit sigSendNotify(notify);//"END");
sendXmlAnswer(answer); sendXmlAnswer(answer);
@@ -235,7 +227,6 @@ void SendSystem::sendNotify(QString notify)
void SendSystem::sendXmlAnswer(QByteArray array, PacketType packetType) void SendSystem::sendXmlAnswer(QByteArray array, PacketType packetType)
{ {
QMutexLocker locker(mutex);
qDebug() << "SendSystemThread: " << QThread::currentThreadId(); qDebug() << "SendSystemThread: " << QThread::currentThreadId();
if (client->GETTYPE() == TypeClientAutorization::TYPE_QT_CLIENT || if (client->GETTYPE() == TypeClientAutorization::TYPE_QT_CLIENT ||
client->GETTYPE() == TypeClientAutorization::TYPE_GUI) client->GETTYPE() == TypeClientAutorization::TYPE_GUI)
@@ -271,6 +262,7 @@ void SendSystem::sendNeedUpdate(bool flag,quint64 size,quint64 fileCount,quint64
void SendSystem::updateFiles(QList<FileData> fileSendList, QList<FileData> deleteList){ void SendSystem::updateFiles(QList<FileData> fileSendList, QList<FileData> deleteList){
mutex->lock();
QListIterator<FileData> clientIterator(deleteList); QListIterator<FileData> clientIterator(deleteList);
while(clientIterator.hasNext()) while(clientIterator.hasNext())
@@ -278,7 +270,11 @@ void SendSystem::updateFiles(QList<FileData> fileSendList, QList<FileData> delet
FileData data = clientIterator.next(); FileData data = clientIterator.next();
sendDeleteBlock(data.path); sendDeleteBlock(data.path);
if(getIsSendStopped()) return; if(getIsSendStopped())
{
mutex->unlock();
return;
}
} }
QListIterator<FileData> serverIterator(fileSendList); QListIterator<FileData> serverIterator(fileSendList);
@@ -298,12 +294,18 @@ void SendSystem::updateFiles(QList<FileData> fileSendList, QList<FileData> delet
socket->waitForBytesWritten(); socket->waitForBytesWritten();
} }
if(isSendStopped) return; if(isSendStopped)
{
mutex->unlock();
return;
}
} }
emit sigLoadHash(); emit sigLoadHash();
sendPacketType(PacketType::TYPE_FINISH); sendPacketType(PacketType::TYPE_FINISH);
socket->waitForBytesWritten();
mutex->unlock();
} }
void SendSystem::socketWrite(QByteArray array) void SendSystem::socketWrite(QByteArray array)

View File

@@ -59,6 +59,7 @@ private:
DataParser* dataParser; DataParser* dataParser;
quint64 fileSize; quint64 fileSize;
QMutex *mutex; QMutex *mutex;
QWaitCondition *waitCondition;
int countSend; int countSend;
bool isSendStopped; bool isSendStopped;
TypeClientAutorization type; TypeClientAutorization type;

View File

@@ -40,7 +40,7 @@ void ClientHandler::initialize(int descriptor,ServerLMSWidget *serverWidget,
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); connect(this,&ClientHandler::sigInitSender,sendSystem,&SendSystem::initialize,Qt::AutoConnection);
connect(this,&ClientHandler::sigFileBlock,sendSystem,&SendSystem::sendFileBlock,Qt::QueuedConnection); 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);
connect(this,&ClientHandler::sigGetIsSendStopped,sendSystem,&SendSystem::getIsSendStopped,Qt::AutoConnection); connect(this,&ClientHandler::sigGetIsSendStopped,sendSystem,&SendSystem::getIsSendStopped,Qt::AutoConnection);