OpenClonk
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 SetSocket (std::unique_ptr< C4NetIOTCP::Socket > socket)
 
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 {nullptr}
 
C4Network2IOProtocol eProt
 
C4NetIO::addr_t PeerAddr
 
C4NetIO::addr_t ConnectAddr
 
std::unique_ptr< C4NetIOTCP::SocketTcpSimOpenSocket
 
C4Network2IOConnStatus Status
 
uint32_t iID
 
uint32_t iRemoteID
 
bool fAutoAccept {false}
 
bool fBroadcastTarget {false}
 
time_t iTimestamp {0}
 
int iPingTime {-1}
 
C4TimeMilliseconds tLastPing
 
C4TimeMilliseconds tLastPong
 
C4ClientCore CCore
 
CStdCSec CCoreCSec
 
int iIRate
 
int iORate
 
int iPacketLoss
 
StdCopyStrBuf Password
 
bool fConnSent {false}
 
bool fPostMortemSent {false}
 
uint32_t iOutPacketCounter {0}
 
uint32_t iInPacketCounter {0}
 
PacketLogEntrypPacketLog {nullptr}
 
CStdCSec PacketLogCSec
 
C4Network2IOConnectionpNext {nullptr}
 
std::atomic_long iRefCnt
 

Friends

class C4Network2IO
 

Detailed Description

Definition at line 214 of file C4Network2IO.h.


Class Documentation

◆ C4Network2IOConnection::PacketLogEntry

struct C4Network2IOConnection::PacketLogEntry

Definition at line 248 of file C4Network2IO.h.

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

Constructor & Destructor Documentation

◆ C4Network2IOConnection()

C4Network2IOConnection::C4Network2IOConnection ( )

Definition at line 1291 of file C4Network2IO.cpp.

1292  : iID(~0), iRemoteID(~0),
1293 
1296 
1297  iRefCnt(0)
1298 {
1299 }
C4TimeMilliseconds tLastPong
Definition: C4Network2IO.h:237
C4TimeMilliseconds tLastPing
Definition: C4Network2IO.h:236
std::atomic_long iRefCnt
Definition: C4Network2IO.h:261

◆ ~C4Network2IOConnection()

C4Network2IOConnection::~C4Network2IOConnection ( )

Definition at line 1301 of file C4Network2IO.cpp.

1302 {
1303  assert(!iRefCnt);
1304  // connection needs to be closed?
1305  if (pNetClass && !isClosed()) Close();
1306  // clear the packet log
1307  ClearPacketLog();
1308 }
void ClearPacketLog(uint32_t iStartNumber=~0)
class C4NetIO * pNetClass
Definition: C4Network2IO.h:224

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

Here is the call graph for this function:

Member Function Documentation

◆ AddRef()

void C4Network2IOConnection::AddRef ( )

Definition at line 1538 of file C4Network2IO.cpp.

1539 {
1540  ++iRefCnt;
1541 }

References iRefCnt.

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

Here is the caller graph for this function:

◆ ClearPacketLog()

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

Definition at line 1400 of file C4Network2IO.cpp.

1401 {
1402  // Search position of first packet to delete
1403  PacketLogEntry *pPos, *pPrev = nullptr;
1404  for (pPos = pPacketLog; pPos; pPrev = pPos, pPos = pPos->Next)
1405  if (pPos->Number < iUntilID)
1406  break;
1407  if (pPos)
1408  {
1409  // Remove packets from list
1410  (pPrev ? pPrev->Next : pPacketLog) = nullptr;
1411  // Delete everything
1412  while (pPos)
1413  {
1414  PacketLogEntry *pDelete = pPos;
1415  pPos = pPos->Next;
1416  delete pDelete;
1417  }
1418  }
1419 }
PacketLogEntry * pPacketLog
Definition: C4Network2IO.h:254

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

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

Here is the caller graph for this function:

◆ Close()

void C4Network2IOConnection::Close ( )

Definition at line 1459 of file C4Network2IO.cpp.

1460 {
1461  if (!pNetClass || isClosed()) return;
1462  // set status
1464  // close
1466 }
@ CS_Closed
Definition: C4Network2IO.h:210
virtual bool Close()=0
C4NetIO::addr_t PeerAddr
Definition: C4Network2IO.h:226
void SetStatus(C4Network2IOConnStatus nStatus)

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

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Connect()

bool C4Network2IOConnection::Connect ( )

Definition at line 1447 of file C4Network2IO.cpp.

1448 {
1449  if (!pNetClass) return false;
1450  if (TcpSimOpenSocket)
1451  {
1452  auto pNetTCP = dynamic_cast<C4NetIOTCP*>(pNetClass);
1453  return pNetTCP->Connect(ConnectAddr, std::move(TcpSimOpenSocket));
1454  }
1455  // try connect
1456  return pNetClass->Connect(ConnectAddr);
1457 }
virtual bool Connect(const addr_t &addr)=0
bool Connect(const addr_t &addr, std::unique_ptr< Socket > socket)
Definition: C4NetIO.cpp:1207
C4NetIO::addr_t ConnectAddr
Definition: C4Network2IO.h:226
std::unique_ptr< C4NetIOTCP::Socket > TcpSimOpenSocket
Definition: C4Network2IO.h:227

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

Referenced by C4Network2IO::ConnectWithSocket().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CreatePostMortem()

bool C4Network2IOConnection::CreatePostMortem ( class C4PacketPostMortem pPkt)

Definition at line 1421 of file C4Network2IO.cpp.

1422 {
1423  // Security
1424  if (!pPkt) return false;
1425  CStdLock PacketLogLock(&PacketLogCSec);
1426  // Nothing to do?
1427  if (!pPacketLog) return false;
1428  // Already created?
1429  if (fPostMortemSent) return false;
1430  // Set connection ID and packet counter
1431  pPkt->SetConnID(iRemoteID);
1432  pPkt->SetPacketCounter(iOutPacketCounter);
1433  // Add packets
1434  for (PacketLogEntry *pEntry = pPacketLog; pEntry; pEntry = pEntry->Next)
1435  pPkt->Add(pEntry->Pkt);
1436  // Okay
1437  fPostMortemSent = true;
1438  return true;
1439 }

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

Referenced by C4Network2::OnDisconn().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DelRef()

void C4Network2IOConnection::DelRef ( )

Definition at line 1543 of file C4Network2IO.cpp.

1544 {
1545  if (--iRefCnt == 0)
1546  delete this;
1547 }

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().

Here is the caller graph for this function:

◆ DoStatistics()

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

Definition at line 1519 of file C4Network2IO.cpp.

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

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

Here is the call graph for this function:

◆ getCCore()

const C4ClientCore& C4Network2IOConnection::getCCore ( ) const
inline

Definition at line 271 of file C4Network2IO.h.

271 { return CCore; }

References CCore.

◆ getCCoreCSec()

CStdCSec& C4Network2IOConnection::getCCoreCSec ( )
inline

Definition at line 272 of file C4Network2IO.h.

272 { return CCoreCSec; }

References CCoreCSec.

◆ getClientID()

int C4Network2IOConnection::getClientID ( ) const
inline

Definition at line 273 of file C4Network2IO.h.

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

References CCore, and C4ClientCore::getID().

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getConnectAddr()

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

Definition at line 267 of file C4Network2IO.h.

267 { return ConnectAddr; }

References ConnectAddr.

Referenced by C4Network2::HandleConnRe().

Here is the caller graph for this function:

◆ getID()

uint32_t C4Network2IOConnection::getID ( ) const
inline

Definition at line 268 of file C4Network2IO.h.

268 { return iID; }

References iID.

◆ getInPacketCounter()

uint32_t C4Network2IOConnection::getInPacketCounter ( ) const
inline

Definition at line 283 of file C4Network2IO.h.

283 { return iInPacketCounter; }

References iInPacketCounter.

Referenced by C4Network2IO::HandlePacket().

Here is the caller graph for this function:

◆ getIRate()

int C4Network2IOConnection::getIRate ( ) const
inline

Definition at line 277 of file C4Network2IO.h.

277 { return iIRate; }

References iIRate.

◆ getLag()

int C4Network2IOConnection::getLag ( ) const

Definition at line 1310 of file C4Network2IO.cpp.

1311 {
1312  if (iPingTime != -1)
1313  {
1314  // Last ping not answered yet?
1315  if(tLastPing > tLastPong)
1316  {
1317  int iPingLag = C4TimeMilliseconds::Now() - tLastPing;
1318  // Use it for lag measurement once it's larger then the last ping time
1319  // (the ping time won't be better than this anyway once the pong's here)
1320  return std::max(iPingLag, iPingTime);
1321  }
1322  }
1323  // Last ping result
1324  return iPingTime;
1325 }
static C4TimeMilliseconds Now()

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

Referenced by C4Network2Client::DoTCPSimultaneousOpen(), and C4Network2Stats::ExecuteSecond().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getNetClass()

C4NetIO* C4Network2IOConnection::getNetClass ( ) const
inline

Definition at line 264 of file C4Network2IO.h.

264 { return pNetClass; }

References pNetClass.

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

Here is the caller graph for this function:

◆ getORate()

int C4Network2IOConnection::getORate ( ) const
inline

Definition at line 278 of file C4Network2IO.h.

278 { return iORate; }

References iORate.

◆ getOutPacketCounter()

uint32_t C4Network2IOConnection::getOutPacketCounter ( ) const
inline

Definition at line 284 of file C4Network2IO.h.

284 { return iOutPacketCounter; }

References iOutPacketCounter.

Referenced by C4Network2::OnDisconn().

Here is the caller graph for this function:

◆ getPacketLoss()

int C4Network2IOConnection::getPacketLoss ( ) const
inline

Definition at line 279 of file C4Network2IO.h.

279 { return iPacketLoss; }

References iPacketLoss.

◆ getPassword()

const char* C4Network2IOConnection::getPassword ( ) const
inline

Definition at line 280 of file C4Network2IO.h.

280 { return Password.getData(); }
StdCopyStrBuf Password
Definition: C4Network2IO.h:242
const char * getData() const
Definition: StdBuf.h:442

References StdStrBuf::getData(), and Password.

Here is the call graph for this function:

◆ getPeerAddr()

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

Definition at line 266 of file C4Network2IO.h.

266 { return PeerAddr.GetPort() ? PeerAddr : ConnectAddr; }
uint16_t GetPort() const
Definition: C4NetIO.cpp:547

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

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getPingTime()

int C4Network2IOConnection::getPingTime ( ) const
inline

Definition at line 275 of file C4Network2IO.h.

275 { return iPingTime; }

References iPingTime.

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

Here is the caller graph for this function:

◆ getProtocol()

C4Network2IOProtocol C4Network2IOConnection::getProtocol ( ) const
inline

Definition at line 265 of file C4Network2IO.h.

265 { return eProt; }
C4Network2IOProtocol eProt
Definition: C4Network2IO.h:225

References eProt.

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

Here is the caller graph for this function:

◆ getRemoteID()

uint32_t C4Network2IOConnection::getRemoteID ( ) const
inline

Definition at line 269 of file C4Network2IO.h.

269 { return iRemoteID; }

References iRemoteID.

◆ getTimestamp()

time_t C4Network2IOConnection::getTimestamp ( ) const
inline

Definition at line 270 of file C4Network2IO.h.

270 { return iTimestamp; }

References iTimestamp.

◆ isAccepted()

bool C4Network2IOConnection::isAccepted ( ) const
inline

Definition at line 289 of file C4Network2IO.h.

289 { return Status == CS_Accepted; }
@ CS_Accepted
Definition: C4Network2IO.h:209
C4Network2IOConnStatus Status
Definition: C4Network2IO.h:230

References CS_Accepted, and Status.

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

Here is the caller graph for this function:

◆ isAutoAccepted()

bool C4Network2IOConnection::isAutoAccepted ( ) const
inline

Definition at line 291 of file C4Network2IO.h.

291 { return fAutoAccept; }

References fAutoAccept.

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

Here is the caller graph for this function:

◆ isBroadcastTarget()

bool C4Network2IOConnection::isBroadcastTarget ( ) const
inline

Definition at line 292 of file C4Network2IO.h.

292 { return fBroadcastTarget; }

References fBroadcastTarget.

◆ isClosed()

bool C4Network2IOConnection::isClosed ( ) const
inline

Definition at line 290 of file C4Network2IO.h.

290 { return Status == CS_Closed || Status == CS_ConnectFail; }
@ CS_ConnectFail
Definition: C4Network2IO.h:211

References CS_Closed, CS_ConnectFail, and Status.

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

Here is the caller graph for this function:

◆ isConnecting()

bool C4Network2IOConnection::isConnecting ( ) const
inline

Definition at line 286 of file C4Network2IO.h.

286 { return Status == CS_Connect; }
@ CS_Connect
Definition: C4Network2IO.h:206

References CS_Connect, and Status.

Referenced by C4Network2IO::OnDisconn().

Here is the caller graph for this function:

◆ isConnSent()

bool C4Network2IOConnection::isConnSent ( ) const
inline

Definition at line 281 of file C4Network2IO.h.

281 { return fConnSent; }

References fConnSent.

Referenced by C4Network2IO::HandlePacket().

Here is the caller graph for this function:

◆ isFailed()

bool C4Network2IOConnection::isFailed ( ) const
inline

Definition at line 293 of file C4Network2IO.h.

293 { return Status == CS_ConnectFail; }

References CS_ConnectFail, and Status.

Referenced by C4Network2::OnDisconn().

Here is the caller graph for this function:

◆ isHalfAccepted()

bool C4Network2IOConnection::isHalfAccepted ( ) const
inline

Definition at line 288 of file C4Network2IO.h.

288 { return Status == CS_HalfAccepted || Status == CS_Accepted; }
@ CS_HalfAccepted
Definition: C4Network2IO.h:208

References CS_Accepted, CS_HalfAccepted, and Status.

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

Here is the caller graph for this function:

◆ isHost()

bool C4Network2IOConnection::isHost ( ) const
inline

Definition at line 274 of file C4Network2IO.h.

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

References CCore, and C4ClientCore::isHost().

Referenced by C4GameControlNetwork::HandlePacket().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isOpen()

bool C4Network2IOConnection::isOpen ( ) const
inline

Definition at line 287 of file C4Network2IO.h.

287 { return Status != CS_Connect && Status != CS_Closed && Status != CS_ConnectFail; }

References CS_Closed, CS_Connect, CS_ConnectFail, and Status.

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

Here is the caller graph for this function:

◆ OnPacketReceived()

void C4Network2IOConnection::OnPacketReceived ( uint8_t  iPacketType)
protected

Definition at line 1393 of file C4Network2IO.cpp.

1394 {
1395  // Just count them
1396  if (iPacketType >= PID_PacketLogStart)
1397  iInPacketCounter++;
1398 }
@ PID_PacketLogStart
Definition: C4PacketBase.h:99

References iInPacketCounter, and PID_PacketLogStart.

Referenced by C4Network2IO::OnPacket().

Here is the caller graph for this function:

◆ OnPing()

void C4Network2IOConnection::OnPing ( )
protected

Definition at line 1356 of file C4Network2IO.cpp.

1357 {
1358  // Still no pong for the last ping?
1359  if (tLastPong < tLastPing)
1360  return;
1361 
1362  // Save time
1364 }

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

Here is the call graph for this function:

◆ ResetAutoAccepted()

void C4Network2IOConnection::ResetAutoAccepted ( )
inline

Definition at line 313 of file C4Network2IO.h.

313 { fAutoAccept = false; }

References fAutoAccept.

Referenced by C4Network2::HandleConnRe().

Here is the caller graph for this function:

◆ Send()

bool C4Network2IOConnection::Send ( const C4NetIOPacket rPkt)

Definition at line 1468 of file C4Network2IO.cpp.

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

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Set()

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 1327 of file C4Network2IO.cpp.

1328 {
1329  // save data
1330  pNetClass = pnNetClass; eProt = enProt;
1331  PeerAddr = nPeerAddr; ConnectAddr = nConnectAddr;
1332  Status = nStatus;
1333  Password = szPassword;
1334  iID = inID;
1335  // initialize
1336  fBroadcastTarget = false;
1337  iTimestamp = time(nullptr); iPingTime = -1;
1338 }

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

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

Here is the caller graph for this function:

◆ SetAccepted()

void C4Network2IOConnection::SetAccepted ( )
inline

Definition at line 311 of file C4Network2IO.h.

References CS_Accepted, and SetStatus().

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetAutoAccepted()

void C4Network2IOConnection::SetAutoAccepted ( )
protected

Definition at line 1388 of file C4Network2IO.cpp.

1389 {
1390  fAutoAccept = true;
1391 }

References fAutoAccept.

Referenced by C4Network2IO::HandlePacket().

Here is the caller graph for this function:

◆ SetBroadcastTarget()

void C4Network2IOConnection::SetBroadcastTarget ( bool  fSet)

Definition at line 1511 of file C4Network2IO.cpp.

1512 {
1513  // Note that each thread will have to make sure that this flag won't be
1514  // changed until Broadcast() is called. See C4Network2IO::BroadcastCSec.
1516  fBroadcastTarget = fSet;
1517 }
virtual bool SetBroadcast(const addr_t &addr, bool fSet=true)=0

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

Referenced by C4Network2IO::HandleFwdReq().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetCCore()

void C4Network2IOConnection::SetCCore ( const C4ClientCore nCCore)

Definition at line 1441 of file C4Network2IO.cpp.

1442 {
1443  CStdLock CCoreLock(&CCoreCSec);
1444  CCore = nCCore;
1445 }

References CCore, and CCoreCSec.

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

Here is the caller graph for this function:

◆ SetConnSent()

void C4Network2IOConnection::SetConnSent ( )
inline

Definition at line 314 of file C4Network2IO.h.

314 { fConnSent = true; }

References fConnSent.

◆ SetHalfAccepted()

void C4Network2IOConnection::SetHalfAccepted ( )
inline

Definition at line 310 of file C4Network2IO.h.

References CS_HalfAccepted, and SetStatus().

Referenced by C4Network2::HandleConn().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetPeerAddr()

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

Definition at line 1350 of file C4Network2IO.cpp.

1351 {
1352  // just do it
1353  PeerAddr = nPeerAddr;
1354 }

References PeerAddr.

Referenced by C4Network2IO::OnConn().

Here is the caller graph for this function:

◆ SetPingTime()

void C4Network2IOConnection::SetPingTime ( int  iPingTime)
protected

Definition at line 1366 of file C4Network2IO.cpp.

1367 {
1368  // save it
1369  iPingTime = inPingTime;
1370  // pong received - save timestamp
1372 }

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

Referenced by C4Network2IO::HandlePacket().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetRemoteID()

void C4Network2IOConnection::SetRemoteID ( uint32_t  iRemoteID)
protected

Definition at line 1345 of file C4Network2IO.cpp.

1346 {
1347  iRemoteID = inRemoteID;
1348 }

References iRemoteID.

Referenced by C4Network2IO::HandlePacket().

Here is the caller graph for this function:

◆ SetSocket()

void C4Network2IOConnection::SetSocket ( std::unique_ptr< C4NetIOTCP::Socket socket)
protected

Definition at line 1340 of file C4Network2IO.cpp.

1341 {
1342  TcpSimOpenSocket = std::move(socket);
1343 }

References TcpSimOpenSocket.

Referenced by C4Network2IO::ConnectWithSocket().

Here is the caller graph for this function:

◆ SetStatus()

void C4Network2IOConnection::SetStatus ( C4Network2IOConnStatus  nStatus)
protected

Definition at line 1374 of file C4Network2IO.cpp.

1375 {
1376  if (nStatus != Status)
1377  {
1378  // Connection can't return from these
1379  assert(!isClosed());
1380  // set status
1381  Status = nStatus;
1382  // reset timestamp for connect/accept/close
1384  iTimestamp = time(nullptr);
1385  }
1386 }
@ CS_Connected
Definition: C4Network2IO.h:207

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().

Here is the call graph for this function:
Here is the caller graph for this function:

Friends And Related Function Documentation

◆ C4Network2IO

friend class C4Network2IO
friend

Definition at line 216 of file C4Network2IO.h.

Member Data Documentation

◆ CCore

C4ClientCore C4Network2IOConnection::CCore
protected

Definition at line 238 of file C4Network2IO.h.

Referenced by getCCore(), getClientID(), isHost(), and SetCCore().

◆ CCoreCSec

CStdCSec C4Network2IOConnection::CCoreCSec
protected

Definition at line 239 of file C4Network2IO.h.

Referenced by getCCoreCSec(), and SetCCore().

◆ ConnectAddr

C4NetIO::addr_t C4Network2IOConnection::ConnectAddr
protected

Definition at line 226 of file C4Network2IO.h.

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

◆ eProt

C4Network2IOProtocol C4Network2IOConnection::eProt
protected

Definition at line 225 of file C4Network2IO.h.

Referenced by getProtocol(), and Set().

◆ fAutoAccept

bool C4Network2IOConnection::fAutoAccept {false}
protected

Definition at line 232 of file C4Network2IO.h.

Referenced by isAutoAccepted(), ResetAutoAccepted(), and SetAutoAccepted().

◆ fBroadcastTarget

bool C4Network2IOConnection::fBroadcastTarget {false}
protected

Definition at line 233 of file C4Network2IO.h.

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

◆ fConnSent

bool C4Network2IOConnection::fConnSent {false}
protected

Definition at line 243 of file C4Network2IO.h.

Referenced by isConnSent(), and SetConnSent().

◆ fPostMortemSent

bool C4Network2IOConnection::fPostMortemSent {false}
protected

Definition at line 244 of file C4Network2IO.h.

Referenced by CreatePostMortem(), and Send().

◆ iID

uint32_t C4Network2IOConnection::iID
protected

Definition at line 231 of file C4Network2IO.h.

Referenced by getID(), and Set().

◆ iInPacketCounter

uint32_t C4Network2IOConnection::iInPacketCounter {0}
protected

Definition at line 247 of file C4Network2IO.h.

Referenced by getInPacketCounter(), and OnPacketReceived().

◆ iIRate

int C4Network2IOConnection::iIRate
protected

Definition at line 240 of file C4Network2IO.h.

Referenced by DoStatistics(), and getIRate().

◆ iORate

int C4Network2IOConnection::iORate
protected

Definition at line 240 of file C4Network2IO.h.

Referenced by DoStatistics(), and getORate().

◆ iOutPacketCounter

uint32_t C4Network2IOConnection::iOutPacketCounter {0}
protected

Definition at line 247 of file C4Network2IO.h.

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

◆ iPacketLoss

int C4Network2IOConnection::iPacketLoss
protected

Definition at line 241 of file C4Network2IO.h.

Referenced by DoStatistics(), and getPacketLoss().

◆ iPingTime

int C4Network2IOConnection::iPingTime {-1}
protected

Definition at line 235 of file C4Network2IO.h.

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

◆ iRefCnt

std::atomic_long C4Network2IOConnection::iRefCnt
protected

Definition at line 261 of file C4Network2IO.h.

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

◆ iRemoteID

uint32_t C4Network2IOConnection::iRemoteID
protected

Definition at line 231 of file C4Network2IO.h.

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

◆ iTimestamp

time_t C4Network2IOConnection::iTimestamp {0}
protected

Definition at line 234 of file C4Network2IO.h.

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

◆ PacketLogCSec

CStdCSec C4Network2IOConnection::PacketLogCSec
protected

Definition at line 255 of file C4Network2IO.h.

Referenced by CreatePostMortem(), and Send().

◆ Password

StdCopyStrBuf C4Network2IOConnection::Password
protected

Definition at line 242 of file C4Network2IO.h.

Referenced by getPassword(), and Set().

◆ PeerAddr

C4NetIO::addr_t C4Network2IOConnection::PeerAddr
protected

◆ pNetClass

class C4NetIO* C4Network2IOConnection::pNetClass {nullptr}
protected

◆ pNext

◆ pPacketLog

PacketLogEntry* C4Network2IOConnection::pPacketLog {nullptr}
protected

Definition at line 254 of file C4Network2IO.h.

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

◆ Status

C4Network2IOConnStatus C4Network2IOConnection::Status
protected

◆ TcpSimOpenSocket

std::unique_ptr<C4NetIOTCP::Socket> C4Network2IOConnection::TcpSimOpenSocket
protected

Definition at line 227 of file C4Network2IO.h.

Referenced by Connect(), and SetSocket().

◆ tLastPing

C4TimeMilliseconds C4Network2IOConnection::tLastPing
protected

Definition at line 236 of file C4Network2IO.h.

Referenced by getLag(), and OnPing().

◆ tLastPong

C4TimeMilliseconds C4Network2IOConnection::tLastPong
protected

Definition at line 237 of file C4Network2IO.h.

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


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