* @brief Reacts to a byte received while waiting for ACK/NAK after a data block. * Returns false when processing must stop because the transfer ended. */
| 118 | * Returns false when processing must stop because the transfer ended. |
| 119 | */ |
| 120 | bool IO::Protocols::XMODEM::handleAckByte(quint8 ch) |
| 121 | { |
| 122 | if (ch == kACK) { |
| 123 | m_timeoutTimer.stop(); |
| 124 | m_retryCount = 0; |
| 125 | m_blockNumber = static_cast<quint8>((m_blockNumber + 1) & 0xFF); |
| 126 | m_state = State::SendingBlocks; |
| 127 | |
| 128 | if (m_file.atEnd()) |
| 129 | sendEOT(); |
| 130 | else |
| 131 | sendBlock(); |
| 132 | |
| 133 | return true; |
| 134 | } |
| 135 | |
| 136 | if (ch == kNAK) { |
| 137 | m_timeoutTimer.stop(); |
| 138 | ++m_retryCount; |
| 139 | if (m_retryCount >= m_maxRetries) { |
| 140 | sendCancel(); |
| 141 | resetState(); |
| 142 | Q_EMIT statusMessage(tr("Too many retries, transfer aborted")); |
| 143 | Q_EMIT finished(false, tr("Maximum retries exceeded")); |
| 144 | return false; |
| 145 | } |
| 146 | |
| 147 | Q_EMIT statusMessage(tr("NAK received, retrying block %1 (%2/%3)") |
| 148 | .arg(m_blockNumber) |
| 149 | .arg(m_retryCount) |
| 150 | .arg(m_maxRetries)); |
| 151 | |
| 152 | m_bytesSent = qMax<qint64>(0, m_bytesSent - m_lastBlockBytes); |
| 153 | if (!m_file.seek(m_lastBlockStart)) [[unlikely]] { |
| 154 | m_file.close(); |
| 155 | Q_EMIT finished(false, tr("Failed to seek in file")); |
| 156 | return false; |
| 157 | } |
| 158 | sendBlock(); |
| 159 | return true; |
| 160 | } |
| 161 | |
| 162 | if (ch == kCAN) { |
| 163 | m_timeoutTimer.stop(); |
| 164 | resetState(); |
| 165 | Q_EMIT statusMessage(tr("Transfer cancelled by receiver")); |
| 166 | Q_EMIT finished(false, tr("Receiver cancelled the transfer")); |
| 167 | } |
| 168 | |
| 169 | return true; |
| 170 | } |
| 171 | |
| 172 | /** |
| 173 | * @brief Reacts to a byte received while waiting for ACK after EOT. |
nothing calls this directly
no test coverage detected