1
/***************************************************************************
2
* Copyright (C) 2005 by Joris Guisson *
3
* joris.guisson@gmail.com *
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. *
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. *
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
24
#include <util/constants.h>
25
#include <util/ptrmap.h>
26
#include <net/socketgroup.h>
35
@author Joris Guisson <joris.guisson@gmail.com>
37
Base class for the 2 networking threads. Handles the socket groups.
39
class NetworkThread : public QThread
44
bt::PtrMap<Uint32,SocketGroup> groups;
45
bt::TimeStamp prev_run_time;
48
NetworkThread(SocketMonitor* sm);
49
virtual ~NetworkThread();
53
* Add a new group with a given limit
54
* @param gid The group ID (cannot be 0, 0 is the default group)
55
* @param limit The limit in bytes per sec
56
* @param assured_rate The assured rate for this group in bytes per second
58
void addGroup(Uint32 gid,Uint32 limit,Uint32 assured_rate);
62
* @param gid The group ID
64
void removeGroup(Uint32 gid);
67
* Set the limit for a group
68
* @param gid The group ID
69
* @param limit The limit
71
void setGroupLimit(Uint32 gid,Uint32 limit);
74
* Set the assured rate for a group
75
* @param gid The group ID
76
* @param as The assured rate
78
void setGroupAssuredRate(Uint32 gid,Uint32 as);
81
* The main function of the thread
86
* Subclasses must implement this function
88
virtual void update() = 0;
93
* @param allowance The groups allowance
94
* @param now The current time
95
* @return true if the group can go again
97
virtual bool doGroup(SocketGroup* g,Uint32 & allowance,bt::TimeStamp now) = 0;
99
/// Stop before the next update
100
void stop() {running = false;}
102
/// Is the thread running
103
bool isRunning() const {return running;}
107
* Go over all groups and do them
108
* @param num_ready The number of ready sockets
109
* @param now The current time
110
* @param limit The global limit in bytes per sec
112
void doGroups(Uint32 num_ready,bt::TimeStamp now,bt::Uint32 limit);
115
Uint32 doGroupsLimited(Uint32 num_ready,bt::TimeStamp now,Uint32 & allowance);