00001 // 00002 // PacketBuffer.h 00003 // 00004 // Copyright (c) Shareaza Development Team, 2002-2005. 00005 // This file is part of SHAREAZA (www.shareaza.com) 00006 // 00007 // Shareaza is free software; you can redistribute it 00008 // and/or modify it under the terms of the GNU General Public License 00009 // as published by the Free Software Foundation; either version 2 of 00010 // the License, or (at your option) any later version. 00011 // 00012 // Shareaza is distributed in the hope that it will be useful, 00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 // GNU General Public License for more details. 00016 // 00017 // You should have received a copy of the GNU General Public License 00018 // along with Shareaza; if not, write to the Free Software 00019 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00020 // 00021 00022 // CG1PacketBuffer holds arrays of packets to send, organized by their type 00023 // http://wiki.shareaza.com/static/Developers.Code.CG1PacketBuffer 00024 00025 // Make the compiler only include the lines here once, this is the same thing as pragma once 00026 #if !defined(AFX_PACKETBUFFER_H__7FE2F4C5_B0E8_444C_9B26_C95CCB344615__INCLUDED_) 00027 #define AFX_PACKETBUFFER_H__7FE2F4C5_B0E8_444C_9B26_C95CCB344615__INCLUDED_ 00028 00029 // Only include the lines beneath this one once 00030 #pragma once 00031 00032 // Tell the compiler these classes exist, and it will find out more about them soon 00033 class CG1Packet; 00034 class CBuffer; 00035 class CG1PacketBufferType; 00036 00037 // Holds 9 arrays of 64 Gnutella packets each, one array for each packet type, like ping or pong 00038 class CG1PacketBuffer 00039 { 00040 00041 public: 00042 00043 // Make a new set of arrays, and delete this set 00044 CG1PacketBuffer(CBuffer* pBuffer); // Takes a buffer to write packets to instead of putting them in the arrays 00045 virtual ~CG1PacketBuffer(); 00046 00047 public: 00048 00049 // Total counts of packets in the arrays 00050 int m_nTotal; // The number of packets Add added without overwriting any 00051 int m_nDropped; // The number of packets Add overwrote 00052 00053 protected: 00054 00055 // The buffer where we can write packets directly, instead of putting them in arrays 00056 CBuffer* m_pBuffer; 00057 00058 // Arrays of packets, one for each type 00059 int m_nCycle; // The type of packet to send next, like 1 ping array, 2 pong array, and so on 00060 int m_nIterate; // The number of packets of this type we've recently sent 00061 CG1PacketBufferType* m_pType; // An array of 9 pointers to arrays of 64 packets each, one array for each packet type 00062 00063 public: 00064 00065 // Add a packet, and clear them all 00066 void Add(CG1Packet* pPacket, BOOL bBuffered = TRUE); // Add a packet to the array of its type 00067 void Clear(); // Clear all the packets from all the arrays 00068 00069 // Get a packet to send, it chooses one added recently, not expired, and keeps the type mixed up 00070 CG1Packet* GetPacketToSend(DWORD dwExpire = 0); 00071 }; 00072 00073 // Holds an array of 64 pointers to packets to send, all of one type, and the time each expires 1 minute after they were added 00074 class CG1PacketBufferType 00075 { 00076 00077 public: 00078 00079 // Create a new packet buffer type object, and delete this one 00080 CG1PacketBufferType(); 00081 virtual ~CG1PacketBufferType(); 00082 00083 protected: 00084 00085 // Two arrays that hold information about 64 Gnutella packets 00086 CG1Packet** m_pBuffer; // This is a pointer to an array of 64 pointers to Gnutella packets, and has nothing to do with a CBuffer object 00087 DWORD* m_pTime; // The time each packet will expire, which is 1 minute after it is added 00088 00089 // Indices and counts for those arrays 00090 int m_nHead; // The index in the array where we added information about a packet most recently 00091 int m_nCount; // The number of spots in the array filled with a packet pointer and time 00092 int m_nCapacity; // The size of the arrays we allocated from settings, 64 by default 00093 00094 public: 00095 00096 // Add a packet to the array, get one out, and clear them all 00097 BOOL Add(CG1Packet* pPacket); 00098 CG1Packet* Get(DWORD dwExpire = 0, int* pnTotal = NULL, int* pnDropped = NULL); 00099 void Clear(); 00100 }; 00101 00102 // End the group of lines to only include once, pragma once doesn't require an endif at the bottom 00103 #endif // !defined(AFX_PACKETBUFFER_H__7FE2F4C5_B0E8_444C_9B26_C95CCB344615__INCLUDED_)