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 #ifndef _tairon_net_limit_limiter_h
18 #define _tairon_net_limit_limiter_h
22 #include <tairon/core/signals.h>
30 /** \brief Limiter is used for limiting network bandwidth.
35 /** Constructs a Limiter object.
37 * \param r Maximum number of bytes to by transferred per second.
38 * \param p Parent of this limiter. Transfer rate of this limiter won't
39 * exceed its parent's rate. If no parent is specified then this
40 * limiter notices its child about free bandwidth to use. An instance
41 * of Tairon::Net::LimitManager has to be created before Limiter can be
44 Limiter(size_t r
, Limiter
*p
= 0);
46 /** Destroys the object.
50 /** Returns maximum number of bytes that can be transferred.
52 size_t getAllowedSize(size_t max
);
54 /** Removes a functor from queue of functors waiting for free transfer.
56 void removeFromQueue(Tairon::Core::Functor0
<void> *f
);
58 /** Sets number of transferred bytes to zero and calls waiting functors.
62 /** Informs this Limiter about transferred data.
64 void transferred(size_t s
);
66 /** Someone wants to be notified when there is a possibility to transfer
69 * \param f Functor that will be called when there are data to read.
71 void wantMore(Tairon::Core::Functor0
<void> *f
);
74 /** Parent of this limiter.
78 /** Maximum number of bytes to be transferred per second.
82 /** Number of bytes that can be transferred.
86 /** List of functors that will be called when a transfer can be done.
88 std::list
<Tairon::Core::Functor0
<void> *> waiting
;
90 /** Functor for calling wantMore() method.
92 Tairon::Core::Functor0
<void> *wantMoreFunctor
;
97 }; // namespace Tairon
101 // vim: ai sw=4 ts=4 noet fdm=marker