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

📄 btpacket.h

📁 p2p软件
💻 H
字号:
//
// BTPacket.h
//
// Copyright (c) Shareaza Development Team, 2002-2004.
// This file is part of SHAREAZA (www.shareaza.com)
//
// Shareaza is free software; you can redistribute it
// and/or modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2 of
// the License, or (at your option) any later version.
//
// Shareaza is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Shareaza; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//

#if !defined(AFX_BTPACKET_H__F3CA41D9_F0E8_4996_A551_F7EEE8D509B3__INCLUDED_)
#define AFX_BTPACKET_H__F3CA41D9_F0E8_4996_A551_F7EEE8D509B3__INCLUDED_

#pragma once

#include "Packet.h"

//
// Packet
//

class CBTPacket : public CPacket
{
// Construction
protected:
	CBTPacket();
	virtual ~CBTPacket();

// Attributes
public:
	BYTE	m_nType;
	
// Operations
public:
	virtual	void		ToBuffer(CBuffer* pBuffer) const;
	static	CBTPacket*	ReadBuffer(CBuffer* pBuffer);
public:
	virtual LPCTSTR		GetType() const;

// Packet Pool
protected:
	class CBTPacketPool : public CPacketPool
	{
	public:
		virtual ~CBTPacketPool() { Clear(); }
	protected:
		virtual void NewPoolImpl(int nSize, CPacket*& pPool, int& nPitch);
		virtual void FreePoolImpl(CPacket* pPool);
	};
	
	static CBTPacketPool POOL;

// Allocation
public:
	inline static CBTPacket* New(BYTE nType)
	{
		CBTPacket* pPacket = (CBTPacket*)POOL.New();
		pPacket->m_nType = nType;
		return pPacket;
	}

	inline virtual void Delete()
	{
		POOL.Delete( this );
	}
	
	friend class CBTPacket::CBTPacketPool;
};

inline void CBTPacket::CBTPacketPool::NewPoolImpl(int nSize, CPacket*& pPool, int& nPitch)
{
	nPitch	= sizeof(CBTPacket);
	pPool	= new CBTPacket[ nSize ];
}

inline void CBTPacket::CBTPacketPool::FreePoolImpl(CPacket* pPacket)
{
	delete [] (CBTPacket*)pPacket;
}

//
// Packet Types
//

#define BT_PACKET_CHOKE				0
#define BT_PACKET_UNCHOKE			1
#define BT_PACKET_INTERESTED		2
#define BT_PACKET_NOT_INTERESTED	3
#define BT_PACKET_HAVE				4
#define BT_PACKET_BITFIELD			5
#define BT_PACKET_REQUEST			6
#define BT_PACKET_PIECE				7
#define BT_PACKET_CANCEL			8

#define BT_PACKET_HANDSHAKE			128
#define BT_PACKET_SOURCE_REQUEST	129
#define BT_PACKET_SOURCE_RESPONSE	130

#define BT_PACKET_KEEPALIVE			255

#pragma pack(1)

typedef struct
{
	DWORD	nLength;
	BYTE	nType;
	DWORD	nPiece;
	DWORD	nOffset;
} BT_PIECE_HEADER;

#pragma pack()

#endif // !defined(AFX_BTPACKET_H__F3CA41D9_F0E8_4996_A551_F7EEE8D509B3__INCLUDED_)

⌨️ 快捷键说明

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