Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QLockFile instead of QLockedFile #21557

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 8 additions & 22 deletions src/app/qtlocalpeer/qtlocalpeer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,37 +78,23 @@
#include <QFileInfo>
#include <QLocalServer>
#include <QLocalSocket>

namespace QtLP_Private
{
#include "qtlockedfile.cpp"

#if defined(Q_OS_WIN)
#include "qtlockedfile_win.cpp"
#else
#include "qtlockedfile_unix.cpp"
#endif
}
#include <QLockFile>

const char ACK[] = "ack";

QtLocalPeer::QtLocalPeer(const QString &path, QObject *parent)
: QObject(parent)
, m_socketName(path + u"/ipc-socket")
, m_server(new QLocalServer(this))
, m_lockFile(path + u"/lockfile")
{
m_server->setSocketOptions(QLocalServer::UserAccessOption);

m_lockFile.setFileName(path + u"/lockfile");
m_lockFile.open(QIODevice::ReadWrite);
}

QtLocalPeer::~QtLocalPeer()
{
if (!isClient())
{
m_lockFile.unlock();
m_lockFile.remove();
}
}

Expand All @@ -117,7 +103,7 @@ bool QtLocalPeer::isClient()
if (m_lockFile.isLocked())
return false;

if (!m_lockFile.lock(QtLP_Private::QtLockedFile::WriteLock, false))
if (!m_lockFile.lock())
return true;

bool res = m_server->listen(m_socketName);
Expand Down Expand Up @@ -150,18 +136,18 @@ bool QtLocalPeer::sendMessage(const QString &message, const int timeout)
connOk = socket.waitForConnected(timeout/2);
if (connOk || i)
break;
int ms = 250;
const int ms = 250;
#if defined(Q_OS_WIN)
::Sleep(DWORD(ms));
#else
struct timespec ts = { ms / 1000, (ms % 1000) * 1000 * 1000 };
const struct timespec ts = { ms / 1000, (ms % 1000) * 1000 * 1000 };
::nanosleep(&ts, nullptr);
#endif
}
if (!connOk)
return false;

QByteArray uMsg(message.toUtf8());
const QByteArray uMsg(message.toUtf8());
QDataStream ds(&socket);
ds.writeBytes(uMsg.constData(), uMsg.size());
bool res = socket.waitForBytesWritten(timeout);
Expand All @@ -188,14 +174,14 @@ void QtLocalPeer::receiveConnection()
delete socket;
return;
}
if (socket->bytesAvailable() >= qint64(sizeof(quint32)))
if (socket->bytesAvailable() >= int64_t(sizeof(int32_t)))
break;
socket->waitForReadyRead();
}

QDataStream ds(socket);
QByteArray uMsg;
quint32 remaining;
uint32_t remaining;
ds >> remaining;
if (remaining > 65535)
{
Expand Down
10 changes: 4 additions & 6 deletions src/app/qtlocalpeer/qtlocalpeer.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,8 @@
#pragma once

#include <QString>

#include "qtlockedfile.h"

class QLocalServer;
#include <QLockFile>
#include <QLocalServer>

class QtLocalPeer final : public QObject
{
Expand All @@ -94,6 +92,6 @@ private slots:

private:
QString m_socketName;
QLocalServer *m_server = nullptr;
QtLP_Private::QtLockedFile m_lockFile;
QLocalServer *m_server = new QLocalServer(this);
QLockFile m_lockFile;
};
209 changes: 0 additions & 209 deletions src/app/qtlocalpeer/qtlockedfile.cpp

This file was deleted.

Loading
Loading