OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4NetIOUDP::PacketList Class Reference

#include <C4NetIO.h>

Collaboration diagram for C4NetIOUDP::PacketList:
[legend]

Public Member Functions

 PacketList (unsigned int iMaxPacketCnt=~0)
 
 ~PacketList ()
 
PacketGetPacket (unsigned int iNr)
 
PacketGetPacketFrgm (unsigned int iNr)
 
PacketGetFirstPacketComplete ()
 
bool FragmentPresent (unsigned int iNr)
 
bool AddPacket (Packet *pPacket)
 
bool DeletePacket (Packet *pPacket)
 
void ClearPackets (unsigned int iUntil)
 
void Clear ()
 

Protected Attributes

PacketpFront
 
PacketpBack
 
unsigned int iPacketCnt
 
unsigned int iMaxPacketCnt
 
CStdCSecEx ListCSec
 

Detailed Description

Definition at line 690 of file C4NetIO.h.

Constructor & Destructor Documentation

C4NetIOUDP::PacketList::PacketList ( unsigned int  iMaxPacketCnt = ~0)

Definition at line 3011 of file C4NetIO.cpp.

3012  : pFront(nullptr),
3013  pBack(nullptr),
3014  iPacketCnt(0),
3015  iMaxPacketCnt(inMaxPacketCnt)
3016 {
3017 
3018 }
unsigned int iMaxPacketCnt
Definition: C4NetIO.h:700
unsigned int iPacketCnt
Definition: C4NetIO.h:700
C4NetIOUDP::PacketList::~PacketList ( )

Definition at line 3020 of file C4NetIO.cpp.

3021 {
3022  Clear();
3023 }

Member Function Documentation

bool C4NetIOUDP::PacketList::AddPacket ( Packet pPacket)

Definition at line 3060 of file C4NetIO.cpp.

References C4NetIOUDP::Packet::FragmentCnt(), C4NetIOUDP::Packet::GetNr(), C4NetIOUDP::Packet::Next, and C4NetIOUDP::Packet::Prev.

Referenced by C4NetIOUDP::Broadcast(), C4NetIOUDP::Peer::OnRecv(), and C4NetIOUDP::Peer::Send().

3061 {
3062  CStdLock ListLock(&ListCSec);
3063  // find insert location
3064  Packet *pInsertAfter = pBack, *pInsertBefore = nullptr;
3065  for (; pInsertAfter; pInsertBefore = pInsertAfter, pInsertAfter = pInsertAfter->Prev)
3066  if (pInsertAfter->GetNr() + pInsertAfter->FragmentCnt() <= pPacket->GetNr())
3067  break;
3068  // check: enough space?
3069  if (pInsertBefore && pInsertBefore->GetNr() < pPacket->GetNr() + pPacket->FragmentCnt())
3070  return false;
3071  // insert
3072  (pInsertAfter ? pInsertAfter->Next : pFront) = pPacket;
3073  (pInsertBefore ? pInsertBefore->Prev : pBack) = pPacket;
3074  pPacket->Next = pInsertBefore;
3075  pPacket->Prev = pInsertAfter;
3076  // count packets, check limit
3077  ++iPacketCnt;
3078  while (iPacketCnt > iMaxPacketCnt)
3080  // ok
3081  return true;
3082 }
unsigned int iMaxPacketCnt
Definition: C4NetIO.h:700
friend class Packet
Definition: C4NetIO.h:688
Packet * Next
Definition: C4NetIO.h:686
CStdCSecEx ListCSec
Definition: C4NetIO.h:702
bool DeletePacket(Packet *pPacket)
Definition: C4NetIO.cpp:3084
unsigned int iPacketCnt
Definition: C4NetIO.h:700
Packet * Prev
Definition: C4NetIO.h:686

Here is the call graph for this function:

Here is the caller graph for this function:

void C4NetIOUDP::PacketList::Clear ( )

Definition at line 3111 of file C4NetIO.cpp.

Referenced by C4NetIOUDP::ClearMCPackets().

3112 {
3113  CStdLock ListLock(&ListCSec);
3114  while (iPacketCnt)
3116 }
CStdCSecEx ListCSec
Definition: C4NetIO.h:702
bool DeletePacket(Packet *pPacket)
Definition: C4NetIO.cpp:3084
unsigned int iPacketCnt
Definition: C4NetIO.h:700

Here is the caller graph for this function:

void C4NetIOUDP::PacketList::ClearPackets ( unsigned int  iUntil)

Definition at line 3104 of file C4NetIO.cpp.

Referenced by C4NetIOUDP::ClearMCPackets(), and C4NetIOUDP::Peer::OnRecv().

3105 {
3106  CStdLock ListLock(&ListCSec);
3107  while (pFront && pFront->GetNr() < iUntil)
3109 }
nr_t GetNr() const
Definition: C4NetIO.h:673
CStdCSecEx ListCSec
Definition: C4NetIO.h:702
bool DeletePacket(Packet *pPacket)
Definition: C4NetIO.cpp:3084

Here is the caller graph for this function:

bool C4NetIOUDP::PacketList::DeletePacket ( Packet pPacket)

Definition at line 3084 of file C4NetIO.cpp.

References C4NetIOUDP::Packet::Next, and C4NetIOUDP::Packet::Prev.

3085 {
3086  CStdLock ListLock(&ListCSec);
3087 #ifdef _DEBUG
3088  // check: this list?
3089  Packet *pPos = pPacket;
3090  while (pPos && pPos != pFront) pPos = pPos->Prev;
3091  assert(pPos);
3092 #endif
3093  // unlink packet
3094  (pPacket->Prev ? pPacket->Prev->Next : pFront) = pPacket->Next;
3095  (pPacket->Next ? pPacket->Next->Prev : pBack) = pPacket->Prev;
3096  // delete packet
3097  delete pPacket;
3098  // decrease count
3099  --iPacketCnt;
3100  // ok
3101  return true;
3102 }
friend class Packet
Definition: C4NetIO.h:688
CStdCSecEx ListCSec
Definition: C4NetIO.h:702
unsigned int iPacketCnt
Definition: C4NetIO.h:700
bool C4NetIOUDP::PacketList::FragmentPresent ( unsigned int  iNr)

Definition at line 3053 of file C4NetIO.cpp.

References C4NetIOUDP::Packet::FragmentPresent(), and C4NetIOUDP::Packet::GetNr().

3054 {
3055  CStdShareLock ListLock(&ListCSec);
3056  Packet *pPkt = GetPacketFrgm(iNr);
3057  return pPkt ? pPkt->FragmentPresent(iNr - pPkt->GetNr()) : false;
3058 }
friend class Packet
Definition: C4NetIO.h:688
CStdCSecEx ListCSec
Definition: C4NetIO.h:702
Packet * GetPacketFrgm(unsigned int iNr)
Definition: C4NetIO.cpp:3036

Here is the call graph for this function:

C4NetIOUDP::Packet * C4NetIOUDP::PacketList::GetFirstPacketComplete ( )

Definition at line 3047 of file C4NetIO.cpp.

3048 {
3049  CStdShareLock ListLock(&ListCSec);
3050  return pFront && pFront->Complete() ? pFront : nullptr;
3051 }
CStdCSecEx ListCSec
Definition: C4NetIO.h:702
bool Complete() const
Definition: C4NetIO.cpp:2934
C4NetIOUDP::Packet * C4NetIOUDP::PacketList::GetPacket ( unsigned int  iNr)

Definition at line 3025 of file C4NetIO.cpp.

Referenced by C4NetIOUDP::Peer::OnRecv().

3026 {
3027  CStdShareLock ListLock(&ListCSec);
3028  for (Packet *pPkt = pBack; pPkt; pPkt = pPkt->Prev)
3029  if (pPkt->GetNr() == iNr)
3030  return pPkt;
3031  else if (pPkt->GetNr() < iNr)
3032  return nullptr;
3033  return nullptr;
3034 }
friend class Packet
Definition: C4NetIO.h:688
CStdCSecEx ListCSec
Definition: C4NetIO.h:702
Packet * Prev
Definition: C4NetIO.h:686

Here is the caller graph for this function:

C4NetIOUDP::Packet * C4NetIOUDP::PacketList::GetPacketFrgm ( unsigned int  iNr)

Definition at line 3036 of file C4NetIO.cpp.

3037 {
3038  CStdShareLock ListLock(&ListCSec);
3039  for (Packet *pPkt = pBack; pPkt; pPkt = pPkt->Prev)
3040  if (pPkt->GetNr() <= iNr && pPkt->GetNr() + pPkt->FragmentCnt() > iNr)
3041  return pPkt;
3042  else if (pPkt->GetNr() < iNr)
3043  return nullptr;
3044  return nullptr;
3045 }
friend class Packet
Definition: C4NetIO.h:688
CStdCSecEx ListCSec
Definition: C4NetIO.h:702
Packet * Prev
Definition: C4NetIO.h:686

Member Data Documentation

unsigned int C4NetIOUDP::PacketList::iMaxPacketCnt
protected

Definition at line 700 of file C4NetIO.h.

unsigned int C4NetIOUDP::PacketList::iPacketCnt
protected

Definition at line 700 of file C4NetIO.h.

CStdCSecEx C4NetIOUDP::PacketList::ListCSec
protected

Definition at line 702 of file C4NetIO.h.

Packet * C4NetIOUDP::PacketList::pBack
protected

Definition at line 698 of file C4NetIO.h.

Packet* C4NetIOUDP::PacketList::pFront
protected

Definition at line 698 of file C4NetIO.h.


The documentation for this class was generated from the following files: