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:
parent
747b8c3244
commit
e0ec162938
|
|
@ -1217,6 +1217,7 @@ void HAPClient::getStatusURL(HAPClient *hapClient, void (*callBack)(const char *
|
||||||
|
|
||||||
if(hapClient){
|
if(hapClient){
|
||||||
hapClient->client.stop();
|
hapClient->client.stop();
|
||||||
|
delay(1);
|
||||||
LOG2("------------ SENT! --------------\n");
|
LOG2("------------ SENT! --------------\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -229,9 +229,9 @@ void Span::pollTask() {
|
||||||
processSerialCommand(cBuf);
|
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)
|
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
|
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);
|
LOG1("** Client #%d DISCONNECTED (%lu sec)\n",i,millis()/1000);
|
||||||
hap[i]->isConnected=false;
|
hap[i]->isConnected=false;
|
||||||
|
hap[i]->client.stop();
|
||||||
|
delay(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue