Sonic::Ipc::Connection Class
One framed connection over a QLocalSocket. More...
- Header:
#include <Sonic/Ipc/Connection> - CMake:
find_package(SonicIpc REQUIRED)
target_link_libraries(mytarget PRIVATE Sonic::Ipc) - Inherits: QObject
List of all members, including inherited members
Public Functions
- Connection(QLocalSocket *socket, quint16 protocolVersion, qint64 maxPayload = defaultMaxPayload, QObject *parent = nullptr)
- std::optional<Sonic::Ipc::Connection::PeerCredentials> peerCredentials() const
- quint16 protocolVersion() const
- bool send(quint32 type, QByteArrayView payload)
- bool sendBlocking(quint32 type, QByteArrayView payload, int msecs)
- QLocalSocket *socket() const
- std::optional<Sonic::Ipc::Frame> waitForFrame(int msecs)
Signals
- void disconnected()
- void frameReceived(quint32 type, const QByteArray &payload)
- void protocolError(const QString &reason)
- void versionRejected(quint16 peerVersion)
Detailed Description
Frames arrive through frameReceived(); threads without an event loop use waitForFrame() and sendBlocking() instead. A protocol error aborts the socket.
Member Function Documentation
Connection::Connection(QLocalSocket *socket, quint16 protocolVersion, qint64 maxPayload = defaultMaxPayload, QObject *parent = nullptr)
Takes socket and reparents it to this connection, which speaks application protocol protocolVersion and rejects payloads larger than maxPayload bytes. parent is the connection's parent.
[signal] void Connection::disconnected()
The socket disconnected.
[signal] void Connection::frameReceived(quint32 type, const QByteArray &payload)
A frame of type with payload arrived.
std::optional<Sonic::Ipc::Connection::PeerCredentials> Connection::peerCredentials() const
The process at the other end; nothing when the socket has no descriptor or the system doesn't tell.
[signal] void Connection::protocolError(const QString &reason)
The peer sent data this side rejects, for the given reason; the socket is aborted. A peer with another protocol version is told so first.
quint16 Connection::protocolVersion() const
The application protocol version this side speaks.
bool Connection::send(quint32 type, QByteArrayView payload)
Writes a frame of type with payload; false when the socket isn't connected, the write fails, or type is the reserved Frame::VersionRejected.
bool Connection::sendBlocking(quint32 type, QByteArrayView payload, int msecs)
Writes a frame of type with payload, then waits until everything is written or msecs pass (-1: no timeout).
QLocalSocket *Connection::socket() const
The connection's socket.
[signal] void Connection::versionRejected(quint16 peerVersion)
The peer rejected this side's protocol version; it speaks peerVersion.
std::optional<Sonic::Ipc::Frame> Connection::waitForFrame(int msecs)
Blocks until a frame arrives or msecs pass (-1: no timeout).