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 {nullptr}
 
PacketpBack {nullptr}
 
unsigned int iPacketCnt {0}
 
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 2991 of file C4NetIO.cpp.

2992  : iMaxPacketCnt(inMaxPacketCnt)
2993 {
2994 
2995 }
unsigned int iMaxPacketCnt
Definition: C4NetIO.h:700
C4NetIOUDP::PacketList::~PacketList ( )

Definition at line 2997 of file C4NetIO.cpp.

2998 {
2999  Clear();
3000 }

Member Function Documentation

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

Definition at line 3037 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().

3038 {
3039  CStdLock ListLock(&ListCSec);
3040  // find insert location
3041  Packet *pInsertAfter = pBack, *pInsertBefore = nullptr;
3042  for (; pInsertAfter; pInsertBefore = pInsertAfter, pInsertAfter = pInsertAfter->Prev)
3043  if (pInsertAfter->GetNr() + pInsertAfter->FragmentCnt() <= pPacket->GetNr())
3044  break;
3045  // check: enough space?
3046  if (pInsertBefore && pInsertBefore->GetNr() < pPacket->GetNr() + pPacket->FragmentCnt())
3047  return false;
3048  // insert
3049  (pInsertAfter ? pInsertAfter->Next : pFront) = pPacket;
3050  (pInsertBefore ? pInsertBefore->Prev : pBack) = pPacket;
3051  pPacket->Next = pInsertBefore;
3052  pPacket->Prev = pInsertAfter;
3053  // count packets, check limit
3054  ++iPacketCnt;
3055  while (iPacketCnt > iMaxPacketCnt)
3057  // ok
3058  return true;
3059 }
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:3061
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 3088 of file C4NetIO.cpp.

Referenced by C4NetIOUDP::ClearMCPackets().

3089 {
3090  CStdLock ListLock(&ListCSec);
3091  while (iPacketCnt)
3093 }
CStdCSecEx ListCSec
Definition: C4NetIO.h:702
bool DeletePacket(Packet *pPacket)
Definition: C4NetIO.cpp:3061
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 3081 of file C4NetIO.cpp.

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

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

Here is the caller graph for this function:

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

Definition at line 3061 of file C4NetIO.cpp.

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

3062 {
3063  CStdLock ListLock(&ListCSec);
3064 #ifdef _DEBUG
3065  // check: this list?
3066  Packet *pPos = pPacket;
3067  while (pPos && pPos != pFront) pPos = pPos->Prev;
3068  assert(pPos);
3069 #endif
3070  // unlink packet
3071  (pPacket->Prev ? pPacket->Prev->Next : pFront) = pPacket->Next;
3072  (pPacket->Next ? pPacket->Next->Prev : pBack) = pPacket->Prev;
3073  // delete packet
3074  delete pPacket;
3075  // decrease count
3076  --iPacketCnt;
3077  // ok
3078  return true;
3079 }
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 3030 of file C4NetIO.cpp.

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

3031 {
3032  CStdShareLock ListLock(&ListCSec);
3033  Packet *pPkt = GetPacketFrgm(iNr);
3034  return pPkt ? pPkt->FragmentPresent(iNr - pPkt->GetNr()) : false;
3035 }
friend class Packet
Definition: C4NetIO.h:688
CStdCSecEx ListCSec
Definition: C4NetIO.h:702
Packet * GetPacketFrgm(unsigned int iNr)
Definition: C4NetIO.cpp:3013

Here is the call graph for this function:

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

Definition at line 3024 of file C4NetIO.cpp.

3025 {
3026  CStdShareLock ListLock(&ListCSec);
3027  return pFront && pFront->Complete() ? pFront : nullptr;
3028 }
CStdCSecEx ListCSec
Definition: C4NetIO.h:702
bool Complete() const
Definition: C4NetIO.cpp:2914
C4NetIOUDP::Packet * C4NetIOUDP::PacketList::GetPacket ( unsigned int  iNr)

Definition at line 3002 of file C4NetIO.cpp.

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

3003 {
3004  CStdShareLock ListLock(&ListCSec);
3005  for (Packet *pPkt = pBack; pPkt; pPkt = pPkt->Prev)
3006  if (pPkt->GetNr() == iNr)
3007  return pPkt;
3008  else if (pPkt->GetNr() < iNr)
3009  return nullptr;
3010  return nullptr;
3011 }
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 3013 of file C4NetIO.cpp.

3014 {
3015  CStdShareLock ListLock(&ListCSec);
3016  for (Packet *pPkt = pBack; pPkt; pPkt = pPkt->Prev)
3017  if (pPkt->GetNr() <= iNr && pPkt->GetNr() + pPkt->FragmentCnt() > iNr)
3018  return pPkt;
3019  else if (pPkt->GetNr() < iNr)
3020  return nullptr;
3021  return nullptr;
3022 }
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 {0}
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 {nullptr}
protected

Definition at line 698 of file C4NetIO.h.

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

Definition at line 698 of file C4NetIO.h.


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