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 {nullptr}
 
C4Network2IOProtocol eProt
 
C4NetIO::addr_t PeerAddr
 
C4NetIO::addr_t ConnectAddr
 
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 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 1282 of file C4Network2IO.cpp.

C4Network2IOConnection::~C4Network2IOConnection ( )

Definition at line 1292 of file C4Network2IO.cpp.

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

1293 {
1294  assert(!iRefCnt);
1295  // connection needs to be closed?
1296  if (pNetClass && !isClosed()) Close();
1297  // clear the packet log
1298  ClearPacketLog();
1299 }
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 1519 of file C4Network2IO.cpp.

References iRefCnt.

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

1520 {
1521  ++iRefCnt;
1522 }
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 1386 of file C4Network2IO.cpp.

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

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

1387 {
1388  // Search position of first packet to delete
1389  PacketLogEntry *pPos, *pPrev = nullptr;
1390  for (pPos = pPacketLog; pPos; pPrev = pPos, pPos = pPos->Next)
1391  if (pPos->Number < iUntilID)
1392  break;
1393  if (pPos)
1394  {
1395  // Remove packets from list
1396  (pPrev ? pPrev->Next : pPacketLog) = nullptr;
1397  // Delete everything
1398  while (pPos)
1399  {
1400  PacketLogEntry *pDelete = pPos;
1401  pPos = pPos->Next;
1402  delete pDelete;
1403  }
1404  }
1405 }
PacketLogEntry * pPacketLog
Definition: C4Network2IO.h:252

Here is the caller graph for this function:

void C4Network2IOConnection::Close ( )

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

1441 {
1442  if (!pNetClass || isClosed()) return;
1443  // set status
1445  // close
1447 }
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 1433 of file C4Network2IO.cpp.

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

Referenced by C4Network2IO::Connect().

1434 {
1435  if (!pNetClass) return false;
1436  // try connect
1437  return pNetClass->Connect(ConnectAddr);
1438 }
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 1407 of file C4Network2IO.cpp.

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

Referenced by C4Network2::OnDisconn().

1408 {
1409  // Security
1410  if (!pPkt) return false;
1411  CStdLock PacketLogLock(&PacketLogCSec);
1412  // Nothing to do?
1413  if (!pPacketLog) return false;
1414  // Already created?
1415  if (fPostMortemSent) return false;
1416  // Set connection ID and packet counter
1417  pPkt->SetConnID(iRemoteID);
1418  pPkt->SetPacketCounter(iOutPacketCounter);
1419  // Add packets
1420  for (PacketLogEntry *pEntry = pPacketLog; pEntry; pEntry = pEntry->Next)
1421  pPkt->Add(pEntry->Pkt);
1422  // Okay
1423  fPostMortemSent = true;
1424  return true;
1425 }
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 1524 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().

1525 {
1526  if (--iRefCnt == 0)
1527  delete this;
1528 }
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 1500 of file C4Network2IO.cpp.

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

1501 {
1502  // get C4NetIO statistics
1503  int inIRate, inORate, inLoss;
1504  if (!isOpen() || !pNetClass->GetConnStatistic(PeerAddr, &inIRate, &inORate, &inLoss))
1505  {
1506  iIRate = iORate = iPacketLoss = 0;
1507  return;
1508  }
1509  // normalize
1510  inIRate = inIRate * 1000 / iInterval;
1511  inORate = inORate * 1000 / iInterval;
1512  // set
1513  iIRate = inIRate; iORate = inORate; iPacketLoss = inLoss;
1514  // sum up
1515  if (pIRateSum) *pIRateSum += iIRate;
1516  if (pORateSum) *pORateSum += iORate;
1517 }
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 1301 of file C4Network2IO.cpp.

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

Referenced by C4Network2Stats::ExecuteSecond().

1302 {
1303  if (iPingTime != -1)
1304  {
1305  // Last ping not answered yet?
1306  if(tLastPing > tLastPong)
1307  {
1308  int iPingLag = C4TimeMilliseconds::Now() - tLastPing;
1309  // Use it for lag measurement once it's larger then the last ping time
1310  // (the ping time won't be better than this anyway once the pong's here)
1311  return std::max(iPingLag, iPingTime);
1312  }
1313  }
1314  // Last ping result
1315  return iPingTime;
1316 }
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:442
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:542

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

References iInPacketCounter, and PID_PacketLogStart.

Referenced by C4Network2IO::OnPacket().

1380 {
1381  // Just count them
1382  if (iPacketType >= PID_PacketLogStart)
1383  iInPacketCounter++;
1384 }

Here is the caller graph for this function:

void C4Network2IOConnection::OnPing ( )
protected

Definition at line 1342 of file C4Network2IO.cpp.

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

1343 {
1344  // Still no pong for the last ping?
1345  if (tLastPong < tLastPing)
1346  return;
1347 
1348  // Save time
1350 }
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.

References fAutoAccept.

Referenced by C4Network2::HandleConnRe().

310 { fAutoAccept = false; }

Here is the caller graph for this function:

bool C4Network2IOConnection::Send ( const C4NetIOPacket rPkt)

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

1450 {
1451  // some packets shouldn't go into the log
1452  if (rPkt.getStatus() < PID_PacketLogStart)
1453  {
1454  assert(isOpen());
1455  C4NetIOPacket Copy(rPkt);
1456  Copy.SetAddr(PeerAddr);
1457  return pNetClass->Send(Copy);
1458  }
1459  CStdLock PacketLogLock(&PacketLogCSec);
1460  // create log entry
1461  PacketLogEntry *pLogEntry = new PacketLogEntry();
1462  pLogEntry->Number = iOutPacketCounter++;
1463  pLogEntry->Pkt = rPkt;
1464  pLogEntry->Next = pPacketLog;
1465  pPacketLog = pLogEntry;
1466  // set address
1467  pLogEntry->Pkt.SetAddr(PeerAddr);
1468  // closed? No sweat, post mortem will reroute it later.
1469  if (!isOpen())
1470  {
1471  // post mortem already sent? This shouldn't happen
1472  if (fPostMortemSent) { assert(false); return false; }
1473  // okay then
1474  return true;
1475  }
1476  // send
1477  bool fSuccess = pNetClass->Send(pLogEntry->Pkt);
1478  if (fSuccess)
1479  assert(!fPostMortemSent);
1480  else {
1481  // Not being able to send a packet is actually a big deal,
1482  // as this means that we will have hole in the packet
1483  // order. Better close the connection - post mortem should
1484  // ideally sort everything out from here.
1485  LogF("Network: Fatal: Send failed (%s)", pNetClass->GetError());
1486  pNetClass->ResetError();
1487  Close();
1488  }
1489  return fSuccess;
1490 }
void ResetError()
Definition: C4NetIO.h:285
virtual const char * GetError() const
Definition: C4NetIO.h:284
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:317
bool LogF(const char *strMessage,...)
Definition: C4Log.cpp:260
void SetAddr(const C4NetIO::addr_t &naddr)
Definition: C4NetIO.h:326
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 1318 of file C4Network2IO.cpp.

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

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

1319 {
1320  // save data
1321  pNetClass = pnNetClass; eProt = enProt;
1322  PeerAddr = nPeerAddr; ConnectAddr = nConnectAddr;
1323  Status = nStatus;
1324  Password = szPassword;
1325  iID = inID;
1326  // initialize
1327  fBroadcastTarget = false;
1328  iTimestamp = time(nullptr); iPingTime = -1;
1329 }
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 1374 of file C4Network2IO.cpp.

References fAutoAccept.

Referenced by C4Network2IO::HandlePacket().

1375 {
1376  fAutoAccept = true;
1377 }

Here is the caller graph for this function:

void C4Network2IOConnection::SetBroadcastTarget ( bool  fSet)

Definition at line 1492 of file C4Network2IO.cpp.

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

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

1493 {
1494  // Note that each thread will have to make sure that this flag won't be
1495  // changed until Broadcast() is called. See C4Network2IO::BroadcastCSec.
1497  fBroadcastTarget = fSet;
1498 }
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 1427 of file C4Network2IO.cpp.

References CCore, and CCoreCSec.

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

1428 {
1429  CStdLock CCoreLock(&CCoreCSec);
1430  CCore = nCCore;
1431 }

Here is the caller graph for this function:

void C4Network2IOConnection::SetConnSent ( )
inline

Definition at line 311 of file C4Network2IO.h.

References fConnSent.

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

References PeerAddr.

Referenced by C4Network2IO::OnConn().

1337 {
1338  // just do it
1339  PeerAddr = nPeerAddr;
1340 }
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 1352 of file C4Network2IO.cpp.

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

Referenced by C4Network2IO::HandlePacket().

1353 {
1354  // save it
1355  iPingTime = inPingTime;
1356  // pong received - save timestamp
1358 }
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 1331 of file C4Network2IO.cpp.

References iRemoteID.

Referenced by C4Network2IO::HandlePacket().

1332 {
1333  iRemoteID = inRemoteID;
1334 }

Here is the caller graph for this function:

void C4Network2IOConnection::SetStatus ( C4Network2IOConnStatus  nStatus)
protected

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

1361 {
1362  if (nStatus != Status)
1363  {
1364  // Connection can't return from these
1365  assert(!isClosed());
1366  // set status
1367  Status = nStatus;
1368  // reset timestamp for connect/accept/close
1370  iTimestamp = time(nullptr);
1371  }
1372 }
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 {false}
protected

Definition at line 230 of file C4Network2IO.h.

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

bool C4Network2IOConnection::fBroadcastTarget {false}
protected

Definition at line 231 of file C4Network2IO.h.

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

bool C4Network2IOConnection::fConnSent {false}
protected

Definition at line 241 of file C4Network2IO.h.

Referenced by isConnSent(), and SetConnSent().

bool C4Network2IOConnection::fPostMortemSent {false}
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 {0}
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 {0}
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 {-1}
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 {0}
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 {nullptr}
protected
PacketLogEntry* C4Network2IOConnection::pPacketLog {nullptr}
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: