Index: lib/Comms/src/CloudConnectServer.cpp =================================================================== diff -u -rc6a4b63a37f3beb1e8a51702ec3a56a1c32cfe8f -r59b4c22f45a1d098064a886452769204e90cfb4b --- lib/Comms/src/CloudConnectServer.cpp (.../CloudConnectServer.cpp) (revision c6a4b63a37f3beb1e8a51702ec3a56a1c32cfe8f) +++ lib/Comms/src/CloudConnectServer.cpp (.../CloudConnectServer.cpp) (revision 59b4c22f45a1d098064a886452769204e90cfb4b) @@ -16,7 +16,7 @@ /*! * \brief CloudConnectServer::CloudConnectServer - * \details Constructor. Wires the server newConnection signal. + * \details Constructor * \param parent Optional QObject parent. */ CloudConnectServer::CloudConnectServer(QObject *parent) : QObject(parent) @@ -27,7 +27,7 @@ /*! * \brief CloudConnectServer::listen * \details Removes any stale socket file, then starts the server. - * \param socketPath Path to the Unix domain socket. + * \param socketPath Path to the Unix domain socket (UDS). * \return true on success, false if the server could not bind. */ bool CloudConnectServer::listen(const QString &socketPath) @@ -45,25 +45,25 @@ /*! * \brief CloudConnectServer::send * \details Builds a CloudConnectFrame and writes it to the connected client. - * \param type Message identifier for the frame header. + * \param topic MQTT topic for the frame header. * \param sequence Caller-managed sequence number. * \param payload Message payload; pass empty for zero-length frames. * \return true if written to the socket, false if no client is connected. */ -bool CloudConnectServer::send(CloudConnectFrame::Type type, quint16 sequence, const QByteArray &payload) +bool CloudConnectServer::send(CloudConnectFrame::Topic topic, quint16 sequence, const QByteArray &payload) { if (_client == nullptr || _client->state() != QLocalSocket::ConnectedState) { return false; } - const QByteArray frame = CloudConnectFrame::build(type, sequence, payload); + const QByteArray frame = CloudConnectFrame::build(topic, sequence, payload); _client->write(frame); _client->flush(); return true; } /*! * \brief CloudConnectServer::isConnected - * \details Reports whether a client is currently attached to the server. + * \details Reports whether a client is currently connected to the server. * \return true if a client is currently connected. */ bool CloudConnectServer::isConnected() const @@ -80,7 +80,7 @@ { if (_client) { qWarning().noquote() << metaObject()->className() - << ": second connection attempt rejected — already connected"; + << ": previous client connected, new client connection refused"; _server.nextPendingConnection()->deleteLater(); return; } @@ -96,36 +96,34 @@ /*! * \brief CloudConnectServer::onDisconnected - * \details Releases the client socket and resets inbound parser state. + * \details Releases the client socket and resets incoming frame state. */ void CloudConnectServer::onDisconnected() { qInfo().noquote() << metaObject()->className() << ": client disconnected"; _client->deleteLater(); _client = nullptr; _rxBuf.clear(); - _rxMsg.reset(); + _rxFrame.reset(); emit didDisconnect(); } /*! * \brief CloudConnectServer::onReadyRead - * \details Appends incoming bytes to the receive buffer and drains it through - * the CloudConnectFrame parser, emitting didMessageReceive() for each - * complete frame. + * \details Handler for incoming data from the client. */ void CloudConnectServer::onReadyRead() { _rxBuf.append(_client->readAll()); CloudConnectFrame::ReadState state; do { - state = _rxMsg.read(_rxBuf); + state = _rxFrame.read(_rxBuf); switch (state) { case CloudConnectFrame::ReadState::Complete: - emit didMessageReceive(_rxMsg.type(), _rxMsg.sequence(), _rxMsg.payload()); - _rxMsg.reset(); + emit didMessageReceive(_rxFrame.topic(), _rxFrame.sequence(), _rxFrame.payload()); + _rxFrame.reset(); break; case CloudConnectFrame::ReadState::HeaderError: qWarning().noquote() << metaObject()->className() << ": header CRC error — frame dropped";