Merge pull request #1678 from defnax/fix-retroshare-ipc

Fix retroshare ipc
This commit is contained in:
csoler 2019-10-11 20:42:44 +02:00 committed by GitHub
commit 66d31d7629
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -241,6 +241,11 @@ Rshare::Rshare(QStringList args, int &argc, char **argv, const QString &dir)
localServer= new QLocalServer(); localServer= new QLocalServer();
QObject::connect(localServer, SIGNAL(newConnection()), this, SLOT(slotConnectionEstablished())); QObject::connect(localServer, SIGNAL(newConnection()), this, SLOT(slotConnectionEstablished()));
updateLocalServer(); updateLocalServer();
// clear out any old arguments (race condition?)
QSharedMemory newArgs;
newArgs.setKey(QString(TARGET) + "_newArgs");
if(newArgs.attach(QSharedMemory::ReadWrite))
newArgs.detach();
} }
} }
@ -325,20 +330,27 @@ Rshare::~Rshare()
*/ */
void Rshare::slotConnectionEstablished() void Rshare::slotConnectionEstablished()
{ {
QLocalSocket *socket = localServer->nextPendingConnection();
socket->close();
delete socket;
QSharedMemory newArgs; QSharedMemory newArgs;
newArgs.setKey(QString(TARGET) + "_newArgs"); newArgs.setKey(QString(TARGET) + "_newArgs");
QLocalSocket *socket = localServer->nextPendingConnection();
if (!newArgs.attach()) if (!newArgs.attach())
{ {
std::cerr << "(EE) Rshare::slotConnectionEstablished() Unable to attach to shared memory segment." /* this is not an error. It just means we were notified to check
<< newArgs.errorString().toStdString() << std::endl; newArgs, but none had been set yet.
TODO: implement separate ping/take messages
std::cerr << "(EE) Rshare::slotConnectionEstablished() Unable to attach to shared memory segment."
<< newArgs.errorString().toStdString() << std::endl;
*/
socket->close();
delete socket;
return; return;
} }
socket->close();
delete socket;
QBuffer buffer; QBuffer buffer;
QDataStream in(&buffer); QDataStream in(&buffer);
QStringList args; QStringList args;