summaryrefslogtreecommitdiffstats
path: root/libktorrent/net/socketgroup.h
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-01-20 02:37:40 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-01-20 02:37:40 +0000
commit9ad5c7b5e23b4940e7a3ea3ca3a6fb77e6a8fab0 (patch)
treed088b5210e77d9fa91d954d8550e00e372b47378 /libktorrent/net/socketgroup.h
downloadktorrent-9ad5c7b5e23b4940e7a3ea3ca3a6fb77e6a8fab0.tar.gz
ktorrent-9ad5c7b5e23b4940e7a3ea3ca3a6fb77e6a8fab0.zip
Updated to final KDE3 ktorrent release (2.2.6)
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/ktorrent@1077377 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'libktorrent/net/socketgroup.h')
-rw-r--r--libktorrent/net/socketgroup.h90
1 files changed, 90 insertions, 0 deletions
diff --git a/libktorrent/net/socketgroup.h b/libktorrent/net/socketgroup.h
new file mode 100644
index 0000000..ba08029
--- /dev/null
+++ b/libktorrent/net/socketgroup.h
@@ -0,0 +1,90 @@
+/***************************************************************************
+ * 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 BufferedSocket;
+
+ /**
+ @author Joris Guisson <joris.guisson@gmail.com>
+ */
+ class SocketGroup
+ {
+ Uint32 limit;
+ std::list<BufferedSocket*> sockets;
+ bt::TimeStamp prev_run_time;
+ Uint32 group_allowance;
+ public:
+ SocketGroup(Uint32 limit);
+ virtual ~SocketGroup();
+
+ /// Clear the lists of sockets
+ void clear() {sockets.clear();}
+
+ /// Add a socket for processing
+ void add(BufferedSocket* 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;}
+
+ /// 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);
+ 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