45 const std::string ApiServer::TAG =
"ApiServer";
48 :
_shutdown(false), _garbage_collector(*this)
54 :
_shutdown(false), _garbage_collector(*this)
65 else if (net.
isAny()) {
71 std::list<ibrcommon::vaddress> addrs = net.
getAddresses();
74 std::stringstream ss; ss << port;
76 for (std::list<ibrcommon::vaddress>::iterator iter = addrs.begin(); iter != addrs.end(); ++iter) {
100 _garbage_collector.
stop();
101 _garbage_collector.
join();
124 startGarbageCollector();
136 _sockets.
select(&fds, NULL, NULL, NULL);
139 for (ibrcommon::socketset::iterator iter = fds.begin(); iter != fds.end(); ++iter)
155 if ( dynamic_cast<ibrcommon::tcpsocket*>(peersock) != NULL )
192 _registrations.push_back(reg);
196 obj =
new ClientHandler(*
this, *_registrations.back(), conn);
202 _connections.push_back(obj);
212 }
catch (
const std::exception&) {
229 _garbage_collector.
pause();
236 for (client_list::iterator iter = _connections.begin(); iter != _connections.end(); ++iter)
249 for (registration_list::iterator iter = _registrations.begin(); iter != _registrations.end(); ++iter)
272 for (registration_list::iterator iter = _registrations.begin(); iter != _registrations.end();)
281 _registrations.erase(iter++);
297 return nextRegistrationExpiry();
319 for (client_list::iterator iter = _connections.begin(); iter != _connections.end(); ++iter)
323 _connections.erase(iter);
334 startGarbageCollector();
340 for (registration_list::iterator iter = _registrations.begin(); iter != _registrations.end(); ++iter)
347 _registrations.erase(iter);
364 for (client_list::iterator iter = _connections.begin(); iter != _connections.end(); ++iter)
372 }
catch (
const std::bad_cast&) { };
375 void ApiServer::startGarbageCollector()
380 size_t timeout = nextRegistrationExpiry();
381 _garbage_collector.
set(timeout);
385 _garbage_collector.
start();
392 size_t ApiServer::nextRegistrationExpiry()
395 bool persistentFound =
false;
396 size_t new_timeout = 0;
400 for (registration_list::iterator iter = _registrations.begin(); iter != _registrations.end(); ++iter)
404 Registration ® = (**iter);
407 if(!reg.isPersistent()){
411 persistentFound =
true;
416 size_t expire_time = reg.getExpireTime();
419 size_t expire_timeout = expire_time - current_time;
425 persistentFound =
true;
426 new_timeout = expire_timeout;
428 else if(expire_timeout < new_timeout)
430 new_timeout = expire_timeout;
434 catch(
const Registration::AlreadyAttachedException &ex)