@@ -296,15 +296,22 @@ void SocketApi::slotNewConnection()
296
296
{
297
297
// Note that on macOS this is not actually a line-based QIODevice, it's a SocketApiSocket which is our
298
298
// custom message based macOS IPC.
299
- QIODevice *socket = _localServer.nextPendingConnection ();
299
+ SocketApiSocket *socket = _localServer.nextPendingConnection ();
300
300
301
301
if (!socket) {
302
302
return ;
303
303
}
304
304
qCInfo (lcSocketApi) << " New connection" << socket;
305
- connect (socket, &QIODevice::readyRead, this , &SocketApi::slotReadSocket);
306
- connect (socket, SIGNAL (disconnected ()), this , SLOT (onLostConnection ()));
307
- connect (socket, &QObject::destroyed, this , &SocketApi::slotSocketDestroyed);
305
+ connect (socket, &SocketApiSocket::readyRead, this , &SocketApi::slotReadSocket);
306
+ connect (socket, &SocketApiSocket::disconnected, this , [socket] {
307
+ qCInfo (lcSocketApi) << " Lost connection " << socket;
308
+ // will trigger destroyed in the next execution of the main loop
309
+ // a direct removal can cause issues when iterating on _listeners
310
+ socket->deleteLater ();
311
+ });
312
+ connect (socket, &SocketApiSocket::destroyed, this , [socket, this ] {
313
+ _listeners.remove (socket);
314
+ });
308
315
OC_ASSERT (socket->readAll ().isEmpty ());
309
316
310
317
auto listener = QSharedPointer<SocketListener>::create (socket);
@@ -317,25 +324,9 @@ void SocketApi::slotNewConnection()
317
324
}
318
325
}
319
326
320
- void SocketApi::onLostConnection ()
321
- {
322
- qCInfo (lcSocketApi) << " Lost connection " << sender ();
323
- sender ()->deleteLater ();
324
-
325
- auto socket = qobject_cast<QIODevice *>(sender ());
326
- OC_ASSERT (socket);
327
- _listeners.remove (socket);
328
- }
329
-
330
- void SocketApi::slotSocketDestroyed (QObject *obj)
331
- {
332
- QIODevice *socket = static_cast <QIODevice *>(obj);
333
- _listeners.remove (socket);
334
- }
335
-
336
327
void SocketApi::slotReadSocket ()
337
328
{
338
- QIODevice *socket = qobject_cast<QIODevice *>(sender ());
329
+ SocketApiSocket *socket = qobject_cast<SocketApiSocket *>(sender ());
339
330
OC_ENFORCE (socket);
340
331
341
332
// Find the SocketListener
@@ -432,10 +423,7 @@ void SocketApi::slotRegisterPath(const QString &alias)
432
423
433
424
Folder *f = FolderMan::instance ()->folder (alias);
434
425
if (f) {
435
- const QString message = buildRegisterPathMessage (removeTrailingSlash (f->path ()));
436
- for (const auto &listener : qAsConst (_listeners)) {
437
- listener->sendMessage (message);
438
- }
426
+ broadcastMessage (buildRegisterPathMessage (removeTrailingSlash (f->path ())));
439
427
}
440
428
441
429
_registeredAliases.insert (alias);
0 commit comments