proper disconnect

This commit is contained in:
badaix 2015-09-30 13:57:23 +02:00
parent 02ec52e765
commit cdf0ac11c9
2 changed files with 49 additions and 16 deletions

26
notes.txt Normal file
View file

@ -0,0 +1,26 @@
*Todo:
-Server ping client
-Server: OnResync while terminating?!?
*g++ 4.8 installation:
sudo apt-get install g++-4.8
cd /usr/bin
sudo ln -sf gcc-4.8 gcc
sudo ln -sf g++-4.8 g++
*Links:
curl -X POST -H "Content-Type: application/json" -d '{"jsonrpc": "2.0", "method": "Application.SetVolume", "params": {"volume":100}, "id": 1}' http://i3c.pla.lcl:8080/jsonrpc
https://en.wikipedia.org/wiki/JSON-RPC
https://github.com/pla1/utils/blob/master/kodi_remote.desktop
http://forum.fhem.de/index.php?topic=10075.130;wap2
http://kodi.wiki/view/JSON-RPC_API/v6#Application.SetVolume
*Logging:
-Too many of these:
Sep 20 06:50:58 wohnzimmer snapclient[2358]: Exception in Controller::worker(): connect: Network is unreachable
Sep 20 06:50:59 wohnzimmer snapclient[2358]: Exception in Controller::worker(): connect: Network is unreachable
Sep 20 06:51:00 wohnzimmer snapclient[2358]: Exception in Controller::worker(): connect: Network is unreachable
-Limit repeaded syslog logging

View file

@ -48,17 +48,7 @@ void StreamServer::send(const msg::BaseMessage* message)
for (auto it = sessions_.begin(); it != sessions_.end(); ) for (auto it = sessions_.begin(); it != sessions_.end(); )
{ {
if (!(*it)->active()) if (!(*it)->active())
{
logS(kLogErr) << "Session inactive. Removing\n";
// don't block: remove ClientSession in a thread
auto func = [](shared_ptr<ClientSession> s)->void{s->stop();};
std::thread t(func, *it);
t.detach();
onDisconnect(it->get()); onDisconnect(it->get());
sessions_.erase(it++);
}
else
++it;
} }
std::shared_ptr<const msg::BaseMessage> shared_message(message); std::shared_ptr<const msg::BaseMessage> shared_message(message);
@ -80,15 +70,32 @@ void StreamServer::onResync(const PipeReader* pipeReader, double ms)
} }
void StreamServer::onDisconnect(ClientSession* connection) void StreamServer::onDisconnect(ClientSession* clientSession)
{ {
ClientInfoPtr client = Config::instance().getClientInfo(connection->macAddress); logO << "onDisconnect: " << clientSession->macAddress << "\n";
if (!client->connected) auto func = [](ClientSession* s)->void{s->stop();};
std::thread t(func, clientSession);
t.detach();
ClientInfoPtr clientInfo = Config::instance().getClientInfo(clientSession->macAddress);
// don't block: remove ClientSession in a thread
for (auto it = sessions_.begin(); it != sessions_.end(); )
{
if (it->get() == clientSession)
{
logO << "erase: " << (*it)->macAddress << "\n";
sessions_.erase(it);
break;
}
}
// notify controllers if not yet done
if (!clientInfo->connected)
return; return;
client->connected = false; clientInfo->connected = false;
gettimeofday(&client->lastSeen, NULL); gettimeofday(&clientInfo->lastSeen, NULL);
Config::instance().save(); Config::instance().save();
json notification = JsonNotification::getJson("Client.OnDisconnect", client->toJson()); json notification = JsonNotification::getJson("Client.OnDisconnect", clientInfo->toJson());
controlServer_->send(notification.dump()); controlServer_->send(notification.dump());
} }