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 
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 
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::unlock
void unlock()
unlock the monitor
net::SocketMonitor::newGroup
Uint32 newGroup(GroupType type, Uint32 limit, Uint32 assured_rate)
net::SocketMonitor::add
void add(TrafficShapedSocket *sock)
Add a new socket, will start the threads if necessary.
net::SocketMonitor
Definition: socketmonitor.h:45
net::SocketMonitor::signalPacketReady
void signalPacketReady()
Tell upload thread a packet is ready.
net::SocketMonitor::setGroupAssuredRate
void setGroupAssuredRate(GroupType type, Uint32 gid, Uint32 as)
net::SocketMonitor::remove
void remove(TrafficShapedSocket *sock)
Remove a socket, will stop threads if no more sockets are left.
net::SocketMonitor::setGroupLimit
void setGroupLimit(GroupType type, Uint32 gid, Uint32 limit)
net::SocketMonitor::end
Itr end()
Get the end of the list of sockets.
Definition: socketmonitor.h:62
net::SocketMonitor::lock
void lock()
lock the monitor
net::SocketMonitor::removeGroup
void removeGroup(GroupType type, Uint32 gid)
net::TrafficShapedSocket
Definition: trafficshapedsocket.h:52
net::SocketMonitor::shutdown
void shutdown()
net::SocketMonitor::begin
Itr begin()
Get the begin of the list of sockets.
Definition: socketmonitor.h:59