Add sendMessage to fileprovidersocketcontroller

Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
This commit is contained in:
Claudio Cambra 2022-12-28 17:46:12 +01:00
parent 28a79d4767
commit 9f2fff3782
No known key found for this signature in database
GPG Key ID: C839200C384636B0
2 changed files with 21 additions and 0 deletions

View File

@ -57,6 +57,24 @@ void FileProviderSocketController::slotReadyRead()
}
}
void FileProviderSocketController::sendMessage(const QString &message) const
{
if (!_socket) {
qCWarning(lcFileProviderSocketController) << "Not sending message on dead file provider socket:" << message;
return;
}
qCDebug(lcFileProviderSocketController) << "Sending File Provider socket message:" << message;
const auto lineEndChar = '\n';
const auto messageToSend = message.endsWith(lineEndChar) ? message : message + lineEndChar;
const auto bytesToSend = messageToSend.toUtf8();
const auto sent = _socket->write(bytesToSend);
if (sent != bytesToSend.length()) {
qCWarning(lcFileProviderSocketController) << "Could not send all data on file provider socket for:" << message;
}
}
}
}

View File

@ -32,6 +32,9 @@ public:
signals:
void socketDestroyed(const QLocalSocket * const socket);
public slots:
void sendMessage(const QString &message) const;
private slots:
void slotOnDisconnected();
void slotSocketDestroyed(QObject *object);