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 689 of file C4NetIO.h.

Constructor & Destructor Documentation

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

Definition at line 2981 of file C4NetIO.cpp.

2982  : iMaxPacketCnt(inMaxPacketCnt)
2983 {
2984 
2985 }
unsigned int iMaxPacketCnt
Definition: C4NetIO.h:699
C4NetIOUDP::PacketList::~PacketList ( )

Definition at line 2987 of file C4NetIO.cpp.

2988 {
2989  Clear();
2990 }

Member Function Documentation

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

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

3028 {
3029  CStdLock ListLock(&ListCSec);
3030  // find insert location
3031  Packet *pInsertAfter = pBack, *pInsertBefore = nullptr;
3032  for (; pInsertAfter; pInsertBefore = pInsertAfter, pInsertAfter = pInsertAfter->Prev)
3033  if (pInsertAfter->GetNr() + pInsertAfter->FragmentCnt() <= pPacket->GetNr())
3034  break;
3035  // check: enough space?
3036  if (pInsertBefore && pInsertBefore->GetNr() < pPacket->GetNr() + pPacket->FragmentCnt())
3037  return false;
3038  // insert
3039  (pInsertAfter ? pInsertAfter->Next : pFront) = pPacket;
3040  (pInsertBefore ? pInsertBefore->Prev : pBack) = pPacket;
3041  pPacket->Next = pInsertBefore;
3042  pPacket->Prev = pInsertAfter;
3043  // count packets, check limit
3044  ++iPacketCnt;
3045  while (iPacketCnt > iMaxPacketCnt)
3047  // ok
3048  return true;
3049 }
unsigned int iMaxPacketCnt
Definition: C4NetIO.h:699
friend class Packet
Definition: C4NetIO.h:687
Packet * Next
Definition: C4NetIO.h:685
CStdCSecEx ListCSec
Definition: C4NetIO.h:701
bool DeletePacket(Packet *pPacket)
Definition: C4NetIO.cpp:3051
unsigned int iPacketCnt
Definition: C4NetIO.h:699
Packet * Prev
Definition: C4NetIO.h:685

Here is the call graph for this function:

Here is the caller graph for this function:

void C4NetIOUDP::PacketList::Clear ( )

Definition at line 3078 of file C4NetIO.cpp.

Referenced by C4NetIOUDP::ClearMCPackets().

3079 {
3080  CStdLock ListLock(&ListCSec);
3081  while (iPacketCnt)
3083 }
CStdCSecEx ListCSec
Definition: C4NetIO.h:701
bool DeletePacket(Packet *pPacket)
Definition: C4NetIO.cpp:3051
unsigned int iPacketCnt
Definition: C4NetIO.h:699

Here is the caller graph for this function:

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

Definition at line 3071 of file C4NetIO.cpp.

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

3072 {
3073  CStdLock ListLock(&ListCSec);
3074  while (pFront && pFront->GetNr() < iUntil)
3076 }
nr_t GetNr() const
Definition: C4NetIO.h:672
CStdCSecEx ListCSec
Definition: C4NetIO.h:701
bool DeletePacket(Packet *pPacket)
Definition: C4NetIO.cpp:3051

Here is the caller graph for this function:

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

Definition at line 3051 of file C4NetIO.cpp.

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

3052 {
3053  CStdLock ListLock(&ListCSec);
3054 #ifdef _DEBUG
3055  // check: this list?
3056  Packet *pPos = pPacket;
3057  while (pPos && pPos != pFront) pPos = pPos->Prev;
3058  assert(pPos);
3059 #endif
3060  // unlink packet
3061  (pPacket->Prev ? pPacket->Prev->Next : pFront) = pPacket->Next;
3062  (pPacket->Next ? pPacket->Next->Prev : pBack) = pPacket->Prev;
3063  // delete packet
3064  delete pPacket;
3065  // decrease count
3066  --iPacketCnt;
3067  // ok
3068  return true;
3069 }
friend class Packet
Definition: C4NetIO.h:687
CStdCSecEx ListCSec
Definition: C4NetIO.h:701
unsigned int iPacketCnt
Definition: C4NetIO.h:699
bool C4NetIOUDP::PacketList::FragmentPresent ( unsigned int  iNr)

Definition at line 3020 of file C4NetIO.cpp.

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

3021 {
3022  CStdShareLock ListLock(&ListCSec);
3023  Packet *pPkt = GetPacketFrgm(iNr);
3024  return pPkt ? pPkt->FragmentPresent(iNr - pPkt->GetNr()) : false;
3025 }
friend class Packet
Definition: C4NetIO.h:687
CStdCSecEx ListCSec
Definition: C4NetIO.h:701
Packet * GetPacketFrgm(unsigned int iNr)
Definition: C4NetIO.cpp:3003

Here is the call graph for this function:

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

Definition at line 3014 of file C4NetIO.cpp.

3015 {
3016  CStdShareLock ListLock(&ListCSec);
3017  return pFront && pFront->Complete() ? pFront : nullptr;
3018 }
CStdCSecEx ListCSec
Definition: C4NetIO.h:701
bool Complete() const
Definition: C4NetIO.cpp:2904
C4NetIOUDP::Packet * C4NetIOUDP::PacketList::GetPacket ( unsigned int  iNr)

Definition at line 2992 of file C4NetIO.cpp.

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

2993 {
2994  CStdShareLock ListLock(&ListCSec);
2995  for (Packet *pPkt = pBack; pPkt; pPkt = pPkt->Prev)
2996  if (pPkt->GetNr() == iNr)
2997  return pPkt;
2998  else if (pPkt->GetNr() < iNr)
2999  return nullptr;
3000  return nullptr;
3001 }
friend class Packet
Definition: C4NetIO.h:687
CStdCSecEx ListCSec
Definition: C4NetIO.h:701
Packet * Prev
Definition: C4NetIO.h:685

Here is the caller graph for this function:

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

Definition at line 3003 of file C4NetIO.cpp.

3004 {
3005  CStdShareLock ListLock(&ListCSec);
3006  for (Packet *pPkt = pBack; pPkt; pPkt = pPkt->Prev)
3007  if (pPkt->GetNr() <= iNr && pPkt->GetNr() + pPkt->FragmentCnt() > iNr)
3008  return pPkt;
3009  else if (pPkt->GetNr() < iNr)
3010  return nullptr;
3011  return nullptr;
3012 }
friend class Packet
Definition: C4NetIO.h:687
CStdCSecEx ListCSec
Definition: C4NetIO.h:701
Packet * Prev
Definition: C4NetIO.h:685

Member Data Documentation

unsigned int C4NetIOUDP::PacketList::iMaxPacketCnt
protected

Definition at line 699 of file C4NetIO.h.

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

Definition at line 699 of file C4NetIO.h.

CStdCSecEx C4NetIOUDP::PacketList::ListCSec
protected

Definition at line 701 of file C4NetIO.h.

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

Definition at line 697 of file C4NetIO.h.

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

Definition at line 697 of file C4NetIO.h.


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