1// 2// This file is part of the aMule Project. 3// 4// Copyright (c) 2005-2011 aMule Team ( admin@amule.org / http://www.amule.org ) 5// Copyright (c) 2002-2011 Merkur ( devs@emule-project.net / http://www.emule-project.net ) 6// 7// Any parts of this program derived from the xMule, lMule or eMule project, 8// or contributed by third-party developers are copyrighted by their 9// respective authors. 10// 11// This program is free software; you can redistribute it and/or modify 12// it under the terms of the GNU General Public License as published by 13// the Free Software Foundation; either version 2 of the License, or 14// (at your option) any later version. 15// 16// This program is distributed in the hope that it will be useful, 17// but WITHOUT ANY WARRANTY; without even the implied warranty of 18// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19// GNU General Public License for more details. 20// 21// You should have received a copy of the GNU General Public License 22// along with this program; if not, write to the Free Software 23// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 24// 25 26#ifndef UPLOADBANDWIDTHTHROTTLER_H 27#define UPLOADBANDWIDTHTHROTTLER_H 28 29 30#include <wx/thread.h> 31 32#include <deque> 33 34#include "Types.h" 35 36class ThrottledControlSocket; 37class ThrottledFileSocket; 38 39class UploadBandwidthThrottler : public wxThread 40{ 41public: 42 UploadBandwidthThrottler(); 43 ~UploadBandwidthThrottler(); 44 45 uint64 GetNumberOfSentBytesSinceLastCallAndReset(); 46 uint64 GetNumberOfSentBytesOverheadSinceLastCallAndReset(); 47 48 void AddToStandardList(uint32 index, ThrottledFileSocket* socket); 49 bool RemoveFromStandardList(ThrottledFileSocket* socket); 50 51 void QueueForSendingControlPacket(ThrottledControlSocket* socket, bool hasSent = false); 52 void RemoveFromAllQueues(ThrottledControlSocket* socket); 53 void RemoveFromAllQueues(ThrottledFileSocket* socket); 54 55 void EndThread(); 56private: 57 void DoRemoveFromAllQueues(ThrottledControlSocket* socket); 58 bool RemoveFromStandardListNoLock(ThrottledFileSocket* socket); 59 60 void* Entry(); 61 62 bool m_doRun; 63 64 65 wxMutex m_sendLocker; 66 wxMutex m_tempQueueLocker; 67 68 typedef std::deque<ThrottledControlSocket*> SocketQueue; 69 70 // a queue for all the sockets that want to have Send() called on them. 71 SocketQueue m_ControlQueue_list; 72 // a queue for all the sockets that want to have Send() called on them. 73 SocketQueue m_ControlQueueFirst_list; 74 // sockets that wants to enter m_ControlQueue_list 75 SocketQueue m_TempControlQueue_list; 76 // sockets that wants to enter m_ControlQueue_list and has been able to send before 77 SocketQueue m_TempControlQueueFirst_list; 78 79 80 typedef std::deque<ThrottledFileSocket*> FileSocketQueue; 81 // sockets that have upload slots. Ordered so the most prioritized socket is first 82 FileSocketQueue m_StandardOrder_list; 83 84 uint64 m_SentBytesSinceLastCall; 85 uint64 m_SentBytesSinceLastCallOverhead; 86}; 87 88 89#endif 90// File_checked_for_headers 91