SocketAPI: Add parameter to enable wait for the socket write.

This is needed to wait until the UNREGISTER message is sent to the
shell code when mirall shuts down.
This commit is contained in:
Klaas Freitag 2014-08-20 16:24:06 +02:00
parent 4356005c5a
commit d1a660ce20
2 changed files with 9 additions and 6 deletions

View file

@ -261,7 +261,7 @@ void SocketApi::slotUnregisterPath( const QString& alias )
{
Folder *f = FolderMan::instance()->folder(alias);
if (f) {
broadcastMessage(QLatin1String("UNREGISTER_PATH"), f->path() );
broadcastMessage(QLatin1String("UNREGISTER_PATH"), f->path(), QString::null, true );
}
}
@ -304,7 +304,7 @@ void SocketApi::slotJobCompleted(const QString &folder, const SyncFileItem &item
void SocketApi::sendMessage(QTcpSocket *socket, const QString& message)
void SocketApi::sendMessage(QTcpSocket *socket, const QString& message, bool doWait)
{
DEBUG << "Sending message: " << message;
QString localMessage = message;
@ -312,13 +312,16 @@ void SocketApi::sendMessage(QTcpSocket *socket, const QString& message)
localMessage.append(QLatin1Char('\n'));
}
qint64 sent = socket->write(localMessage.toUtf8());
if( doWait ) {
socket->waitForBytesWritten(1000);
}
if( sent != localMessage.toUtf8().length() ) {
qDebug() << "WARN: Could not send all data on socket for " << localMessage;
}
}
void SocketApi::broadcastMessage( const QString& verb, const QString& path, const QString& status )
void SocketApi::broadcastMessage( const QString& verb, const QString& path, const QString& status, bool doWait )
{
QString msg(verb);
@ -333,7 +336,7 @@ void SocketApi::broadcastMessage( const QString& verb, const QString& path, cons
DEBUG << "Broadcasting to" << _listeners.count() << "listeners: " << msg;
foreach(QTcpSocket *socket, _listeners) {
sendMessage(socket, msg);
sendMessage(socket, msg, doWait);
}
}

View file

@ -48,8 +48,8 @@ private slots:
void slotJobCompleted(const QString &, const SyncFileItem &);
private:
void sendMessage(QTcpSocket* socket, const QString& message);
void broadcastMessage(const QString& verb, const QString &path, const QString &status = QString::null);
void sendMessage(QTcpSocket* socket, const QString& message, bool doWait = false);
void broadcastMessage(const QString& verb, const QString &path, const QString &status = QString::null, bool doWait = false);
Q_INVOKABLE void command_RETRIEVE_FOLDER_STATUS(const QString& argument, QTcpSocket* socket);
Q_INVOKABLE void command_RETRIEVE_FILE_STATUS(const QString& argument, QTcpSocket* socket);