1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-04 20:32:21 +01:00
This commit is contained in:
J. Nick Koston
2025-08-10 18:28:27 -05:00
parent 856e13986a
commit 4bdf44bb78

View File

@@ -137,25 +137,31 @@ void ESPHomeOTAComponent::handle_handshake_() {
// Try to read first byte of magic bytes // Try to read first byte of magic bytes
uint8_t first_byte; uint8_t first_byte;
ssize_t read = this->client_->read(&first_byte, 1); ssize_t read = this->client_->read(&first_byte, 1);
if (read == 1) {
// Got the first byte, check if it's the magic byte if (read == -1 && (errno == EAGAIN || errno == EWOULDBLOCK)) {
if (first_byte != 0x6C) { return; // No data yet, try again next loop
ESP_LOGW(TAG, "Invalid initial byte: 0x%02X", first_byte);
this->cleanup_connection_();
return;
}
// First byte is valid, continue with data handling
this->handle_data_();
} else if (read == -1) {
if (errno != EAGAIN && errno != EWOULDBLOCK) {
this->log_socket_error_("reading first byte");
this->cleanup_connection_();
}
// For EAGAIN/EWOULDBLOCK, just return and try again next loop
} else if (read == 0) {
ESP_LOGW(TAG, "Remote closed during handshake");
this->cleanup_connection_();
} }
if (read <= 0) {
// Error or connection closed
if (read == -1) {
this->log_socket_error_("reading first byte");
} else {
ESP_LOGW(TAG, "Remote closed during handshake");
}
this->cleanup_connection_();
return;
}
// Got first byte, check if it's the magic byte
if (first_byte != 0x6C) {
ESP_LOGW(TAG, "Invalid initial byte: 0x%02X", first_byte);
this->cleanup_connection_();
return;
}
// First byte is valid, continue with data handling
this->handle_data_();
} }
void ESPHomeOTAComponent::handle_data_() { void ESPHomeOTAComponent::handle_data_() {