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()
{
connect(this,&Logger::sigAddToLogger, this, &Logger::handleLog,Qt::QueuedConnection);
connect(this,&Logger::sigAddToLogger, this, &Logger::handleLog,Qt::AutoConnection);
createDirectory();
}

View File

@@ -14,7 +14,6 @@ void SendSystem::initialize(DataParser *dataParser,QMutex *globalMutex)
qDebug() << "SendSystem thread: " << QThread::currentThreadId();
mutex = globalMutex;
}
void SendSystem::setClient(Client *client,QTcpSocket *socket)
@@ -33,16 +32,14 @@ void SendSystem::sendMessageBlock(QString message)
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);
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());
if(isSendStopped)
{ //Поведение на случай отключения клиента
{ //Поведение на случай отключения клиента
file.close();
Logger::instance().log("UNLOCK STOP MUTEX : " + client->getLogin(),LogLevel::ERROR);
return;
@@ -84,13 +81,11 @@ void SendSystem::sendFileBlock(QString path)
file.close();
Logger::instance().log("CLOSE FILE : " + client->getLogin() + " " + fileInfo.fileName());
countSend = 0;
Logger::instance().log("UNLOCK MUTEX : " + client->getLogin(),LogLevel::WARNING);
}
void SendSystem::sendFileBlockByteArray(QByteArray array, PacketType packetType)
{
qDebug() << "sendFileBlockByteArray thread: " << QThread::currentThreadId();
QMutexLocker locker(mutex);
if(client->GETTYPE() == TypeClientAutorization::TYPE_QT_CLIENT ||
client->GETTYPE() == TypeClientAutorization::TYPE_GUI)
{
@@ -129,7 +124,6 @@ void SendSystem::sendVersion()
void SendSystem::sendFileBlockWithRename(QString path, QString newName)
{
QMutexLocker locker(mutex);
qDebug() << "sendFileBlockWithRename thread: " << QThread::currentThreadId();
QDataStream stream(socket);
@@ -201,7 +195,6 @@ void SendSystem::sendDeleteBlock(QString path)
void SendSystem::sendPacketType(PacketType packetType)
{
QMutexLocker locker(mutex);
if (client->GETTYPE() == TypeClientAutorization::TYPE_QT_CLIENT ||
client->GETTYPE() == TypeClientAutorization::TYPE_GUI)
{
@@ -227,7 +220,6 @@ void SendSystem::sendHello()
void SendSystem::sendNotify(QString notify)
{
QMutexLocker locker(mutex);
qDebug() << "SendNotify thread: " << QThread::currentThreadId();
auto answer = emit sigSendNotify(notify);//"END");
sendXmlAnswer(answer);
@@ -235,7 +227,6 @@ void SendSystem::sendNotify(QString notify)
void SendSystem::sendXmlAnswer(QByteArray array, PacketType packetType)
{
QMutexLocker locker(mutex);
qDebug() << "SendSystemThread: " << QThread::currentThreadId();
if (client->GETTYPE() == TypeClientAutorization::TYPE_QT_CLIENT ||
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){
mutex->lock();
QListIterator<FileData> clientIterator(deleteList);
while(clientIterator.hasNext())
@@ -278,7 +270,11 @@ void SendSystem::updateFiles(QList<FileData> fileSendList, QList<FileData> delet
FileData data = clientIterator.next();
sendDeleteBlock(data.path);
if(getIsSendStopped()) return;
if(getIsSendStopped())
{
mutex->unlock();
return;
}
}
QListIterator<FileData> serverIterator(fileSendList);
@@ -298,12 +294,18 @@ void SendSystem::updateFiles(QList<FileData> fileSendList, QList<FileData> delet
socket->waitForBytesWritten();
}
if(isSendStopped) return;
if(isSendStopped)
{
mutex->unlock();
return;
}
}
emit sigLoadHash();
sendPacketType(PacketType::TYPE_FINISH);
socket->waitForBytesWritten();
mutex->unlock();
}
void SendSystem::socketWrite(QByteArray array)

View File

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