OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4Network2IOConnection Class Reference

#include <C4Network2IO.h>

Collaboration diagram for C4Network2IOConnection:
[legend]

Classes

struct  PacketLogEntry
 

Public Member Functions

 C4Network2IOConnection ()
 
 ~C4Network2IOConnection ()
 
C4NetIOgetNetClass () const
 
C4Network2IOProtocol getProtocol () const
 
const C4NetIO::addr_tgetPeerAddr () const
 
const C4NetIO::addr_tgetConnectAddr () const
 
uint32_t getID () const
 
uint32_t getRemoteID () const
 
time_t getTimestamp () const
 
const C4ClientCoregetCCore () const
 
CStdCSecgetCCoreCSec ()
 
int getClientID () const
 
bool isHost () const
 
int getPingTime () const
 
int getLag () const
 
int getIRate () const
 
int getORate () const
 
int getPacketLoss () const
 
const char * getPassword () const
 
bool isConnSent () const
 
uint32_t getInPacketCounter () const
 
uint32_t getOutPacketCounter () const
 
bool isConnecting () const
 
bool isOpen () const
 
bool isHalfAccepted () const
 
bool isAccepted () const
 
bool isClosed () const
 
bool isAutoAccepted () const
 
bool isBroadcastTarget () const
 
bool isFailed () const
 
void SetHalfAccepted ()
 
void SetAccepted ()
 
void SetCCore (const C4ClientCore &nCCore)
 
void ResetAutoAccepted ()
 
void SetConnSent ()
 
bool Connect ()
 
void Close ()
 
bool Send (const C4NetIOPacket &rPkt)
 
void SetBroadcastTarget (bool fSet)
 
void DoStatistics (int iInterval, int *pIRateSum, int *pORateSum)
 
void AddRef ()
 
void DelRef ()
 
bool CreatePostMortem (class C4PacketPostMortem *pPkt)
 

Protected Member Functions

void Set (C4NetIO *pnNetClass, C4Network2IOProtocol eProt, const C4NetIO::addr_t &nPeerAddr, const C4NetIO::addr_t &nConnectAddr, C4Network2IOConnStatus nStatus, const char *szPassword, uint32_t iID)
 
void SetRemoteID (uint32_t iRemoteID)
 
void SetPeerAddr (const C4NetIO::addr_t &nPeerAddr)
 
void OnPing ()
 
void SetPingTime (int iPingTime)
 
void SetStatus (C4Network2IOConnStatus nStatus)
 
void SetAutoAccepted ()
 
void OnPacketReceived (uint8_t iPacketType)
 
void ClearPacketLog (uint32_t iStartNumber=~0)
 

Protected Attributes

class C4NetIOpNetClass
 
C4Network2IOProtocol eProt
 
C4NetIO::addr_t PeerAddr
 
C4NetIO::addr_t ConnectAddr
 
C4Network2IOConnStatus Status
 
uint32_t iID
 
uint32_t iRemoteID
 
bool fAutoAccept
 
bool fBroadcastTarget
 
time_t iTimestamp
 
int iPingTime
 
C4TimeMilliseconds tLastPing
 
C4TimeMilliseconds tLastPong
 
C4ClientCore CCore
 
CStdCSec CCoreCSec
 
int iIRate
 
int iORate
 
int iPacketLoss
 
StdCopyStrBuf Password
 
bool fConnSent
 
bool fPostMortemSent
 
uint32_t iOutPacketCounter
 
uint32_t iInPacketCounter
 
PacketLogEntrypPacketLog
 
CStdCSec PacketLogCSec
 
C4Network2IOConnectionpNext
 
std::atomic_long iRefCnt
 

Friends

class C4Network2IO
 

Detailed Description

Definition at line 213 of file C4Network2IO.h.


Class Documentation

struct C4Network2IOConnection::PacketLogEntry

Definition at line 246 of file C4Network2IO.h.

Collaboration diagram for C4Network2IOConnection::PacketLogEntry:
[legend]
Class Members
PacketLogEntry * Next
uint32_t Number
C4NetIOPacket Pkt

Constructor & Destructor Documentation

C4Network2IOConnection::C4Network2IOConnection ( )

Definition at line 1295 of file C4Network2IO.cpp.

1296  : pNetClass(nullptr),
1297  iID(~0), iRemoteID(~0),
1298  fAutoAccept(false),
1299  fBroadcastTarget(false),
1300  iTimestamp(0),
1301  iPingTime(-1),
1304  fConnSent(false),
1305  fPostMortemSent(false),
1307  pPacketLog(nullptr),
1308  pNext(nullptr),
1309  iRefCnt(0)
1310 {
1311 }
C4Network2IOConnection * pNext
Definition: C4Network2IO.h:256
class C4NetIO * pNetClass
Definition: C4Network2IO.h:223
std::atomic_long iRefCnt
Definition: C4Network2IO.h:259
C4TimeMilliseconds tLastPing
Definition: C4Network2IO.h:234
PacketLogEntry * pPacketLog
Definition: C4Network2IO.h:252
C4TimeMilliseconds tLastPong
Definition: C4Network2IO.h:235
C4Network2IOConnection::~C4Network2IOConnection ( )

Definition at line 1313 of file C4Network2IO.cpp.

References ClearPacketLog(), Close(), iRefCnt, isClosed(), and pNetClass.

1314 {
1315  assert(!iRefCnt);
1316  // connection needs to be closed?
1317  if (pNetClass && !isClosed()) Close();
1318  // clear the packet log
1319  ClearPacketLog();
1320 }
class C4NetIO * pNetClass
Definition: C4Network2IO.h:223
std::atomic_long iRefCnt
Definition: C4Network2IO.h:259
bool isClosed() const
Definition: C4Network2IO.h:288
void ClearPacketLog(uint32_t iStartNumber=~0)

Here is the call graph for this function:

Member Function Documentation

void C4Network2IOConnection::AddRef ( )

Definition at line 1540 of file C4Network2IO.cpp.

References iRefCnt.

Referenced by C4Network2IO::AddConnection(), C4Network2IO::GetDataConnection(), C4Network2IO::GetMsgConnection(), C4Network2IO::HandlePacket(), C4Network2IO::OnDisconn(), C4Network2Client::SetDataConn(), and C4Network2Client::SetMsgConn().

1541 {
1542  ++iRefCnt;
1543 }
std::atomic_long iRefCnt
Definition: C4Network2IO.h:259

Here is the caller graph for this function:

void C4Network2IOConnection::ClearPacketLog ( uint32_t  iStartNumber = ~0)
protected

Definition at line 1407 of file C4Network2IO.cpp.

References C4Network2IOConnection::PacketLogEntry::Next, and pPacketLog.

Referenced by C4Network2IO::HandlePacket(), and ~C4Network2IOConnection().

1408 {
1409  // Search position of first packet to delete
1410  PacketLogEntry *pPos, *pPrev = nullptr;
1411  for (pPos = pPacketLog; pPos; pPrev = pPos, pPos = pPos->Next)
1412  if (pPos->Number < iUntilID)
1413  break;
1414  if (pPos)
1415  {
1416  // Remove packets from list
1417  (pPrev ? pPrev->Next : pPacketLog) = nullptr;
1418  // Delete everything
1419  while (pPos)
1420  {
1421  PacketLogEntry *pDelete = pPos;
1422  pPos = pPos->Next;
1423  delete pDelete;
1424  }
1425  }
1426 }
PacketLogEntry * pPacketLog
Definition: C4Network2IO.h:252

Here is the caller graph for this function:

void C4Network2IOConnection::Close ( )

Definition at line 1461 of file C4Network2IO.cpp.

References C4NetIO::Close(), CS_Closed, isClosed(), PeerAddr, pNetClass, and SetStatus().

Referenced by C4Network2Client::CloseConns(), C4Network2::HandleConn(), C4Network2::HandleConnRe(), C4Network2IO::HandlePacket(), C4Network2::HandlePacket(), Send(), C4Network2Client::~C4Network2Client(), and ~C4Network2IOConnection().

1462 {
1463  if (!pNetClass || isClosed()) return;
1464  // set status
1466  // close
1468 }
C4NetIO::addr_t PeerAddr
Definition: C4Network2IO.h:225
class C4NetIO * pNetClass
Definition: C4Network2IO.h:223
virtual bool Close()=0
void SetStatus(C4Network2IOConnStatus nStatus)
bool isClosed() const
Definition: C4Network2IO.h:288

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Network2IOConnection::Connect ( )

Definition at line 1454 of file C4Network2IO.cpp.

References C4NetIO::Connect(), ConnectAddr, and pNetClass.

Referenced by C4Network2IO::Connect().

1455 {
1456  if (!pNetClass) return false;
1457  // try connect
1458  return pNetClass->Connect(ConnectAddr);
1459 }
class C4NetIO * pNetClass
Definition: C4Network2IO.h:223
C4NetIO::addr_t ConnectAddr
Definition: C4Network2IO.h:225
virtual bool Connect(const addr_t &addr)=0

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Network2IOConnection::CreatePostMortem ( class C4PacketPostMortem pPkt)

Definition at line 1428 of file C4Network2IO.cpp.

References C4PacketPostMortem::Add(), fPostMortemSent, iOutPacketCounter, iRemoteID, C4Network2IOConnection::PacketLogEntry::Next, PacketLogCSec, pPacketLog, C4PacketPostMortem::SetConnID(), and C4PacketPostMortem::SetPacketCounter().

Referenced by C4Network2::OnDisconn().

1429 {
1430  // Security
1431  if (!pPkt) return false;
1432  CStdLock PacketLogLock(&PacketLogCSec);
1433  // Nothing to do?
1434  if (!pPacketLog) return false;
1435  // Already created?
1436  if (fPostMortemSent) return false;
1437  // Set connection ID and packet counter
1438  pPkt->SetConnID(iRemoteID);
1439  pPkt->SetPacketCounter(iOutPacketCounter);
1440  // Add packets
1441  for (PacketLogEntry *pEntry = pPacketLog; pEntry; pEntry = pEntry->Next)
1442  pPkt->Add(pEntry->Pkt);
1443  // Okay
1444  fPostMortemSent = true;
1445  return true;
1446 }
PacketLogEntry * pPacketLog
Definition: C4Network2IO.h:252

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Network2IOConnection::DelRef ( )

Definition at line 1545 of file C4Network2IO.cpp.

References iRefCnt.

Referenced by C4Network2IO::BroadcastMsg(), C4Network2IO::HandleFwdReq(), C4Network2IO::HandlePacket(), C4Network2IO::OnThreadEvent(), C4Network2Client::RemoveConn(), C4Network2IO::RemoveConnection(), C4Network2Res::SendChunk(), C4Network2IO::SendMsgToClient(), C4Network2Client::SetDataConn(), C4Network2Client::SetMsgConn(), C4Network2Res::StartLoad(), and C4Network2Client::~C4Network2Client().

1546 {
1547  if (--iRefCnt == 0)
1548  delete this;
1549 }
std::atomic_long iRefCnt
Definition: C4Network2IO.h:259

Here is the caller graph for this function:

void C4Network2IOConnection::DoStatistics ( int  iInterval,
int *  pIRateSum,
int *  pORateSum 
)

Definition at line 1521 of file C4Network2IO.cpp.

References C4NetIO::GetConnStatistic(), iIRate, iORate, iPacketLoss, isOpen(), PeerAddr, and pNetClass.

1522 {
1523  // get C4NetIO statistics
1524  int inIRate, inORate, inLoss;
1525  if (!isOpen() || !pNetClass->GetConnStatistic(PeerAddr, &inIRate, &inORate, &inLoss))
1526  {
1527  iIRate = iORate = iPacketLoss = 0;
1528  return;
1529  }
1530  // normalize
1531  inIRate = inIRate * 1000 / iInterval;
1532  inORate = inORate * 1000 / iInterval;
1533  // set
1534  iIRate = inIRate; iORate = inORate; iPacketLoss = inLoss;
1535  // sum up
1536  if (pIRateSum) *pIRateSum += iIRate;
1537  if (pORateSum) *pORateSum += iORate;
1538 }
C4NetIO::addr_t PeerAddr
Definition: C4Network2IO.h:225
class C4NetIO * pNetClass
Definition: C4Network2IO.h:223
virtual bool GetConnStatistic(const addr_t &addr, int *pIRate, int *pORate, int *pLoss)=0
bool isOpen() const
Definition: C4Network2IO.h:285

Here is the call graph for this function:

const C4ClientCore& C4Network2IOConnection::getCCore ( ) const
inline

Definition at line 269 of file C4Network2IO.h.

References CCore.

269 { return CCore; }
CStdCSec& C4Network2IOConnection::getCCoreCSec ( )
inline

Definition at line 270 of file C4Network2IO.h.

References CCoreCSec.

270 { return CCoreCSec; }
int C4Network2IOConnection::getClientID ( ) const
inline

Definition at line 271 of file C4Network2IO.h.

References C4ClientCore::getID().

Referenced by C4Network2IO::HandleFwdReq(), C4Network2::HandleLobbyPacket(), C4Network2Players::HandlePacket(), C4GameControlNetwork::HandlePacket(), C4Network2::HandlePacket(), C4Network2ResList::HandlePacket(), C4Network2::OnConnectFail(), C4Network2::OnDisconn(), and C4Network2Res::OnStatus().

271 { return CCore.getID(); }
int32_t getID() const
Definition: C4Client.h:57

Here is the call graph for this function:

Here is the caller graph for this function:

const C4NetIO::addr_t& C4Network2IOConnection::getConnectAddr ( ) const
inline

Definition at line 265 of file C4Network2IO.h.

References ConnectAddr.

Referenced by C4Network2::HandleConnRe().

265 { return ConnectAddr; }
C4NetIO::addr_t ConnectAddr
Definition: C4Network2IO.h:225

Here is the caller graph for this function:

uint32_t C4Network2IOConnection::getID ( ) const
inline

Definition at line 266 of file C4Network2IO.h.

References iID.

266 { return iID; }
uint32_t C4Network2IOConnection::getInPacketCounter ( ) const
inline

Definition at line 281 of file C4Network2IO.h.

References iInPacketCounter.

Referenced by C4Network2IO::HandlePacket().

281 { return iInPacketCounter; }

Here is the caller graph for this function:

int C4Network2IOConnection::getIRate ( ) const
inline

Definition at line 275 of file C4Network2IO.h.

References iIRate.

275 { return iIRate; }
int C4Network2IOConnection::getLag ( ) const

Definition at line 1322 of file C4Network2IO.cpp.

References iPingTime, C4TimeMilliseconds::Now(), tLastPing, and tLastPong.

Referenced by C4Network2Stats::ExecuteSecond().

1323 {
1324  if (iPingTime != -1)
1325  {
1326  // Last ping not answered yet?
1327  if(tLastPing > tLastPong)
1328  {
1329  int iPingLag = C4TimeMilliseconds::Now() - tLastPing;
1330  // Use it for lag measurement once it's larger then the last ping time
1331  // (the ping time won't be better than this anyway once the pong's here)
1332  return std::max(iPingLag, iPingTime);
1333  }
1334  }
1335  // Last ping result
1336  return iPingTime;
1337 }
C4TimeMilliseconds tLastPing
Definition: C4Network2IO.h:234
C4TimeMilliseconds tLastPong
Definition: C4Network2IO.h:235
static C4TimeMilliseconds Now()

Here is the call graph for this function:

Here is the caller graph for this function:

C4NetIO* C4Network2IOConnection::getNetClass ( ) const
inline

Definition at line 262 of file C4Network2IO.h.

References pNetClass.

Referenced by C4Network2::HandleConnRe(), C4Network2::OnConnect(), C4Network2::OnConnectFail(), C4Network2::OnDisconnect(), and C4Network2ClientDlg::UpdateText().

262 { return pNetClass; }
class C4NetIO * pNetClass
Definition: C4Network2IO.h:223

Here is the caller graph for this function:

int C4Network2IOConnection::getORate ( ) const
inline

Definition at line 276 of file C4Network2IO.h.

References iORate.

276 { return iORate; }
uint32_t C4Network2IOConnection::getOutPacketCounter ( ) const
inline

Definition at line 282 of file C4Network2IO.h.

References iOutPacketCounter.

Referenced by C4Network2::OnDisconn().

282 { return iOutPacketCounter; }

Here is the caller graph for this function:

int C4Network2IOConnection::getPacketLoss ( ) const
inline

Definition at line 277 of file C4Network2IO.h.

References iPacketLoss.

277 { return iPacketLoss; }
const char* C4Network2IOConnection::getPassword ( ) const
inline

Definition at line 278 of file C4Network2IO.h.

References StdStrBuf::getData().

278 { return Password.getData(); }
const char * getData() const
Definition: StdBuf.h:450
StdCopyStrBuf Password
Definition: C4Network2IO.h:240

Here is the call graph for this function:

const C4NetIO::addr_t& C4Network2IOConnection::getPeerAddr ( ) const
inline

Definition at line 264 of file C4Network2IO.h.

References ConnectAddr, and C4NetIO::EndpointAddress::GetPort().

Referenced by C4Network2IO::doAutoAccept(), C4Network2::HandleConn(), C4Network2::HandleConnRe(), C4Network2IO::HandleFwdReq(), C4Network2ClientList::HandlePacket(), C4Network2IO::HandlePacket(), C4Network2::OnConnect(), C4Network2::OnConnectFail(), C4Network2::OnDisconnect(), C4Network2Client::SendAddresses(), and C4Network2ClientDlg::UpdateText().

264 { return PeerAddr.GetPort() ? PeerAddr : ConnectAddr; }
C4NetIO::addr_t PeerAddr
Definition: C4Network2IO.h:225
C4NetIO::addr_t ConnectAddr
Definition: C4Network2IO.h:225
uint16_t GetPort() const
Definition: C4NetIO.cpp:548

Here is the call graph for this function:

Here is the caller graph for this function:

int C4Network2IOConnection::getPingTime ( ) const
inline

Definition at line 273 of file C4Network2IO.h.

References iPingTime.

Referenced by C4GameControlNetwork::CalcPerformance(), C4Network2::HandleActivateReq(), and C4Network2ClientDlg::UpdateText().

273 { return iPingTime; }

Here is the caller graph for this function:

C4Network2IOProtocol C4Network2IOConnection::getProtocol ( ) const
inline

Definition at line 263 of file C4Network2IO.h.

References eProt.

Referenced by C4Network2Client::DoConnectAttempt(), and C4Network2::HandleConnRe().

263 { return eProt; }
C4Network2IOProtocol eProt
Definition: C4Network2IO.h:224

Here is the caller graph for this function:

uint32_t C4Network2IOConnection::getRemoteID ( ) const
inline

Definition at line 267 of file C4Network2IO.h.

References iRemoteID.

267 { return iRemoteID; }
time_t C4Network2IOConnection::getTimestamp ( ) const
inline

Definition at line 268 of file C4Network2IO.h.

References iTimestamp.

268 { return iTimestamp; }
bool C4Network2IOConnection::isAccepted ( ) const
inline

Definition at line 287 of file C4Network2IO.h.

References CS_Accepted.

Referenced by C4Network2::HandleConnRe(), C4Network2IO::HandleFwdReq(), C4GameControlNetwork::HandlePacket(), and C4Network2IO::HandlePacket().

287 { return Status == CS_Accepted; }
C4Network2IOConnStatus Status
Definition: C4Network2IO.h:228

Here is the caller graph for this function:

bool C4Network2IOConnection::isAutoAccepted ( ) const
inline

Definition at line 289 of file C4Network2IO.h.

References fAutoAccept.

Referenced by C4Network2::HandleConnRe(), and C4Network2IO::HandlePacket().

289 { return fAutoAccept; }

Here is the caller graph for this function:

bool C4Network2IOConnection::isBroadcastTarget ( ) const
inline

Definition at line 290 of file C4Network2IO.h.

References fBroadcastTarget.

290 { return fBroadcastTarget; }
bool C4Network2IOConnection::isClosed ( ) const
inline

Definition at line 288 of file C4Network2IO.h.

References CS_Closed, and CS_ConnectFail.

Referenced by Close(), C4Network2::HandleConn(), C4GameControlNetwork::HandlePacket(), C4Network2IO::HandlePacket(), C4Network2IO::OnConn(), C4Network2IO::OnDisconn(), C4Network2IO::OnThreadEvent(), SetStatus(), and ~C4Network2IOConnection().

288 { return Status == CS_Closed || Status == CS_ConnectFail; }
C4Network2IOConnStatus Status
Definition: C4Network2IO.h:228

Here is the caller graph for this function:

bool C4Network2IOConnection::isConnecting ( ) const
inline

Definition at line 284 of file C4Network2IO.h.

References CS_Connect.

Referenced by C4Network2IO::OnDisconn().

284 { return Status == CS_Connect; }
C4Network2IOConnStatus Status
Definition: C4Network2IO.h:228

Here is the caller graph for this function:

bool C4Network2IOConnection::isConnSent ( ) const
inline

Definition at line 279 of file C4Network2IO.h.

References fConnSent.

Referenced by C4Network2IO::HandlePacket().

279 { return fConnSent; }

Here is the caller graph for this function:

bool C4Network2IOConnection::isFailed ( ) const
inline

Definition at line 291 of file C4Network2IO.h.

References CS_ConnectFail.

Referenced by C4Network2::OnDisconn().

291 { return Status == CS_ConnectFail; }
C4Network2IOConnStatus Status
Definition: C4Network2IO.h:228

Here is the caller graph for this function:

bool C4Network2IOConnection::isHalfAccepted ( ) const
inline

Definition at line 286 of file C4Network2IO.h.

References CS_Accepted, and CS_HalfAccepted.

Referenced by C4Network2::HandleConn(), C4Network2IO::HandlePacket(), and C4Network2IO::OnDisconn().

286 { return Status == CS_HalfAccepted || Status == CS_Accepted; }
C4Network2IOConnStatus Status
Definition: C4Network2IO.h:228

Here is the caller graph for this function:

bool C4Network2IOConnection::isHost ( ) const
inline

Definition at line 272 of file C4Network2IO.h.

References C4ClientCore::isHost().

Referenced by C4GameControlNetwork::HandlePacket().

272 { return CCore.isHost(); }
bool isHost() const
Definition: C4Client.h:58

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Network2IOConnection::isOpen ( ) const
inline

Definition at line 285 of file C4Network2IO.h.

References CS_Closed, CS_Connect, and CS_ConnectFail.

Referenced by C4Network2Client::CloseConns(), DoStatistics(), C4Network2::HandleConnRe(), C4Network2IO::HandlePacket(), C4Network2::HandlePacket(), C4Network2ResList::HandlePacket(), C4Network2IO::OnConn(), and Send().

Here is the caller graph for this function:

void C4Network2IOConnection::OnPacketReceived ( uint8_t  iPacketType)
protected

Definition at line 1400 of file C4Network2IO.cpp.

References iInPacketCounter, and PID_PacketLogStart.

Referenced by C4Network2IO::OnPacket().

1401 {
1402  // Just count them
1403  if (iPacketType >= PID_PacketLogStart)
1404  iInPacketCounter++;
1405 }

Here is the caller graph for this function:

void C4Network2IOConnection::OnPing ( )
protected

Definition at line 1363 of file C4Network2IO.cpp.

References C4TimeMilliseconds::Now(), tLastPing, and tLastPong.

1364 {
1365  // Still no pong for the last ping?
1366  if (tLastPong < tLastPing)
1367  return;
1368 
1369  // Save time
1371 }
C4TimeMilliseconds tLastPing
Definition: C4Network2IO.h:234
C4TimeMilliseconds tLastPong
Definition: C4Network2IO.h:235
static C4TimeMilliseconds Now()

Here is the call graph for this function:

void C4Network2IOConnection::ResetAutoAccepted ( )
inline

Definition at line 310 of file C4Network2IO.h.

Referenced by C4Network2::HandleConnRe().

310 { fAutoAccept = false; }

Here is the caller graph for this function:

bool C4Network2IOConnection::Send ( const C4NetIOPacket rPkt)

Definition at line 1470 of file C4Network2IO.cpp.

References Close(), fPostMortemSent, C4NetIO::GetError(), C4NetIOPacket::getStatus(), iOutPacketCounter, isOpen(), LogF(), C4Network2IOConnection::PacketLogEntry::Next, C4Network2IOConnection::PacketLogEntry::Number, PacketLogCSec, PeerAddr, PID_PacketLogStart, C4Network2IOConnection::PacketLogEntry::Pkt, pNetClass, pPacketLog, C4NetIO::ResetError(), C4NetIO::Send(), and C4NetIOPacket::SetAddr().

Referenced by C4Network2Client::CloseConns(), C4Network2::HandleConn(), C4GameControlNetwork::HandleControlReq(), C4Network2IO::HandleFwdReq(), C4Network2IO::HandlePacket(), C4Network2Client::SendAddresses(), C4Network2Res::SendChunk(), C4Network2Client::SendData(), C4Network2ResList::SendDiscover(), C4Network2Client::SendMsg(), C4Network2IO::SendMsgToClient(), C4Network2Res::SendStatus(), and C4Network2Res::StartLoad().

1471 {
1472  // some packets shouldn't go into the log
1473  if (rPkt.getStatus() < PID_PacketLogStart)
1474  {
1475  assert(isOpen());
1476  C4NetIOPacket Copy(rPkt);
1477  Copy.SetAddr(PeerAddr);
1478  return pNetClass->Send(Copy);
1479  }
1480  CStdLock PacketLogLock(&PacketLogCSec);
1481  // create log entry
1482  PacketLogEntry *pLogEntry = new PacketLogEntry();
1483  pLogEntry->Number = iOutPacketCounter++;
1484  pLogEntry->Pkt = rPkt;
1485  pLogEntry->Next = pPacketLog;
1486  pPacketLog = pLogEntry;
1487  // set address
1488  pLogEntry->Pkt.SetAddr(PeerAddr);
1489  // closed? No sweat, post mortem will reroute it later.
1490  if (!isOpen())
1491  {
1492  // post mortem already sent? This shouldn't happen
1493  if (fPostMortemSent) { assert(false); return false; }
1494  // okay then
1495  return true;
1496  }
1497  // send
1498  bool fSuccess = pNetClass->Send(pLogEntry->Pkt);
1499  if (fSuccess)
1500  assert(!fPostMortemSent);
1501  else {
1502  // Not being able to send a packet is actually a big deal,
1503  // as this means that we will have hole in the packet
1504  // order. Better close the connection - post mortem should
1505  // ideally sort everything out from here.
1506  LogF("Network: Fatal: Send failed (%s)", pNetClass->GetError());
1507  pNetClass->ResetError();
1508  Close();
1509  }
1510  return fSuccess;
1511 }
void ResetError()
Definition: C4NetIO.h:286
virtual const char * GetError() const
Definition: C4NetIO.h:285
C4NetIO::addr_t PeerAddr
Definition: C4Network2IO.h:225
class C4NetIO * pNetClass
Definition: C4Network2IO.h:223
virtual bool Send(const class C4NetIOPacket &rPacket)=0
PacketLogEntry * pPacketLog
Definition: C4Network2IO.h:252
uint8_t getStatus() const
Definition: C4NetIO.h:318
bool LogF(const char *strMessage,...)
Definition: C4Log.cpp:253
void SetAddr(const C4NetIO::addr_t &naddr)
Definition: C4NetIO.h:327
bool isOpen() const
Definition: C4Network2IO.h:285

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Network2IOConnection::Set ( C4NetIO pnNetClass,
C4Network2IOProtocol  eProt,
const C4NetIO::addr_t nPeerAddr,
const C4NetIO::addr_t nConnectAddr,
C4Network2IOConnStatus  nStatus,
const char *  szPassword,
uint32_t  iID 
)
protected

Definition at line 1339 of file C4Network2IO.cpp.

References ConnectAddr, eProt, fBroadcastTarget, iID, iPingTime, iTimestamp, Password, PeerAddr, pNetClass, and Status.

Referenced by C4Network2IO::Connect(), and C4Network2IO::OnConn().

1340 {
1341  // save data
1342  pNetClass = pnNetClass; eProt = enProt;
1343  PeerAddr = nPeerAddr; ConnectAddr = nConnectAddr;
1344  Status = nStatus;
1345  Password = szPassword;
1346  iID = inID;
1347  // initialize
1348  fBroadcastTarget = false;
1349  iTimestamp = time(nullptr); iPingTime = -1;
1350 }
C4Network2IOProtocol eProt
Definition: C4Network2IO.h:224
C4NetIO::addr_t PeerAddr
Definition: C4Network2IO.h:225
class C4NetIO * pNetClass
Definition: C4Network2IO.h:223
StdCopyStrBuf Password
Definition: C4Network2IO.h:240
C4Network2IOConnStatus Status
Definition: C4Network2IO.h:228
C4NetIO::addr_t ConnectAddr
Definition: C4Network2IO.h:225

Here is the caller graph for this function:

void C4Network2IOConnection::SetAccepted ( )
inline

Definition at line 308 of file C4Network2IO.h.

References CS_Accepted, and SetStatus().

Referenced by C4Network2::HandleConnRe(), and C4Network2IO::HandlePacket().

void SetStatus(C4Network2IOConnStatus nStatus)

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Network2IOConnection::SetAutoAccepted ( )
protected

Definition at line 1395 of file C4Network2IO.cpp.

References fAutoAccept.

Referenced by C4Network2IO::HandlePacket().

1396 {
1397  fAutoAccept = true;
1398 }

Here is the caller graph for this function:

void C4Network2IOConnection::SetBroadcastTarget ( bool  fSet)

Definition at line 1513 of file C4Network2IO.cpp.

References fBroadcastTarget, PeerAddr, pNetClass, and C4NetIO::SetBroadcast().

Referenced by C4Network2IO::BroadcastMsg(), and C4Network2IO::HandleFwdReq().

1514 {
1515  // Note that each thread will have to make sure that this flag won't be
1516  // changed until Broadcast() is called. See C4Network2IO::BroadcastCSec.
1518  fBroadcastTarget = fSet;
1519 }
C4NetIO::addr_t PeerAddr
Definition: C4Network2IO.h:225
class C4NetIO * pNetClass
Definition: C4Network2IO.h:223
virtual bool SetBroadcast(const addr_t &addr, bool fSet=true)=0

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Network2IOConnection::SetCCore ( const C4ClientCore nCCore)

Definition at line 1448 of file C4Network2IO.cpp.

References CCore, and CCoreCSec.

Referenced by C4Network2IO::Connect(), C4Network2::HandleConn(), C4Network2::HandleConnRe(), and C4Network2IO::HandlePacket().

1449 {
1450  CStdLock CCoreLock(&CCoreCSec);
1451  CCore = nCCore;
1452 }

Here is the caller graph for this function:

void C4Network2IOConnection::SetConnSent ( )
inline

Definition at line 311 of file C4Network2IO.h.

311 { fConnSent = true; }
void C4Network2IOConnection::SetHalfAccepted ( )
inline

Definition at line 307 of file C4Network2IO.h.

References CS_HalfAccepted, and SetStatus().

Referenced by C4Network2::HandleConn().

void SetStatus(C4Network2IOConnStatus nStatus)

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Network2IOConnection::SetPeerAddr ( const C4NetIO::addr_t nPeerAddr)
protected

Definition at line 1357 of file C4Network2IO.cpp.

References PeerAddr.

Referenced by C4Network2IO::OnConn().

1358 {
1359  // just do it
1360  PeerAddr = nPeerAddr;
1361 }
C4NetIO::addr_t PeerAddr
Definition: C4Network2IO.h:225

Here is the caller graph for this function:

void C4Network2IOConnection::SetPingTime ( int  iPingTime)
protected

Definition at line 1373 of file C4Network2IO.cpp.

References iPingTime, C4TimeMilliseconds::Now(), and tLastPong.

Referenced by C4Network2IO::HandlePacket().

1374 {
1375  // save it
1376  iPingTime = inPingTime;
1377  // pong received - save timestamp
1379 }
C4TimeMilliseconds tLastPong
Definition: C4Network2IO.h:235
static C4TimeMilliseconds Now()

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Network2IOConnection::SetRemoteID ( uint32_t  iRemoteID)
protected

Definition at line 1352 of file C4Network2IO.cpp.

References iRemoteID.

Referenced by C4Network2IO::HandlePacket().

1353 {
1354  iRemoteID = inRemoteID;
1355 }

Here is the caller graph for this function:

void C4Network2IOConnection::SetStatus ( C4Network2IOConnStatus  nStatus)
protected

Definition at line 1381 of file C4Network2IO.cpp.

References CS_Accepted, CS_Closed, CS_Connect, CS_Connected, isClosed(), iTimestamp, and Status.

Referenced by Close(), C4Network2IO::HandlePacket(), C4Network2IO::OnConn(), C4Network2IO::OnDisconn(), SetAccepted(), and SetHalfAccepted().

1382 {
1383  if (nStatus != Status)
1384  {
1385  // Connection can't return from these
1386  assert(!isClosed());
1387  // set status
1388  Status = nStatus;
1389  // reset timestamp for connect/accept/close
1391  iTimestamp = time(nullptr);
1392  }
1393 }
C4Network2IOConnStatus Status
Definition: C4Network2IO.h:228
bool isClosed() const
Definition: C4Network2IO.h:288

Here is the call graph for this function:

Here is the caller graph for this function:

Friends And Related Function Documentation

friend class C4Network2IO
friend

Definition at line 215 of file C4Network2IO.h.

Member Data Documentation

C4ClientCore C4Network2IOConnection::CCore
protected

Definition at line 236 of file C4Network2IO.h.

Referenced by getCCore(), and SetCCore().

CStdCSec C4Network2IOConnection::CCoreCSec
protected

Definition at line 237 of file C4Network2IO.h.

Referenced by getCCoreCSec(), and SetCCore().

C4NetIO::addr_t C4Network2IOConnection::ConnectAddr
protected

Definition at line 225 of file C4Network2IO.h.

Referenced by Connect(), getConnectAddr(), getPeerAddr(), and Set().

C4Network2IOProtocol C4Network2IOConnection::eProt
protected

Definition at line 224 of file C4Network2IO.h.

Referenced by getProtocol(), and Set().

bool C4Network2IOConnection::fAutoAccept
protected

Definition at line 230 of file C4Network2IO.h.

Referenced by isAutoAccepted(), and SetAutoAccepted().

bool C4Network2IOConnection::fBroadcastTarget
protected

Definition at line 231 of file C4Network2IO.h.

Referenced by isBroadcastTarget(), Set(), and SetBroadcastTarget().

bool C4Network2IOConnection::fConnSent
protected

Definition at line 241 of file C4Network2IO.h.

Referenced by isConnSent().

bool C4Network2IOConnection::fPostMortemSent
protected

Definition at line 242 of file C4Network2IO.h.

Referenced by CreatePostMortem(), and Send().

uint32_t C4Network2IOConnection::iID
protected

Definition at line 229 of file C4Network2IO.h.

Referenced by getID(), and Set().

uint32_t C4Network2IOConnection::iInPacketCounter
protected

Definition at line 245 of file C4Network2IO.h.

Referenced by getInPacketCounter(), and OnPacketReceived().

int C4Network2IOConnection::iIRate
protected

Definition at line 238 of file C4Network2IO.h.

Referenced by DoStatistics(), and getIRate().

int C4Network2IOConnection::iORate
protected

Definition at line 238 of file C4Network2IO.h.

Referenced by DoStatistics(), and getORate().

uint32_t C4Network2IOConnection::iOutPacketCounter
protected

Definition at line 245 of file C4Network2IO.h.

Referenced by CreatePostMortem(), getOutPacketCounter(), and Send().

int C4Network2IOConnection::iPacketLoss
protected

Definition at line 239 of file C4Network2IO.h.

Referenced by DoStatistics(), and getPacketLoss().

int C4Network2IOConnection::iPingTime
protected

Definition at line 233 of file C4Network2IO.h.

Referenced by getLag(), getPingTime(), Set(), and SetPingTime().

std::atomic_long C4Network2IOConnection::iRefCnt
protected

Definition at line 259 of file C4Network2IO.h.

Referenced by AddRef(), DelRef(), and ~C4Network2IOConnection().

uint32_t C4Network2IOConnection::iRemoteID
protected

Definition at line 229 of file C4Network2IO.h.

Referenced by CreatePostMortem(), getRemoteID(), and SetRemoteID().

time_t C4Network2IOConnection::iTimestamp
protected

Definition at line 232 of file C4Network2IO.h.

Referenced by getTimestamp(), Set(), and SetStatus().

CStdCSec C4Network2IOConnection::PacketLogCSec
protected

Definition at line 253 of file C4Network2IO.h.

Referenced by CreatePostMortem(), and Send().

StdCopyStrBuf C4Network2IOConnection::Password
protected

Definition at line 240 of file C4Network2IO.h.

Referenced by Set().

C4NetIO::addr_t C4Network2IOConnection::PeerAddr
protected

Definition at line 225 of file C4Network2IO.h.

Referenced by Close(), DoStatistics(), Send(), Set(), SetBroadcastTarget(), and SetPeerAddr().

class C4NetIO* C4Network2IOConnection::pNetClass
protected
PacketLogEntry* C4Network2IOConnection::pPacketLog
protected

Definition at line 252 of file C4Network2IO.h.

Referenced by ClearPacketLog(), CreatePostMortem(), and Send().

C4Network2IOConnStatus C4Network2IOConnection::Status
protected

Definition at line 228 of file C4Network2IO.h.

Referenced by Set(), and SetStatus().

C4TimeMilliseconds C4Network2IOConnection::tLastPing
protected

Definition at line 234 of file C4Network2IO.h.

Referenced by getLag(), and OnPing().

C4TimeMilliseconds C4Network2IOConnection::tLastPong
protected

Definition at line 235 of file C4Network2IO.h.

Referenced by getLag(), OnPing(), and SetPingTime().


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