Choker.h
资源名称:GGBT.rar [点击查看]
上传用户:lds876
上传日期:2013-05-25
资源大小:567k
文件大小:1k
源码类别:
P2P编程
开发平台:
Visual C++
- // Choker.h: interface for the CChoker class.
- //
- //////////////////////////////////////////////////////////////////////
- #if !defined(AFX_CHOKER_H__C1CFEB4B_319A_437D_81C9_DD69A484ACA7__INCLUDED_)
- #define AFX_CHOKER_H__C1CFEB4B_319A_437D_81C9_DD69A484ACA7__INCLUDED_
- #if _MSC_VER > 1000
- #pragma once
- #endif // _MSC_VER > 1000
- class CConnection;
- class CChoker
- {
- class CPreferItem
- {
- public:
- CPreferItem(long lrate, CConnection* pConnection)
- {
- m_lrate = lrate;
- m_pConnection = pConnection;
- }
- long m_lrate;
- CConnection* m_pConnection;
- };
- struct std::greater<CPreferItem&>
- {
- bool operator()(CPreferItem&x, CPreferItem& y)
- {
- return x.m_lrate > y.m_lrate;
- }
- };
- public:
- CChoker(long lMaxUploads, HANDLE hevDone);
- virtual ~CChoker();
- void SetMaxUploads(long lMaxUploads);
- time_t round_robin();
- void interested(CConnection* pConnection);
- void not_interested(CConnection* pConnection);
- void connection_lost(CConnection* pConnection);
- void connection_made(CConnection* pConnection);
- private:
- void _test();
- void _round_robin();
- void _rechoke();
- bool _snubbed(CConnection* pConnection);
- long _rate(CConnection* pConnection);
- static void printitem(CPreferItem& item);
- vector<CConnection*> m_connections;
- long m_lMaxUploads;
- HANDLE m_hevDone;
- time_t m_tRoundRobin;
- long m_lCount;
- };
- #endif // !defined(AFX_CHOKER_H__C1CFEB4B_319A_437D_81C9_DD69A484ACA7__INCLUDED_)