Choker.h
上传用户:lds876
上传日期:2013-05-25
资源大小:567k
文件大小:1k
源码类别:

P2P编程

开发平台:

Visual C++

  1. // Choker.h: interface for the CChoker class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #if !defined(AFX_CHOKER_H__C1CFEB4B_319A_437D_81C9_DD69A484ACA7__INCLUDED_)
  5. #define AFX_CHOKER_H__C1CFEB4B_319A_437D_81C9_DD69A484ACA7__INCLUDED_
  6. #if _MSC_VER > 1000
  7. #pragma once
  8. #endif // _MSC_VER > 1000
  9. class CConnection;
  10. class CChoker  
  11. {
  12. class CPreferItem
  13. {
  14. public:
  15. CPreferItem(long lrate, CConnection* pConnection)
  16. {
  17. m_lrate = lrate;
  18. m_pConnection = pConnection;
  19. }
  20. long m_lrate;
  21. CConnection* m_pConnection;
  22. };
  23. struct std::greater<CPreferItem&>
  24. {
  25. bool operator()(CPreferItem&x, CPreferItem& y)
  26. {
  27. return x.m_lrate > y.m_lrate;
  28. }
  29. };
  30. public:
  31. CChoker(long lMaxUploads, HANDLE hevDone);
  32. virtual ~CChoker();
  33. void SetMaxUploads(long lMaxUploads);
  34. time_t round_robin();
  35. void interested(CConnection* pConnection);
  36. void not_interested(CConnection* pConnection);
  37. void connection_lost(CConnection* pConnection);
  38. void connection_made(CConnection* pConnection);
  39. private:
  40. void _test();
  41. void _round_robin();
  42. void _rechoke();
  43. bool _snubbed(CConnection* pConnection);
  44. long _rate(CConnection* pConnection);
  45. static void printitem(CPreferItem& item);
  46. vector<CConnection*> m_connections;
  47. long m_lMaxUploads;
  48. HANDLE m_hevDone;
  49. time_t m_tRoundRobin;
  50. long m_lCount;
  51. };
  52. #endif // !defined(AFX_CHOKER_H__C1CFEB4B_319A_437D_81C9_DD69A484ACA7__INCLUDED_)