⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 btsocket.h

📁 模拟P2P各种网络环境的,适合新手们的学习,不错的源码.
💻 H
字号:
#ifndef __BTSOCKET_H__
#define __BTSOCKET_H__
#include <vector>
#include <list>
#include "SimEventHandler.h"
using namespace std;
class BTSession;
class BTConnection;
class BTEvent;
typedef unsigned long BandType;
class BTSocket: public SimEventHandler{
typedef struct{
	double mTimeStamp;
	BandType  mBandwidth;
}BandwidthHistory;
public:
	BTSocket*	mCounterPart;
	BTConnection* mInConnection;
	BTConnection* mOutConnection;
	BTSession*	mSession;
	BTEvent* 	mRequestTimeout;
	BTEvent* 	mConnectionTimeout; 
	BTEvent* 	mEstimateFinish;
	bool 		mPeerInsterested;
	bool			mInsterested;
	bool			mPeerChoke;
	bool			mChoke;
	bool			mUploading;
	bool			mDownloading;
	unsigned int	mRequestingPiece;
	unsigned int	mBegin;
	unsigned int	mLength;
	unsigned int 	mDownloadLeft;
	double 		mStartTime;
	bool			mConnected;
	bool			mClosed;
	list<BandwidthHistory*> mInBandwidthHistory;
	list<BandwidthHistory*> mOutBandwidthHistory;
	double		mAvrDownload;
	double		mAvrUpload;
public:
	BTSocket(BTSession*);
	~BTSocket(void);
	void handler(SimEvent*);
	void handleBlockFininshed(BTEvent*);
	void handleRequestTimeout(BTEvent*);
	void adjustInBandwidth(void);
	void adjustOutBandwidth(void);
	double calcInAverageBandwidthSince(double);
	double calcOutAverageBandwidthSince(double);
	void sendConnectionTimeout(void);
	void cancelConnectionTimeout(void);
	void changeConnectionTimeout(void);
	void sendRequestTimeout(void);
	void cancelRequestTimeout(void);
	void changeRequestTimeout(void);
	//string toString(void){};

};
#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -