QtCraft API C++ classes QML types Handbook

QcConnection Class

Message-level view of a transport: encodes outgoing messages, decodes incoming frames and closes the link on undecodable input. More...

Header: #include <common/protocol/QcConnection.h>
Inherits: QObject

Public Types

Handler

Public Functions

QcConnection(std::unique_ptr<QcTransport> transport, QcProtocol::Peer remote, QcConnection::Handler handler, QObject *parent = nullptr)
QcConnection(const QcConnection &)
QcConnection(QcConnection &&)
void close()
bool isOpen() const
QString lastError() const
qint64 pendingBytes() const
void send(const QcMessage &message)
QcTraffic traffic() const
QcTransport &transport() const
QcConnection &operator=(QcConnection &&)
QcConnection &operator=(const QcConnection &)

Signals

void closed()

Detailed Description

Sends nothing more once the other end said goodbye (a Disconnect): it is closing, and data arriving at a closed socket would reset the connection (decision E-904).

Member Type Documentation

[alias] QcConnection::Handler

Receives each decoded message.

Member Function Documentation

QcConnection::QcConnection(std::unique_ptr<QcTransport> transport, QcProtocol::Peer remote, QcConnection::Handler handler, QObject *parent = nullptr)

remote is the role of the other end; it decides which message types are accepted.

[delete] QcConnection::QcConnection(const QcConnection &)

Copy-constructs an instance of QcConnection. This function is deleted.

[delete] QcConnection::QcConnection(QcConnection &&)

Move-constructs an instance of QcConnection. This function is deleted.

void QcConnection::close()

Closes the transport.

[signal] void QcConnection::closed()

The transport closed.

bool QcConnection::isOpen() const

Returns whether the transport is open.

QString QcConnection::lastError() const

Returns the protocol error that closed the connection, else the transport's reason.

qint64 QcConnection::pendingBytes() const

Returns the bytes the transport has not yet handed to the network (QcTransport::pendingBytes).

void QcConnection::send(const QcMessage &message)

Encodes message and sends it as one frame; does nothing when the transport is closed or the other end said goodbye.

QcTraffic QcConnection::traffic() const

Returns the frame bytes so far; safe to read from any thread.

QcTransport &QcConnection::transport() const

Returns the link underneath (to move it to another thread together with the connection).

[delete] QcConnection &QcConnection::operator=(QcConnection &&)

Move-assigns other to this QcConnection instance. This function is deleted.

[delete] QcConnection &QcConnection::operator=(const QcConnection &)

Copy-assigns other to this QcConnection instance. This function is deleted.