Connection.h
资源名称:GGBT.rar [点击查看]
上传用户:lds876
上传日期:2013-05-25
资源大小:567k
文件大小:2k
源码类别:
P2P编程
开发平台:
Visual C++
- // Connection.h: interface for the CConnection class.
- //
- //////////////////////////////////////////////////////////////////////
- #if !defined(AFX_CONNECTION_H__23CEED2C_4E50_4480_B2A1_D27433C01AFD__INCLUDED_)
- #define AFX_CONNECTION_H__23CEED2C_4E50_4480_B2A1_D27433C01AFD__INCLUDED_
- #if _MSC_VER > 1000
- #pragma once
- #endif // _MSC_VER > 1000
- // enum {CHOKE, UNCHOKE, INTERESTED, NOT_INTERESTED, HAVE, BITFIELD, REQUEST, PIECE, CANCEL};
- #define CHOKE 0
- #define UNCHOKE 1
- #define INTERESTED 2
- #define NOT_INTERESTED 3
- #define HAVE 4
- #define BITFIELD 5
- #define REQUEST 6
- #define PIECE 7
- #define CANCEL 8
- void booleans_to_bitfield(vector<bool>&vHave, memstream& memRet);
- bool bitfield_to_booleans(memstream& membitfield, long lNumPieces, vector<bool>& vHave);
- class CEncryptedConnection;
- class CConnector;
- class CSingleDownload;
- class CUpload;
- class CConnection
- {
- public:
- CConnection(CEncryptedConnection* pEConnection, CConnector* pConnector);
- virtual ~CConnection();
- void send_interested();
- void send_not_interested();
- void send_choke();
- void send_unchoke();
- void send_request(long index, long begin, long length);
- void send_cancel(long index, long begin, long length);
- void send_piece(long index, long begin, memstream& piece);
- void send_bitfield(vector<bool>& vHave);
- void send_have(long index);
- void GetRate(long& lDownRate, long & lUpRate);
- string GetIP();
- bool GetIP(long& lAddr, short& sPort);
- memstream& GetID();
- bool IsFlush();
- bool is_locally_initiated();
- void Close();
- bool IsPause();
- void Pause(bool bPause);
- // data
- CEncryptedConnection* m_pEConnection;
- bool m_bGotAnything;
- CSingleDownload* m_pDownload;
- CUpload* m_pUpload;
- enum {eCount = 30};
- long m_lValueUp[eCount];
- long m_lValueDown[eCount];
- long m_lIndex;
- private:
- CConnector* m_pConnector;
- bool m_bPause;
- };
- #endif // !defined(AFX_CONNECTION_H__23CEED2C_4E50_4480_B2A1_D27433C01AFD__INCLUDED_)