libktorrent  2.2.0
networkthread.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 NETNETWORKTHREAD_H
21 #define NETNETWORKTHREAD_H
22 
23 #include <qthread.h>
24 #include <util/constants.h>
25 #include <util/ptrmap.h>
26 #include <net/socketgroup.h>
27 #include <net/poll.h>
28 
29 using bt::Uint32;
30 
31 namespace net
32 {
33  class SocketMonitor;
34 
40  class NetworkThread : public QThread, public Poll
41  {
42  protected:
43  SocketMonitor* sm;
44  bool running;
46  bt::TimeStamp prev_run_time;
47 
48  public:
50  ~NetworkThread() override;
51 
52 
59  void addGroup(Uint32 gid,Uint32 limit,Uint32 assured_rate);
60 
65  void removeGroup(Uint32 gid);
66 
72  void setGroupLimit(Uint32 gid,Uint32 limit);
73 
79  void setGroupAssuredRate(Uint32 gid,Uint32 as);
80 
84  void run() override;
85 
89  virtual void update() = 0;
90 
98  virtual bool doGroup(SocketGroup* g,Uint32 & allowance,bt::TimeStamp now) = 0;
99 
101  void stop() {running = false;}
102 
104  bool isRunning() const {return running;}
105 
106  protected:
113  void doGroups(Uint32 num_ready,bt::TimeStamp now,bt::Uint32 limit);
114 
115  private:
116  Uint32 doGroupsLimited(Uint32 num_ready,bt::TimeStamp now,Uint32 & allowance);
117  };
118 
119 }
120 
121 #endif
net::NetworkThread::removeGroup
void removeGroup(Uint32 gid)
net::NetworkThread::addGroup
void addGroup(Uint32 gid, Uint32 limit, Uint32 assured_rate)
net::NetworkThread
Definition: networkthread.h:41
bt::PtrMap
Map of pointers.
Definition: ptrmap.h:56
net::NetworkThread::run
void run() override
net::NetworkThread::stop
void stop()
Stop before the next update.
Definition: networkthread.h:101
net::NetworkThread::doGroup
virtual bool doGroup(SocketGroup *g, Uint32 &allowance, bt::TimeStamp now)=0
net::SocketMonitor
Definition: socketmonitor.h:63
net::NetworkThread::setGroupAssuredRate
void setGroupAssuredRate(Uint32 gid, Uint32 as)
net::NetworkThread::update
virtual void update()=0
net::NetworkThread::setGroupLimit
void setGroupLimit(Uint32 gid, Uint32 limit)
net::NetworkThread::isRunning
bool isRunning() const
Is the thread running.
Definition: networkthread.h:104
net::SocketGroup
Definition: socketgroup.h:54
net::Poll
Definition: poll.h:64
net::NetworkThread::doGroups
void doGroups(Uint32 num_ready, bt::TimeStamp now, bt::Uint32 limit)