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);
202 _connections.push_back(obj);
212 }
catch (
const std::exception&) {
229 _garbage_collector.
pause();
236 for (std::list<ClientHandler*>::iterator iter = _connections.begin(); iter != _connections.end(); ++iter)
243 while (_connections.size() > 0) ::
sleep(1);
249 for (std::list<dtn::api::Registration>::iterator iter = _registrations.begin(); iter != _registrations.end(); ++iter)
253 if (iter->isPersistent()){
270 for (std::list<dtn::api::Registration>::iterator iter = _registrations.begin(); iter != _registrations.end();)
275 if(!iter->isPersistent()){
277 iter = _registrations.erase(iter);
292 return nextRegistrationExpiry();
314 for (std::list<ClientHandler*>::iterator iter = _connections.begin(); iter != _connections.end(); ++iter)
318 _connections.erase(iter);
329 startGarbageCollector();
335 for (std::list<dtn::api::Registration>::iterator iter = _registrations.begin(); iter != _registrations.end(); ++iter)
340 _registrations.erase(iter);
356 for (std::list<ClientHandler*>::iterator iter = _connections.begin(); iter != _connections.end(); ++iter)
364 }
catch (
const std::bad_cast&) { };
367 void ApiServer::startGarbageCollector()
372 size_t timeout = nextRegistrationExpiry();
373 _garbage_collector.
set(timeout);
377 _garbage_collector.
start();
384 size_t ApiServer::nextRegistrationExpiry()
387 bool persistentFound =
false;
388 size_t new_timeout = 0;
392 for (std::list<dtn::api::Registration>::iterator iter = _registrations.begin(); iter != _registrations.end(); ++iter)
397 if(!iter->isPersistent()){
401 persistentFound =
true;
406 size_t expire_time = iter->getExpireTime();
409 size_t expire_timeout = expire_time - current_time;
415 persistentFound =
true;
416 new_timeout = expire_timeout;
418 else if(expire_timeout < new_timeout)
420 new_timeout = expire_timeout;
424 catch(
const Registration::AlreadyAttachedException &ex)