Address review: rename close_socket_ to destroy_socket_, use log helper for reuseaddr, clarify destructor behavior

This commit is contained in:
J. Nick Koston
2026-02-20 18:10:52 -06:00
parent f389314945
commit 9fc291e98f
5 changed files with 9 additions and 9 deletions
+2 -2
View File
@@ -32,7 +32,7 @@ APIServer::APIServer() { global_api_server = this; }
void APIServer::socket_failed_(const LogString *msg) {
ESP_LOGW(TAG, "Socket %s: errno %d", LOG_STR_ARG(msg), errno);
this->close_socket_();
this->destroy_socket_();
this->mark_failed();
}
@@ -623,7 +623,7 @@ void APIServer::on_shutdown() {
this->shutting_down_ = true;
// Close the listening socket to prevent new connections
this->close_socket_();
this->destroy_socket_();
// Change batch delay to 5ms for quick flushing during shutdown
this->batch_delay_ = 5;
+2 -2
View File
@@ -249,8 +249,8 @@ class APIServer : public Component,
void add_state_subscription_(std::string entity_id, optional<std::string> attribute,
std::function<void(const std::string &)> f, bool once);
#endif // USE_API_HOMEASSISTANT_STATES
// Listen sockets use LwIPSocketImpl/BSDSocketImpl whose destructors call close()
inline void close_socket_() {
// Socket destructor will close or abort depending on platform
inline void destroy_socket_() {
delete this->socket_;
this->socket_ = nullptr;
}
@@ -70,14 +70,14 @@ void DNSServer::start(const network::IPAddress &ip) {
int err = this->socket_->bind((struct sockaddr *) &server_addr, addr_len);
if (err != 0) {
ESP_LOGE(TAG, "Bind failed: %d", errno);
this->close_socket_();
this->destroy_socket_();
return;
}
ESP_LOGV(TAG, "Bound to port %d", DNS_PORT);
}
void DNSServer::stop() {
this->close_socket_();
this->destroy_socket_();
ESP_LOGV(TAG, "Stopped");
}
@@ -14,8 +14,8 @@ class DNSServer {
void process_next_request();
protected:
// Listen sockets use LwIPSocketImpl/BSDSocketImpl whose destructors call close()
inline void close_socket_() {
// Socket destructor will close or abort depending on platform
inline void destroy_socket_() {
delete this->socket_;
this->socket_ = nullptr;
}
@@ -452,7 +452,7 @@ void ESPHomeOTAComponent::log_remote_closed_(const LogString *during) {
void ESPHomeOTAComponent::server_failed_(const LogString *msg) {
this->log_socket_error_(msg);
// Listen sockets use LwIPSocketImpl/BSDSocketImpl whose destructors call close()
// Socket destructor will close or abort depending on platform
delete this->server_;
this->server_ = nullptr;
this->mark_failed();