Use exit handler to ensure socket is removed

This commit is contained in:
craig.p.drummond
2014-03-24 20:42:54 +00:00
committed by craig.p.drummond
parent 0f21c1f2c6
commit 835c68eacd
2 changed files with 15 additions and 8 deletions

View File

@@ -36,27 +36,35 @@
#include <signal.h>
#include <unistd.h>
#endif
#include <stdlib.h>
static QString socketName;
static void deleteSocket()
{
// Just in case Cantata has crashed, ensure we delete the socket...
if (!socketName.isEmpty()) {
QLocalServer::removeServer(socketName);
}
}
TagServer::TagServer(const QString &sockName, int parent)
: socketName(sockName)
, parentPid(parent)
: parentPid(parent)
{
socket=new QLocalSocket(this);
socket->connectToServer(socketName);
socket->connectToServer(sockName);
connect(socket, SIGNAL(readyRead()), SLOT(process()));
connect(socket, SIGNAL(disconnected()), qApp, SLOT(quit()));
QTimer *timer=new QTimer(this);
timer->setSingleShot(false);
timer->start(5000);
connect(timer, SIGNAL(timeout()), SLOT(checkParent()));
socketName=sockName;
atexit(deleteSocket);
}
TagServer::~TagServer()
{
// Just in case Cantata has crashed, ensure we delete the socket...
if (!socketName.isEmpty()) {
QLocalServer::removeServer(socketName);
}
}
void TagServer::process()

View File

@@ -41,7 +41,6 @@ private Q_SLOTS:
void checkParent();
private:
QString socketName;
int parentPid;
QLocalSocket *socket;
};