OpenClonk
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 {nullptr}
 
PacketpBack {nullptr}
 
unsigned int iPacketCnt {0}
 
unsigned int iMaxPacketCnt
 
CStdCSecEx ListCSec
 

Detailed Description

Definition at line 707 of file C4NetIO.h.

Constructor & Destructor Documentation

◆ PacketList()

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

Definition at line 3048 of file C4NetIO.cpp.

3049  : iMaxPacketCnt(inMaxPacketCnt)
3050 {
3051 
3052 }
unsigned int iMaxPacketCnt
Definition: C4NetIO.h:717

◆ ~PacketList()

C4NetIOUDP::PacketList::~PacketList ( )

Definition at line 3054 of file C4NetIO.cpp.

References Clear().

3055 {
3056  Clear();
3057 }
Here is the call graph for this function:

Member Function Documentation

◆ AddPacket()

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

Definition at line 3094 of file C4NetIO.cpp.

References DeletePacket(), C4NetIOUDP::Packet::FragmentCnt(), C4NetIOUDP::Packet::GetNr(), iMaxPacketCnt, iPacketCnt, ListCSec, C4NetIOUDP::Packet::Next, pBack, pFront, and C4NetIOUDP::Packet::Prev.

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

3095 {
3096  CStdLock ListLock(&ListCSec);
3097  // find insert location
3098  Packet *pInsertAfter = pBack, *pInsertBefore = nullptr;
3099  for (; pInsertAfter; pInsertBefore = pInsertAfter, pInsertAfter = pInsertAfter->Prev)
3100  if (pInsertAfter->GetNr() + pInsertAfter->FragmentCnt() <= pPacket->GetNr())
3101  break;
3102  // check: enough space?
3103  if (pInsertBefore && pInsertBefore->GetNr() < pPacket->GetNr() + pPacket->FragmentCnt())
3104  return false;
3105  // insert
3106  (pInsertAfter ? pInsertAfter->Next : pFront) = pPacket;
3107  (pInsertBefore ? pInsertBefore->Prev : pBack) = pPacket;
3108  pPacket->Next = pInsertBefore;
3109  pPacket->Prev = pInsertAfter;
3110  // count packets, check limit
3111  ++iPacketCnt;
3112  while (iPacketCnt > iMaxPacketCnt)
3114  // ok
3115  return true;
3116 }
unsigned int iMaxPacketCnt
Definition: C4NetIO.h:717
friend class Packet
Definition: C4NetIO.h:705
Packet * Next
Definition: C4NetIO.h:703
CStdCSecEx ListCSec
Definition: C4NetIO.h:719
bool DeletePacket(Packet *pPacket)
Definition: C4NetIO.cpp:3118
unsigned int iPacketCnt
Definition: C4NetIO.h:717
Packet * Prev
Definition: C4NetIO.h:703
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Clear()

void C4NetIOUDP::PacketList::Clear ( )

Definition at line 3145 of file C4NetIO.cpp.

References DeletePacket(), C4NetIOUDP::Peer::iConnectRetries, iPacketCnt, C4NetIOUDP::Peer::iReCheckInterval, ListCSec, and pFront.

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

3146 {
3147  CStdLock ListLock(&ListCSec);
3148  while (iPacketCnt)
3150 }
CStdCSecEx ListCSec
Definition: C4NetIO.h:719
bool DeletePacket(Packet *pPacket)
Definition: C4NetIO.cpp:3118
unsigned int iPacketCnt
Definition: C4NetIO.h:717
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ClearPackets()

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

Definition at line 3138 of file C4NetIO.cpp.

References DeletePacket(), C4NetIOUDP::Packet::GetNr(), ListCSec, and pFront.

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

3139 {
3140  CStdLock ListLock(&ListCSec);
3141  while (pFront && pFront->GetNr() < iUntil)
3143 }
CStdCSecEx ListCSec
Definition: C4NetIO.h:719
nr_t GetNr() const
Definition: C4NetIO.h:690
bool DeletePacket(Packet *pPacket)
Definition: C4NetIO.cpp:3118
Here is the call graph for this function:
Here is the caller graph for this function:

◆ DeletePacket()

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

Definition at line 3118 of file C4NetIO.cpp.

References iPacketCnt, ListCSec, C4NetIOUDP::Packet::Next, pBack, pFront, and C4NetIOUDP::Packet::Prev.

Referenced by AddPacket(), C4NetIOUDP::Peer::CheckCompleteIPackets(), Clear(), and ClearPackets().

3119 {
3120  CStdLock ListLock(&ListCSec);
3121 #ifdef _DEBUG
3122  // check: this list?
3123  Packet *pPos = pPacket;
3124  while (pPos && pPos != pFront) pPos = pPos->Prev;
3125  assert(pPos);
3126 #endif
3127  // unlink packet
3128  (pPacket->Prev ? pPacket->Prev->Next : pFront) = pPacket->Next;
3129  (pPacket->Next ? pPacket->Next->Prev : pBack) = pPacket->Prev;
3130  // delete packet
3131  delete pPacket;
3132  // decrease count
3133  --iPacketCnt;
3134  // ok
3135  return true;
3136 }
friend class Packet
Definition: C4NetIO.h:705
CStdCSecEx ListCSec
Definition: C4NetIO.h:719
unsigned int iPacketCnt
Definition: C4NetIO.h:717
Here is the caller graph for this function:

◆ FragmentPresent()

bool C4NetIOUDP::PacketList::FragmentPresent ( unsigned int  iNr)

Definition at line 3087 of file C4NetIO.cpp.

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

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

3088 {
3089  CStdShareLock ListLock(&ListCSec);
3090  Packet *pPkt = GetPacketFrgm(iNr);
3091  return pPkt ? pPkt->FragmentPresent(iNr - pPkt->GetNr()) : false;
3092 }
friend class Packet
Definition: C4NetIO.h:705
CStdCSecEx ListCSec
Definition: C4NetIO.h:719
Packet * GetPacketFrgm(unsigned int iNr)
Definition: C4NetIO.cpp:3070
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetFirstPacketComplete()

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

Definition at line 3081 of file C4NetIO.cpp.

References C4NetIOUDP::Packet::Complete(), ListCSec, and pFront.

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

3082 {
3083  CStdShareLock ListLock(&ListCSec);
3084  return pFront && pFront->Complete() ? pFront : nullptr;
3085 }
CStdCSecEx ListCSec
Definition: C4NetIO.h:719
bool Complete() const
Definition: C4NetIO.cpp:2971
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetPacket()

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

Definition at line 3059 of file C4NetIO.cpp.

References ListCSec, pBack, and C4NetIOUDP::Packet::Prev.

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

3060 {
3061  CStdShareLock ListLock(&ListCSec);
3062  for (Packet *pPkt = pBack; pPkt; pPkt = pPkt->Prev)
3063  if (pPkt->GetNr() == iNr)
3064  return pPkt;
3065  else if (pPkt->GetNr() < iNr)
3066  return nullptr;
3067  return nullptr;
3068 }
friend class Packet
Definition: C4NetIO.h:705
CStdCSecEx ListCSec
Definition: C4NetIO.h:719
Packet * Prev
Definition: C4NetIO.h:703
Here is the caller graph for this function:

◆ GetPacketFrgm()

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

Definition at line 3070 of file C4NetIO.cpp.

References ListCSec, pBack, and C4NetIOUDP::Packet::Prev.

Referenced by C4NetIOUDP::Peer::CheckCompleteIPackets(), and FragmentPresent().

3071 {
3072  CStdShareLock ListLock(&ListCSec);
3073  for (Packet *pPkt = pBack; pPkt; pPkt = pPkt->Prev)
3074  if (pPkt->GetNr() <= iNr && pPkt->GetNr() + pPkt->FragmentCnt() > iNr)
3075  return pPkt;
3076  else if (pPkt->GetNr() < iNr)
3077  return nullptr;
3078  return nullptr;
3079 }
friend class Packet
Definition: C4NetIO.h:705
CStdCSecEx ListCSec
Definition: C4NetIO.h:719
Packet * Prev
Definition: C4NetIO.h:703
Here is the caller graph for this function:

Member Data Documentation

◆ iMaxPacketCnt

unsigned int C4NetIOUDP::PacketList::iMaxPacketCnt
protected

Definition at line 717 of file C4NetIO.h.

Referenced by AddPacket().

◆ iPacketCnt

unsigned int C4NetIOUDP::PacketList::iPacketCnt {0}
protected

Definition at line 717 of file C4NetIO.h.

Referenced by AddPacket(), Clear(), and DeletePacket().

◆ ListCSec

CStdCSecEx C4NetIOUDP::PacketList::ListCSec
protected

◆ pBack

Packet * C4NetIOUDP::PacketList::pBack {nullptr}
protected

Definition at line 715 of file C4NetIO.h.

Referenced by AddPacket(), DeletePacket(), GetPacket(), and GetPacketFrgm().

◆ pFront

Packet* C4NetIOUDP::PacketList::pFront {nullptr}
protected

Definition at line 715 of file C4NetIO.h.

Referenced by AddPacket(), Clear(), ClearPackets(), DeletePacket(), and GetFirstPacketComplete().


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