mirror of
https://github.com/daveallie/crosspoint-reader.git
synced 2026-02-05 23:27:38 +03:00
fixed files stalling at 90%
This commit is contained in:
parent
53592e58b2
commit
023cca1118
@ -235,17 +235,29 @@ void CalibreWirelessActivity::listenForDiscovery() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CalibreWirelessActivity::handleTcpClient() {
|
void CalibreWirelessActivity::handleTcpClient() {
|
||||||
|
// In binary mode, keep reading even if connection closed - data may still be buffered
|
||||||
|
if (inBinaryMode) {
|
||||||
|
// Check if there's still data to read, even if connection is closing
|
||||||
|
if (tcpClient.available() > 0 || tcpClient.connected()) {
|
||||||
|
receiveBinaryData();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Connection closed and no more data - check if transfer was complete
|
||||||
|
if (binaryBytesRemaining > 0) {
|
||||||
|
Serial.printf("[%lu] [CAL] Connection lost with %zu bytes remaining\n", millis(), binaryBytesRemaining);
|
||||||
|
currentFile.close();
|
||||||
|
inBinaryMode = false;
|
||||||
|
setError("Transfer incomplete - connection lost");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!tcpClient.connected()) {
|
if (!tcpClient.connected()) {
|
||||||
setState(WirelessState::DISCONNECTED);
|
setState(WirelessState::DISCONNECTED);
|
||||||
setStatus("Calibre disconnected");
|
setStatus("Calibre disconnected");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inBinaryMode) {
|
|
||||||
receiveBinaryData();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string message;
|
std::string message;
|
||||||
if (readJsonMessage(message)) {
|
if (readJsonMessage(message)) {
|
||||||
size_t start = message.find('[');
|
size_t start = message.find('[');
|
||||||
@ -532,8 +544,9 @@ void CalibreWirelessActivity::receiveBinaryData() {
|
|||||||
|
|
||||||
int available = tcpClient.available();
|
int available = tcpClient.available();
|
||||||
if (available <= 0) {
|
if (available <= 0) {
|
||||||
// Brief wait for more data
|
// Wait longer for data - TCP buffers may not be immediately available
|
||||||
vTaskDelay(1);
|
// especially near end of transfer when connection is closing
|
||||||
|
vTaskDelay(10 / portTICK_PERIOD_MS);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user