Added logic to check for hap[i] disconnect and issue stop() when found

This cures memory leakage when using HomeSpan without a Home Hub.  Sockets are now properly closed when the Home App abruptly disconnects.
This commit is contained in:
Gregg 2024-05-11 07:43:11 -05:00
parent 747b8c3244
commit e0ec162938
3 changed files with 8 additions and 5 deletions

View File

@ -1217,6 +1217,7 @@ void HAPClient::getStatusURL(HAPClient *hapClient, void (*callBack)(const char *
if(hapClient){
hapClient->client.stop();
delay(1);
LOG2("------------ SENT! --------------\n");
}
}

View File

@ -229,9 +229,9 @@ void Span::pollTask() {
processSerialCommand(cBuf);
}
if(hapServer->hasClient()){ // found new client
WiFiClient newClient;
WiFiClient newClient=hapServer->available(); // get new client
if(newClient=hapServer->available()){ // found new client
int socket=newClient.fd()-LWIP_SOCKET_OFFSET; // get socket number (starting at zero)
@ -263,6 +263,8 @@ void Span::pollTask() {
else if(hap[i]->isConnected){ // if client is not connected, but HAPClient thinks it is
LOG1("** Client #%d DISCONNECTED (%lu sec)\n",i,millis()/1000);
hap[i]->isConnected=false;
hap[i]->client.stop();
delay(1);
}
}
}