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,10 +229,10 @@ void Span::pollTask() {
|
||||||
processSerialCommand(cBuf);
|
processSerialCommand(cBuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(hapServer->hasClient()){ // found new client
|
WiFiClient newClient;
|
||||||
|
|
||||||
|
if(newClient=hapServer->available()){ // found new client
|
||||||
|
|
||||||
WiFiClient newClient=hapServer->available(); // get 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)
|
||||||
|
|
||||||
if(hap[socket]==NULL) // create HAPClient at that socket if it does not alreay exist
|
if(hap[socket]==NULL) // create HAPClient at that socket if it does not alreay exist
|
||||||
|
|
@ -262,7 +262,9 @@ 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@
|
||||||
void setup() {
|
void setup() {
|
||||||
|
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
|
|
||||||
homeSpan.setLogLevel(2);
|
homeSpan.setLogLevel(2);
|
||||||
homeSpan.enableWebLog();
|
homeSpan.enableWebLog();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue