1 /***************************************************************************
3 * Copyright (C) 2006 David Brodsky *
5 * This library is free software; you can redistribute it and/or *
6 * modify it under the terms of the GNU Library General Public *
7 * License as published by the Free Software Foundation and appearing *
8 * in the file LICENSE.LGPL included in the packaging of this file. *
10 * This library is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
13 * Library General Public License for more details. *
15 ***************************************************************************/
17 #include <tairon/net/timer.h>
19 #include "limitmanager.h"
29 LimitManager
*LimitManager::limitmanager
= 0;
31 /* {{{ LimitManager::LimitManager() */
32 LimitManager::LimitManager()
35 timer
->timeoutSignal
.connect(Tairon::Core::threadMethodDFunctor(Tairon::Core::Thread::current(), this, &LimitManager::timeout
));
36 timer
->start(1000); // every second
42 /* {{{ LimitManager::~LimitManager() */
43 LimitManager::~LimitManager()
49 /* {{{ LimitManager::removeFromQueue(Limiter *) */
50 void LimitManager::removeFromQueue(Limiter
*l
)
52 toDelete
.push_back(l
);
56 /* {{{ LimitManager::timeout() */
57 void LimitManager::timeout()
59 // A crash due to an invalid iterator may be caused if a limiter wants to
60 // be removed from the queue while the queue is traversed. This workaround
61 // should do the right thing.
62 for (std::list
<Limiter
*>::const_iterator it
= toDelete
.begin(); it
!= toDelete
.end(); ++it
)
66 for (std::set
<Limiter
*>::const_iterator it
= waiting
.begin(); it
!= waiting
.end(); ++it
)
71 /* {{{ LimitManager::wantMore(Limiter *) */
72 void LimitManager::wantMore(Limiter
*l
)
80 }; // namespace Tairon
82 // vim: ai sw=4 ts=4 noet fdm=marker