/usr/include/libktorrent/net/socketgroup.h is in libktorrent-dev 1.3.1-5.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 | /***************************************************************************
* Copyright (C) 2005 by Joris Guisson *
* joris.guisson@gmail.com *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
#ifndef NETSOCKETGROUP_H
#define NETSOCKETGROUP_H
#include <list>
#include <util/constants.h>
namespace net
{
using bt::Uint32;
class TrafficShapedSocket;
/**
@author Joris Guisson <joris.guisson@gmail.com>
*/
class SocketGroup
{
Uint32 limit;
Uint32 assured_rate;
std::list<TrafficShapedSocket*> sockets;
bt::TimeStamp prev_run_time;
Uint32 group_allowance;
Uint32 group_assured;
public:
SocketGroup(Uint32 limit,Uint32 assured_rate);
virtual ~SocketGroup();
/// Clear the lists of sockets
void clear() {sockets.clear();}
/// Add a socket for processing
void add(TrafficShapedSocket* s) {sockets.push_back(s);}
/**
Process all the sockets in the vector for download.
@param global_allowance How much the group can do, this will be updated, 0 means no limit
@param now Current time
@return true if we can download more data, false otherwise
*/
bool download(Uint32 & global_allowance,bt::TimeStamp now);
/**
Process all the sockets in the vector for upload
@param global_allowance How much the group can do, this will be updated, 0 means no limit
@param now Current time
@return true if we can upload more data, false otherwise
*/
bool upload(Uint32 & global_allowance,bt::TimeStamp now);
/**
* Set the group limit in bytes per sec
* @param lim The limit
*/
void setLimit(Uint32 lim) {limit = lim;}
/**
* Set the assured rate for the gorup in bytes per sec
* @param as The assured rate
*/
void setAssuredRate(Uint32 as) {assured_rate = as;}
/// Get the number of sockets
Uint32 numSockets() const {return sockets.size();}
/**
* Calculate the allowance for this group
* @param now Current timestamp
*/
void calcAllowance(bt::TimeStamp now);
/**
* Get the assured allowance .
*/
Uint32 getAssuredAllowance() const {return group_assured;}
private:
void processUnlimited(bool up,bt::TimeStamp now);
bool processLimited(bool up,bt::TimeStamp now,Uint32 & allowance);
bool process(bool up,bt::TimeStamp now,Uint32 & global_allowance);
};
}
#endif
|