libktorrent  2.2.0
socketmonitor.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 NETSOCKETMONITOR_H
21 #define NETSOCKETMONITOR_H
22 
23 
24 #include <list>
25 #include <qmutex.h>
26 #include <util/constants.h>
27 #include <ktorrent_export.h>
28 
29 
30 namespace net
31 {
32  using bt::Uint32;
33 
34  class TrafficShapedSocket;
35 
36 
37 
44  class KTORRENT_EXPORT SocketMonitor
45  {
46  SocketMonitor();
47  public:
48  virtual ~SocketMonitor();
49 
51  void add(TrafficShapedSocket* sock);
52 
54  void remove(TrafficShapedSocket* sock);
55 
56  typedef std::list<TrafficShapedSocket*>::iterator Itr;
57 
59  Itr begin() {return sockets.begin();}
60 
62  Itr end() {return sockets.end();}
63 
65  void lock();
66 
68  void unlock();
69 
71  void signalPacketReady();
72 
73  enum GroupType
74  {
75  UPLOAD_GROUP,
76  DOWNLOAD_GROUP
77  };
78 
82  void shutdown();
83 
84 
92  Uint32 newGroup(GroupType type,Uint32 limit,Uint32 assured_rate);
93 
100  void setGroupLimit(GroupType type,Uint32 gid,Uint32 limit);
101 
108  void setGroupAssuredRate(GroupType type,Uint32 gid,Uint32 as);
109 
115  void removeGroup(GroupType type,Uint32 gid);
116 
117  static void setDownloadCap(Uint32 bytes_per_sec);
118  static Uint32 getDownloadCap();
119  static void setUploadCap(Uint32 bytes_per_sec);
120  static Uint32 getUploadCap();
121  static void setSleepTime(Uint32 sleep_time);
122  static SocketMonitor & instance() {return self;}
123 
124  private:
125  class Private;
126  Private* d;
127  std::list<TrafficShapedSocket*> sockets;
128  static SocketMonitor self;
129  };
130 
131 }
132 
133 #endif
net::SocketMonitor
Definition: socketmonitor.h:63