libktorrent  2.2.0
socketgroup.h
1 /***************************************************************************
2  * Copyright (C) 2005 by Joris Guisson *
3  * joris.guisson@gmail.com *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program 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 *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19  ***************************************************************************/
20 #ifndef NETSOCKETGROUP_H
21 #define NETSOCKETGROUP_H
22 
23 #include <list>
24 #include <util/constants.h>
25 
26 namespace net
27 {
28  using bt::Uint32;
29 
30  class TrafficShapedSocket;
31 
36  {
37  Uint32 limit;
38  Uint32 assured_rate;
39  std::list<TrafficShapedSocket*> sockets;
40  bt::TimeStamp prev_run_time;
41  Uint32 group_allowance;
42  Uint32 group_assured;
43  public:
44  SocketGroup(Uint32 limit,Uint32 assured_rate);
45  virtual ~SocketGroup();
46 
48  void clear() {sockets.clear();}
49 
51  void add(TrafficShapedSocket* s) {sockets.push_back(s);}
52 
59  bool download(Uint32 & global_allowance,bt::TimeStamp now);
60 
67  bool upload(Uint32 & global_allowance,bt::TimeStamp now);
68 
73  void setLimit(Uint32 lim) {limit = lim;}
74 
79  void setAssuredRate(Uint32 as) {assured_rate = as;}
80 
82  Uint32 numSockets() const {return sockets.size();}
83 
88  void calcAllowance(bt::TimeStamp now);
89 
93  Uint32 getAssuredAllowance() const {return group_assured;}
94  private:
95  void processUnlimited(bool up,bt::TimeStamp now);
96  bool processLimited(bool up,bt::TimeStamp now,Uint32 & allowance);
97  bool process(bool up,bt::TimeStamp now,Uint32 & global_allowance);
98  };
99 
100 
101 }
102 
103 #endif
net::SocketGroup::add
void add(TrafficShapedSocket *s)
Add a socket for processing.
Definition: socketgroup.h:51
net::SocketGroup::download
bool download(Uint32 &global_allowance, bt::TimeStamp now)
net::SocketGroup::clear
void clear()
Clear the lists of sockets.
Definition: socketgroup.h:48
net::SocketGroup::numSockets
Uint32 numSockets() const
Get the number of sockets.
Definition: socketgroup.h:82
net::SocketGroup::calcAllowance
void calcAllowance(bt::TimeStamp now)
net::SocketGroup::setLimit
void setLimit(Uint32 lim)
Definition: socketgroup.h:73
net::SocketGroup::upload
bool upload(Uint32 &global_allowance, bt::TimeStamp now)
net::SocketGroup::getAssuredAllowance
Uint32 getAssuredAllowance() const
Definition: socketgroup.h:93
net::SocketGroup
Definition: socketgroup.h:36
net::SocketGroup::setAssuredRate
void setAssuredRate(Uint32 as)
Definition: socketgroup.h:79
net::TrafficShapedSocket
Definition: trafficshapedsocket.h:52