io/socket: add flush()

This commit is contained in:
outfoxxed 2024-04-18 04:13:20 -07:00
parent a06af243ad
commit 23d0c2e01d
Signed by untrusted user: outfoxxed
GPG key ID: 4C88A185FB89301E
2 changed files with 26 additions and 1 deletions

View file

@ -2,6 +2,7 @@
#include <qlocalserver.h>
#include <qlocalsocket.h>
#include <qloggingcategory.h>
#include <qobject.h>
#include <qqmlcomponent.h>
#include <qqmlintegration.h>
@ -11,6 +12,8 @@
#include "../core/reload.hpp"
#include "datastream.hpp"
Q_DECLARE_LOGGING_CATEGORY(logSocket);
///! Unix socket listener.
class Socket: public DataStream {
Q_OBJECT;
@ -30,8 +33,13 @@ public:
explicit Socket(QObject* parent = nullptr): DataStream(parent) {}
/// Write data to the socket. Does nothing if not connected.
///
/// Remember to call flush after your last write.
Q_INVOKABLE void write(const QString& data);
/// Flush any queued writes to the socket.
Q_INVOKABLE void flush();
// takes ownership
void setSocket(QLocalSocket* socket);
@ -54,6 +62,7 @@ protected:
private slots:
void onSocketConnected();
void onSocketDisconnected();
void onSocketError(QLocalSocket::LocalSocketError error);
private:
void connectPathSocket();