OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4LeagueClient Class Referenceabstract

#include <C4League.h>

Inheritance diagram for C4LeagueClient:
[legend]
Collaboration diagram for C4LeagueClient:
[legend]

Public Types

typedef EndpointAddress addr_t
 

Public Member Functions

 C4LeagueClient ()
 
const char * getCSID () const
 
C4LeagueAction getCurrentAction () const
 
void ResetCurrentAction ()
 
bool Start (const C4Network2Reference &Ref)
 
bool GetStartReply (StdStrBuf *pMessage, StdStrBuf *pLeague, StdStrBuf *pStreamingAddr, int32_t *pSeed, int32_t *pMaxPlayers)
 
bool Update (const C4Network2Reference &Ref)
 
bool GetUpdateReply (StdStrBuf *pMessage, C4ClientPlayerInfos *pPlayerLeagueInfos)
 
bool End (const C4Network2Reference &Ref, const char *szRecordName, const BYTE *pRecordSHA)
 
bool GetEndReply (StdStrBuf *pMessage, class C4RoundResultsPlayers *pRoundResults)
 
bool Auth (const C4PlayerInfo &PlrInfo, const char *szAccount, const char *szPassword, const char *szNewAccount=nullptr, const char *szNewPassword=nullptr, bool fRememberLogin=false)
 
bool GetAuthReply (StdStrBuf *pMessage, StdStrBuf *pAUID, StdStrBuf *pAccount, bool *pRegister, StdStrBuf *pLoginToken)
 
bool AuthCheck (const C4PlayerInfo &PlrInfo)
 
bool GetAuthCheckReply (StdStrBuf *pMessage, const char *szLeague, class C4PlayerInfo *pPlrInfo)
 
bool ReportDisconnect (const C4ClientPlayerInfos &rSendPlayerFBIDs, C4LeagueDisconnectReason eReason)
 
bool GetReportDisconnectReply (StdStrBuf *pMessage)
 
bool QueryReferences ()
 
bool GetReferences (C4Network2Reference **&rpReferences, int32_t &rRefCount)
 
bool Query (const StdBuf &Data, bool fBinary)
 
bool Query (const char *szData, bool fBinary)
 
bool isBusy () const
 
bool isSuccess () const
 
bool isConnected () const
 
size_t getTotalSize () const
 
size_t getDownloadedSize () const
 
const StdBufgetResultBin () const
 
const char * getResultString () const
 
const char * getServerName () const
 
const char * getRequest () const
 
const C4NetIO::addr_tgetServerAddress () const
 
void Cancel (const char *szReason)
 
void Clear ()
 
bool SetServer (const char *szServerAddress)
 
void SetNotify (class C4InteractiveThread *pnNotify)
 
virtual bool Execute (int iMaxTime, pollfd *readyfds)
 
virtual bool Execute (int iMaxTime=TO_INF)
 
virtual C4TimeMilliseconds GetNextTick (C4TimeMilliseconds tNow)
 
virtual bool Init (uint16_t iPort=addr_t::IPPORT_NONE)
 
virtual bool InitBroadcast (addr_t *pBroadcastAddr)
 
virtual bool Close ()
 
virtual bool Close (const addr_t &addr)
 
virtual bool CloseBroadcast ()
 
virtual bool Connect (const addr_t &addr)
 
virtual bool Send (const C4NetIOPacket &rPacket)
 
virtual bool Send (const class C4NetIOPacket &rPacket)=0
 
virtual bool Broadcast (const C4NetIOPacket &rPacket)
 
virtual bool Broadcast (const class C4NetIOPacket &rPacket)=0
 
virtual bool SetBroadcast (const addr_t &addr, bool fSet=true)
 
virtual void UnBlock ()
 
virtual void GetFDs (std::vector< struct pollfd > &FDs)
 
virtual bool GetStatistic (int *pBroadcastRate)
 
virtual bool GetConnStatistic (const addr_t &addr, int *pIRate, int *pORate, int *pLoss)
 
virtual void ClearStatistic ()
 
virtual void SetCallback (CBClass *pnCallback)
 
virtual void SetCallback (CBClass *pnCallback)=0
 
virtual bool IsNotify ()
 
virtual const char * GetError () const
 
void ResetError ()
 
bool ExecuteUntil (int iTimeout=-1)
 
bool IsSignaled ()
 
virtual bool IsLowPriority ()
 
virtual uint32_t TimerInterval ()
 

Static Public Member Functions

static std::vector< HostAddressGetLocalAddresses ()
 

Static Public Attributes

static const int TO_INF = -1
 

Protected Member Functions

virtual int32_t GetDefaultPort ()
 
virtual void PackPacket (const C4NetIOPacket &rPacket, StdBuf &rOutBuf)
 
virtual size_t UnpackPacket (const StdBuf &rInBuf, const C4NetIO::addr_t &addr)
 
bool OnConn (const C4NetIO::addr_t &AddrPeer, const C4NetIO::addr_t &AddrConnect, const addr_t *pOwnAddr, C4NetIO *pNetIO)
 
void OnDisconn (const C4NetIO::addr_t &AddrPeer, C4NetIO *pNetIO, const char *szReason)
 
void OnPacket (const class C4NetIOPacket &rPacket, C4NetIO *pNetIO)
 
void ResetRequestTimeout ()
 
bool Listen (uint16_t inListenPort)
 
PeerAccept (SOCKET nsock=INVALID_SOCKET, const addr_t &ConnectAddr=addr_t())
 
PeerGetPeer (const addr_t &addr)
 
void OnShareFree (CStdCSecEx *pCSec)
 
void AddConnectWait (SOCKET sock, const addr_t &addr)
 
ConnectWaitGetConnectWait (const addr_t &addr)
 
void ClearConnectWaits ()
 
bool InitIPv6Socket (SOCKET socket)
 
void SetError (const char *strnError, bool fSockErr=false)
 
void Changed ()
 

Protected Attributes

StdCopyBuf ResultBin
 
StdCopyStrBuf ResultString
 
PeerpPeerList
 
struct C4NetIOTCP::ConnectWaitpConnectWaits
 
CStdCSecEx PeerListCSec
 
CStdCSec PeerListAddCSec
 
bool fInit
 
uint16_t iListenPort
 
SOCKET lsock
 
int Pipe [2]
 
StdCopyStrBuf Error
 

Detailed Description

Definition at line 205 of file C4League.h.

Member Typedef Documentation

typedef EndpointAddress C4NetIO::addr_t
inherited

Definition at line 212 of file C4NetIO.h.

Constructor & Destructor Documentation

C4LeagueClient::C4LeagueClient ( )
inline

Definition at line 214 of file C4League.h.

214 : C4Network2RefClient(), CSID(), eCurrAction(C4LA_None) { }

Member Function Documentation

C4NetIOTCP::Peer * C4NetIOTCP::Accept ( SOCKET  nsock = INVALID_SOCKET,
const addr_t ConnectAddr = addr_t() 
)
protectedinherited

Definition at line 1383 of file C4NetIO.cpp.

References StdSchedulerProc::Changed(), C4NetIO::EndpointAddress::Clear(), CStdLock::Clear(), C4NetIOTCP::Peer::Close(), closesocket, C4NetIO::HostAddress::GetFamily(), INVALID_SOCKET, ioctlsocket, C4NetIOTCP::lsock, C4NetIOTCP::Peer::Next, C4NetIO::CBClass::OnConn(), C4NetIOTCP::Peer, C4NetIOTCP::PeerListAddCSec, C4NetIOTCP::PeerListCSec, C4NetIOTCP::pPeerList, C4NetIO::SetError(), SOCK_CLOEXEC, SOCKET_ERROR, and C4NetIO::HostAddress::UnknownFamily.

Referenced by C4NetIOTCP::Execute().

1384 {
1385 
1386  addr_t caddr = ConnectAddr;
1387 
1388  // accept incoming connection?
1389  C4NetIO::addr_t addr; socklen_t iAddrSize = sizeof addr;
1390  if (nsock == INVALID_SOCKET)
1391  {
1392  // accept from listener
1393 #ifdef __linux__
1394  if ((nsock = ::accept4(lsock, &addr, &iAddrSize, SOCK_CLOEXEC)) == INVALID_SOCKET)
1395 #else
1396  if ((nsock = ::accept(lsock, &addr, &iAddrSize)) == INVALID_SOCKET)
1397 #endif
1398  {
1399  // set error
1400  SetError("socket accept failed", true);
1401  return nullptr;
1402  }
1403  // connect address unknown, so zero it
1404  caddr.Clear();
1405  }
1406  else
1407  {
1408  // get peer address
1409  if (::getpeername(nsock, &addr, &iAddrSize) == SOCKET_ERROR)
1410  {
1411 #ifndef HAVE_WINSOCK
1412  // getpeername behaves strangely on exotic platforms. Just ignore it.
1413  if (errno != ENOTCONN)
1414  {
1415 #endif
1416  // set error
1417  SetError("could not get peer address for connected socket", true);
1418  return nullptr;
1419 #ifndef HAVE_WINSOCK
1420  }
1421 #endif
1422  }
1423  }
1424 
1425  // check address
1426  if (addr.GetFamily() == addr_t::UnknownFamily)
1427  {
1428  // set error
1429  SetError("socket accept failed: invalid address returned");
1430  closesocket(nsock);
1431  return nullptr;
1432  }
1433 
1434  // disable nagle (yep, we know what we are doing here - I think)
1435  int iNoDelay = 1;
1436  ::setsockopt(nsock, IPPROTO_TCP, TCP_NODELAY, reinterpret_cast<const char *>(&iNoDelay), sizeof(iNoDelay));
1437 
1438 #ifdef STDSCHEDULER_USE_EVENTS
1439  // set event
1440  if (::WSAEventSelect(nsock, Event, FD_READ | FD_WRITE | FD_CLOSE) == SOCKET_ERROR)
1441  {
1442  // set error
1443  SetError("connection accept failed: could not set event", true);
1444  closesocket(nsock);
1445  return nullptr;
1446  }
1447 #elif defined(HAVE_WINSOCK)
1448  // disable blocking
1449  unsigned long iBlock = 1;
1450  if (::ioctlsocket(nsock, FIONBIO, &iBlock) == SOCKET_ERROR)
1451  {
1452  // set error
1453  SetError("connect failed: could not disable blocking", true);
1454  close(nsock);
1455  return false;
1456  }
1457 #else
1458  // disable blocking
1459  if (::fcntl(nsock, F_SETFL, fcntl(nsock, F_GETFL) | O_NONBLOCK) == SOCKET_ERROR)
1460  {
1461  // set error
1462  SetError("connection accept failed: could not disable blocking", true);
1463  close(nsock);
1464  return nullptr;
1465  }
1466 #endif
1467 
1468 
1469  // create new peer
1470  Peer *pnPeer = new Peer(addr, nsock, this);
1471 
1472  // get required locks to add item to list
1473  CStdShareLock PeerListLock(&PeerListCSec);
1474  CStdLock PeerListAddLock(&PeerListAddCSec);
1475 
1476  // add to list
1477  pnPeer->Next = pPeerList;
1478  pPeerList = pnPeer;
1479 
1480  // clear add-lock
1481  PeerListAddLock.Clear();
1482 
1483  Changed();
1484 
1485  // ask callback if connection should be permitted
1486  if (pCB && !pCB->OnConn(addr, caddr, nullptr, this))
1487  // close socket immediately (will be deleted later)
1488  pnPeer->Close();
1489 
1490  // ok
1491  return pnPeer;
1492 }
#define INVALID_SOCKET
Definition: C4NetIO.h:37
void SetError(const char *strnError, bool fSockErr=false)
Definition: C4NetIO.cpp:754
virtual bool OnConn(const addr_t &AddrPeer, const addr_t &AddrConnect, const addr_t *pOwnAddr, C4NetIO *pNetIO)
Definition: C4NetIO.h:220
#define ioctlsocket
Definition: C4NetIO.cpp:51
Peer * pPeerList
Definition: C4NetIO.h:443
CStdCSecEx PeerListCSec
Definition: C4NetIO.h:455
friend class Peer
Definition: C4NetIO.h:441
AddressFamily GetFamily() const
Definition: C4NetIO.cpp:526
EndpointAddress addr_t
Definition: C4NetIO.h:212
CStdCSec PeerListAddCSec
Definition: C4NetIO.h:456
#define SOCK_CLOEXEC
Definition: C4NetIO.h:51
#define closesocket
Definition: C4NetIO.cpp:52
SOCKET lsock
Definition: C4NetIO.h:463
#define SOCKET_ERROR
Definition: C4NetIO.cpp:53

Here is the call graph for this function:

Here is the caller graph for this function:

void C4NetIOTCP::AddConnectWait ( SOCKET  sock,
const addr_t addr 
)
protectedinherited

Definition at line 1607 of file C4NetIO.cpp.

References C4NetIOTCP::ConnectWait::addr, StdSchedulerProc::Changed(), C4NetIOTCP::ConnectWait::Next, C4NetIOTCP::pConnectWaits, C4NetIOTCP::PeerListAddCSec, C4NetIOTCP::PeerListCSec, C4NetIOTCP::ConnectWait::sock, and C4NetIOTCP::UnBlock().

Referenced by C4NetIOTCP::Connect().

1608 {
1609  CStdShareLock PeerListLock(&PeerListCSec);
1610  CStdLock PeerListAddLock(&PeerListAddCSec);
1611  // create new entry, add to list
1612  ConnectWait *pnWait = new ConnectWait;
1613  pnWait->sock = sock; pnWait->addr = addr;
1614  pnWait->Next = pConnectWaits;
1615  pConnectWaits = pnWait;
1616 #ifndef STDSCHEDULER_USE_EVENTS
1617  // unblock, so new FD can be realized
1618  UnBlock();
1619 #endif
1620  Changed();
1621 }
virtual void UnBlock()
Definition: C4NetIO.cpp:1299
CStdCSecEx PeerListCSec
Definition: C4NetIO.h:455
CStdCSec PeerListAddCSec
Definition: C4NetIO.h:456
struct C4NetIOTCP::ConnectWait * pConnectWaits

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4LeagueClient::Auth ( const C4PlayerInfo PlrInfo,
const char *  szAccount,
const char *  szPassword,
const char *  szNewAccount = nullptr,
const char *  szNewPassword = nullptr,
bool  fRememberLogin = false 
)

Definition at line 406 of file C4League.cpp.

References C4LA_PlrAuth, StdStrBuf::getData(), mkDecompileAdapt(), mkInsertAdapt(), mkNamingAdapt(), C4Network2HTTPClient::Query(), C4LeagueRequestHead::SetAuth(), C4LeagueRequestHead::SetNewAccount(), and C4LeagueRequestHead::SetNewPassword().

Referenced by C4Network2::LeaguePlrAuth().

407 {
408  // Build header
409  eCurrAction = C4LA_PlrAuth;
410  C4LeagueRequestHead Head(eCurrAction);
411  Head.SetAuth(szAccount, szPassword, fRememberLogin);
412  if (szNewAccount)
413  Head.SetNewAccount(szNewAccount);
414  if (szNewPassword)
415  Head.SetNewPassword(szNewPassword);
416  // Create query
417  StdStrBuf QueryText = DecompileToBuf<StdCompilerINIWrite>(
419  mkNamingAdapt(Head, "Request"),
420  mkNamingAdapt(mkDecompileAdapt(PlrInfo), "PlrInfo"),
421  false));
422  // Perform query
423  return Query(QueryText.getData(), false);
424 }
const char * getData() const
Definition: StdBuf.h:450
StdNamingAdapt< T > mkNamingAdapt(T &&rValue, const char *szName)
Definition: StdAdaptors.h:93
StdDecompileAdapt< T > mkDecompileAdapt(const T &rValue)
Definition: StdAdaptors.h:154
StdInsertAdapt< T, I > mkInsertAdapt(T &&rObj, I &&rIns, bool fBefore=true)
Definition: StdAdaptors.h:438
bool Query(const StdBuf &Data, bool fBinary)

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4LeagueClient::AuthCheck ( const C4PlayerInfo PlrInfo)

Definition at line 456 of file C4League.cpp.

References C4LA_PlrAuthCheck, C4PlayerInfo::getAuthID(), StdStrBuf::getData(), StdStrBuf::getLength(), mkDecompileAdapt(), mkInsertAdapt(), mkNamingAdapt(), and C4Network2HTTPClient::Query().

Referenced by C4Network2::LeaguePlrAuthCheck().

457 {
458  assert(CSID.getLength());
459  // Build header
460  eCurrAction = C4LA_PlrAuthCheck;
461  C4LeagueRequestHead Head(eCurrAction, CSID.getData(), PlrInfo.getAuthID());
462  // Create query
463  StdStrBuf QueryText = DecompileToBuf<StdCompilerINIWrite>(
465  mkNamingAdapt(Head, "Request"),
466  mkNamingAdapt(mkDecompileAdapt(PlrInfo), "PlrInfo"),
467  false));
468  // Perform query
469  return Query(QueryText.getData(), false);
470 }
const char * getData() const
Definition: StdBuf.h:450
StdNamingAdapt< T > mkNamingAdapt(T &&rValue, const char *szName)
Definition: StdAdaptors.h:93
StdDecompileAdapt< T > mkDecompileAdapt(const T &rValue)
Definition: StdAdaptors.h:154
StdInsertAdapt< T, I > mkInsertAdapt(T &&rObj, I &&rIns, bool fBefore=true)
Definition: StdAdaptors.h:438
size_t getLength() const
Definition: StdBuf.h:453
bool Query(const StdBuf &Data, bool fBinary)
const char * getAuthID() const
Definition: C4PlayerInfo.h:186

Here is the call graph for this function:

Here is the caller graph for this function:

virtual bool C4NetIO::Broadcast ( const class C4NetIOPacket rPacket)
pure virtualinherited
bool C4NetIOTCP::Broadcast ( const C4NetIOPacket rPacket)
virtualinherited

Definition at line 1288 of file C4NetIO.cpp.

References C4NetIOPacket::getRef(), C4NetIOTCP::Peer::Next, C4NetIOTCP::PeerListCSec, C4NetIOTCP::pPeerList, and C4NetIOTCP::Send().

1289 {
1290  CStdShareLock PeerListLock(&PeerListCSec);
1291  // just send to all clients
1292  bool fSuccess = true;
1293  for (Peer *pPeer = pPeerList; pPeer; pPeer = pPeer->Next)
1294  if (pPeer->Open() && pPeer->doBroadcast())
1295  fSuccess &= Send(C4NetIOPacket(rPacket.getRef(), pPeer->GetAddr()));
1296  return fSuccess;
1297 }
C4NetIOPacket getRef() const
Definition: C4NetIO.h:324
Peer * pPeerList
Definition: C4NetIO.h:443
CStdCSecEx PeerListCSec
Definition: C4NetIO.h:455
friend class Peer
Definition: C4NetIO.h:441
virtual bool Send(const C4NetIOPacket &rPacket)
Definition: C4NetIO.cpp:1266

Here is the call graph for this function:

void C4Network2HTTPClient::Cancel ( const char *  szReason)
inherited

Definition at line 547 of file C4Network2Reference.cpp.

References C4NetIOTCP::Close(), and C4NetIO::Error.

Referenced by C4StartupNetListEntry::Execute(), C4Network2HTTPClient::Execute(), C4Network2HTTPClient::Query(), and C4DownloadDlg::UserClose().

548 {
549  // Close connection - and connection attempt
550  Close(ServerAddr); Close(ServerAddrFallback); Close(PeerAddr);
551  // Reset flags
552  fBusy = fSuccess = fConnected = fBinary = false;
553  iDownloadedSize = iTotalSize = iDataOffset = 0;
554  Error = szReason;
555 }
StdCopyStrBuf Error
Definition: C4NetIO.h:282
virtual bool Close()
Definition: C4NetIO.cpp:870

Here is the call graph for this function:

Here is the caller graph for this function:

void StdSchedulerProc::Changed ( )
protectedinherited

Definition at line 121 of file StdScheduler.cpp.

References s.

Referenced by C4NetIOTCP::Accept(), C4NetIOTCP::AddConnectWait(), C4NetIOUDP::AddPeer(), C4NetIOTCP::Listen(), and CStdTimerProc::SetDelay().

122 {
123  auto s = scheduler;
124  if (s)
125  s->Changed(this);
126 }
#define s

Here is the caller graph for this function:

void C4Network2HTTPClient::Clear ( )
inherited

Definition at line 557 of file C4Network2Reference.cpp.

References StdBuf::Clear(), StdStrBuf::Clear(), C4NetIO::Error, C4Network2HTTPClient::ResultBin, and C4Network2HTTPClient::ResultString.

Referenced by C4Network2::StreamOut().

558 {
559  fBusy = fSuccess = fConnected = fBinary = false;
560  iDownloadedSize = iTotalSize = iDataOffset = 0;
561  ResultBin.Clear();
563  Error.Clear();
564 }
void Clear()
Definition: StdBuf.h:474
void Clear()
Definition: StdBuf.h:198
StdCopyStrBuf Error
Definition: C4NetIO.h:282

Here is the call graph for this function:

Here is the caller graph for this function:

void C4NetIOTCP::ClearConnectWaits ( )
protectedinherited

Definition at line 1633 of file C4NetIO.cpp.

References closesocket, C4NetIOTCP::ConnectWait::Next, C4NetIOTCP::pConnectWaits, and C4NetIOTCP::PeerListCSec.

Referenced by C4NetIOTCP::Close().

1634 {
1635  CStdShareLock PeerListLock(&PeerListCSec);
1636  for (ConnectWait *pWait = pConnectWaits; pWait; pWait = pWait->Next)
1637  if (pWait->sock)
1638  {
1639  closesocket(pWait->sock);
1640  pWait->sock = 0;
1641  }
1642 }
CStdCSecEx PeerListCSec
Definition: C4NetIO.h:455
ConnectWait * Next
Definition: C4NetIO.h:451
struct C4NetIOTCP::ConnectWait * pConnectWaits
#define closesocket
Definition: C4NetIO.cpp:52

Here is the caller graph for this function:

void C4NetIOTCP::ClearStatistic ( )
virtualinherited

Implements C4NetIO.

Definition at line 1375 of file C4NetIO.cpp.

References C4NetIOTCP::Peer::Next, C4NetIOTCP::PeerListCSec, and C4NetIOTCP::pPeerList.

1376 {
1377  CStdShareLock PeerListLock(&PeerListCSec);
1378  // clear all peer statistics
1379  for (Peer *pPeer = pPeerList; pPeer; pPeer = pPeer->Next)
1380  pPeer->ClearStatistics();
1381 }
Peer * pPeerList
Definition: C4NetIO.h:443
CStdCSecEx PeerListCSec
Definition: C4NetIO.h:455
friend class Peer
Definition: C4NetIO.h:441
bool C4NetIOTCP::Close ( )
virtualinherited

Implements C4NetIO.

Reimplemented in C4Network2IRCClient, and C4AulDebug.

Definition at line 870 of file C4NetIO.cpp.

References C4NetIOTCP::ClearConnectWaits(), closesocket, C4NetIOTCP::fInit, INVALID_SOCKET, C4NetIOTCP::lsock, C4NetIOTCP::Peer::Next, C4NetIO::CBClass::OnDisconn(), C4NetIOTCP::PeerListCSec, C4NetIOTCP::Pipe, C4NetIOTCP::pPeerList, and C4NetIO::ResetError().

Referenced by C4Network2HTTPClient::Cancel(), C4Network2RefServer::Clear(), C4AulDebug::Close(), C4Network2IRCClient::Close(), C4NetIOTCP::Init(), main(), C4Network2HTTPClient::UnpackPacket(), C4NetIOTCP::~C4NetIOTCP(), and C4NetIOTCP::Peer::~Peer().

871 {
872  ResetError();
873 
874  // not init?
875  if (!fInit) return false;
876 
877  // terminate connections
878  CStdShareLock PeerListLock(&PeerListCSec);
879  for (Peer *pPeer = pPeerList; pPeer; pPeer = pPeer->Next)
880  if (pPeer->Open())
881  {
882  pPeer->Close();
883  if (pCB) pCB->OnDisconn(pPeer->GetAddr(), this, "owner class closed");
884  }
885 
887 
888  // close listen socket
889  if (lsock != INVALID_SOCKET)
890  {
893  }
894 
895 #ifdef STDSCHEDULER_USE_EVENTS
896  // close event
897  if (Event != nullptr)
898  {
899  WSACloseEvent(Event);
900  Event = nullptr;
901  }
902 #else
903  // close pipe
904  close(Pipe[0]);
905  close(Pipe[1]);
906 #endif
907 
908 #ifdef HAVE_WINSOCK
909  // release winsock
910  ReleaseWinSock();
911 #endif
912 
913  // ok
914  fInit = false;
915  return true;
916 }
void ResetError()
Definition: C4NetIO.h:286
void ClearConnectWaits()
Definition: C4NetIO.cpp:1633
#define INVALID_SOCKET
Definition: C4NetIO.h:37
Peer * pPeerList
Definition: C4NetIO.h:443
int Pipe[2]
Definition: C4NetIO.h:470
CStdCSecEx PeerListCSec
Definition: C4NetIO.h:455
friend class Peer
Definition: C4NetIO.h:441
#define closesocket
Definition: C4NetIO.cpp:52
bool fInit
Definition: C4NetIO.h:459
SOCKET lsock
Definition: C4NetIO.h:463
virtual void OnDisconn(const addr_t &AddrPeer, C4NetIO *pNetIO, const char *szReason)
Definition: C4NetIO.h:221

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4NetIOTCP::Close ( const addr_t addr)
virtualinherited

Implements C4NetIO.

Reimplemented in C4AulDebug.

Definition at line 1235 of file C4NetIO.cpp.

References C4NetIOTCP::ConnectWait::addr, C4NetIOTCP::Peer::Close(), closesocket, C4NetIOTCP::Peer::GetAddr(), C4NetIOTCP::GetConnectWait(), C4NetIOTCP::GetPeer(), C4NetIO::CBClass::OnDisconn(), C4NetIOTCP::PeerListCSec, and C4NetIOTCP::ConnectWait::sock.

1236 {
1237  CStdShareLock PeerListLock(&PeerListCSec);
1238  // find connect wait
1239  ConnectWait *pWait = GetConnectWait(addr);
1240  if (pWait)
1241  {
1242  // close socket, do callback
1243  closesocket(pWait->sock); pWait->sock = 0;
1244  if (pCB) pCB->OnDisconn(pWait->addr, this, "closed");
1245  }
1246  else
1247  {
1248  // find peer
1249  Peer *pPeer = GetPeer(addr);
1250  if (pPeer)
1251  {
1252  C4NetIO::addr_t addr = pPeer->GetAddr();
1253  // close peer
1254  pPeer->Close();
1255  // do callback
1256  if (pCB) pCB->OnDisconn(addr, this, "closed");
1257  }
1258  // not found
1259  else
1260  return false;
1261  }
1262  // ok
1263  return true;
1264 }
CStdCSecEx PeerListCSec
Definition: C4NetIO.h:455
Peer * GetPeer(const addr_t &addr)
Definition: C4NetIO.cpp:1549
friend class Peer
Definition: C4NetIO.h:441
#define closesocket
Definition: C4NetIO.cpp:52
virtual void OnDisconn(const addr_t &AddrPeer, C4NetIO *pNetIO, const char *szReason)
Definition: C4NetIO.h:221
ConnectWait * GetConnectWait(const addr_t &addr)
Definition: C4NetIO.cpp:1623

Here is the call graph for this function:

bool C4NetIOTCP::CloseBroadcast ( )
virtualinherited

Definition at line 918 of file C4NetIO.cpp.

919 {
920  return true;
921 }
bool C4NetIOTCP::Connect ( const addr_t addr)
virtualinherited

Implements C4NetIO.

Definition at line 1167 of file C4NetIO.cpp.

References C4NetIOTCP::AddConnectWait(), closesocket, C4NetIO::HostAddress::GetFamily(), HaveWouldBlockError(), C4NetIO::InitIPv6Socket(), INVALID_SOCKET, ioctlsocket, C4NetIO::HostAddress::IPv6, C4NetIO::SetError(), SOCK_CLOEXEC, SOCKET, and SOCKET_ERROR.

Referenced by C4Network2IRCClient::Connect(), C4Network2HTTPClient::Execute(), main(), and C4Network2HTTPClient::Query().

1168 {
1169  // create new socket
1170  SOCKET nsock = ::socket(addr.GetFamily() == HostAddress::IPv6 ? AF_INET6 : AF_INET, SOCK_STREAM | SOCK_CLOEXEC, IPPROTO_TCP);
1171  if (nsock == INVALID_SOCKET)
1172  {
1173  SetError("socket creation failed", true);
1174  return false;
1175  }
1176 
1177  if (addr.GetFamily() == HostAddress::IPv6)
1178  if (!InitIPv6Socket(nsock))
1179  return false;
1180 
1181 #ifdef STDSCHEDULER_USE_EVENTS
1182  // set event
1183  if (::WSAEventSelect(nsock, Event, FD_CONNECT) == SOCKET_ERROR)
1184  {
1185  // set error
1186  SetError("connect failed: could not set event", true);
1187  closesocket(nsock);
1188  return false;
1189  }
1190 
1191  // add to list
1192  AddConnectWait(nsock, addr);
1193 
1194 #elif defined(HAVE_WINSOCK)
1195  // disable blocking
1196  unsigned long iBlock = 1;
1197  if (::ioctlsocket(nsock, FIONBIO, &iBlock) == SOCKET_ERROR)
1198  {
1199  // set error
1200  SetError("connect failed: could not disable blocking", true);
1201  close(nsock);
1202  return false;
1203  }
1204 #else
1205  // disable blocking
1206  if (::fcntl(nsock, F_SETFL, fcntl(nsock, F_GETFL) | O_NONBLOCK) == SOCKET_ERROR)
1207  {
1208  // set error
1209  SetError("connect failed: could not disable blocking", true);
1210  close(nsock);
1211  return false;
1212  }
1213 #endif
1214 
1215  // connect (async)
1216  if (::connect(nsock, &addr, sizeof addr) == SOCKET_ERROR)
1217  {
1218  if (!HaveWouldBlockError()) // expected
1219  {
1220  SetError("socket connection failed", true);
1221  closesocket(nsock);
1222  return false;
1223  }
1224  }
1225 
1226 #ifndef STDSCHEDULER_USE_EVENTS
1227  // add to list
1228  AddConnectWait(nsock, addr);
1229 #endif
1230 
1231  // ok
1232  return true;
1233 }
#define INVALID_SOCKET
Definition: C4NetIO.h:37
void SetError(const char *strnError, bool fSockErr=false)
Definition: C4NetIO.cpp:754
#define ioctlsocket
Definition: C4NetIO.cpp:51
bool InitIPv6Socket(SOCKET socket)
Definition: C4NetIO.cpp:734
void AddConnectWait(SOCKET sock, const addr_t &addr)
Definition: C4NetIO.cpp:1607
#define SOCKET
Definition: C4NetIO.h:36
bool HaveWouldBlockError()
Definition: C4NetIO.cpp:209
#define SOCK_CLOEXEC
Definition: C4NetIO.h:51
#define closesocket
Definition: C4NetIO.cpp:52
#define SOCKET_ERROR
Definition: C4NetIO.cpp:53

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4LeagueClient::End ( const C4Network2Reference Ref,
const char *  szRecordName,
const BYTE pRecordSHA 
)

Definition at line 376 of file C4League.cpp.

References C4LA_End, StdStrBuf::getData(), StdStrBuf::getLength(), mkDecompileAdapt(), mkInsertAdapt(), mkNamingAdapt(), and C4Network2HTTPClient::Query().

Referenced by C4Network2::LeagueEnd().

377 {
378  assert(CSID.getLength());
379  // Create query
380  eCurrAction = C4LA_End;
381  C4LeagueRequestHeadEnd Head(eCurrAction, CSID.getData(), szRecordName, pRecordSHA);
382  StdStrBuf QueryText = DecompileToBuf<StdCompilerINIWrite>(
384  mkNamingAdapt(Head, "Request"),
385  mkNamingAdapt(mkDecompileAdapt(Ref), "Reference"),
386  false));
387  // Perform query
388  return Query(QueryText.getData(), false);
389 }
const char * getData() const
Definition: StdBuf.h:450
StdNamingAdapt< T > mkNamingAdapt(T &&rValue, const char *szName)
Definition: StdAdaptors.h:93
StdDecompileAdapt< T > mkDecompileAdapt(const T &rValue)
Definition: StdAdaptors.h:154
StdInsertAdapt< T, I > mkInsertAdapt(T &&rObj, I &&rIns, bool fBefore=true)
Definition: StdAdaptors.h:438
size_t getLength() const
Definition: StdBuf.h:453
bool Query(const StdBuf &Data, bool fBinary)

Here is the call graph for this function:

Here is the caller graph for this function:

virtual bool C4Network2HTTPClient::Execute ( int  iMaxTime,
pollfd *  readyfds 
)
inlinevirtualinherited

Reimplemented from C4NetIOTCP.

Definition at line 192 of file C4Network2Reference.h.

References C4Network2HTTPClient::Execute().

Referenced by C4Network2HTTPClient::Execute(), C4Game::InitNetworkFromAddress(), C4Network2::LeagueEnd(), C4Network2::LeaguePlrAuth(), C4Network2::LeaguePlrAuthCheck(), C4Network2::LeagueStart(), C4Network2::LeagueWaitNotBusy(), and C4DownloadDlg::OnIdle().

192 { return Execute(iMaxTime); }
virtual bool Execute(int iMaxTime, pollfd *readyfds)

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Network2HTTPClient::Execute ( int  iMaxTime = TO_INF)
virtualinherited

Definition at line 447 of file C4Network2Reference.cpp.

References Application, C4Network2HTTPClient::Cancel(), C4NetIOTCP::Connect(), C4NetIOTCP::Execute(), StdStrBuf::getData(), C4Application::InteractiveThread, C4TimeMilliseconds::Now(), C4TimeMilliseconds::PositiveInfinity, C4InteractiveThread::ThreadLogS(), and C4NetIO::EndpointAddress::ToString().

448 {
449  // Check timeout
450  if (fBusy)
451  {
452  if (C4TimeMilliseconds::Now() > HappyEyeballsTimeout)
453  {
454  HappyEyeballsTimeout = C4TimeMilliseconds::PositiveInfinity;
455  Application.InteractiveThread.ThreadLogS("HTTP: Starting fallback connection to %s (%s)", Server.getData(), ServerAddrFallback.ToString().getData());
456  Connect(ServerAddrFallback);
457  }
458  if (time(nullptr) > iRequestTimeout)
459  {
460  Cancel("Request timeout");
461  return true;
462  }
463  }
464  // Execute normally
465  return C4NetIOTCP::Execute(iMaxTime);
466 }
const char * getData() const
Definition: StdBuf.h:450
virtual bool Execute(int iMaxTime=TO_INF, pollfd *readyfds=0)
Definition: C4NetIO.cpp:932
bool ThreadLogS(const char *szMessage,...) GNUC_FORMAT_ATTRIBUTE_O
virtual bool Connect(const addr_t &addr)
Definition: C4NetIO.cpp:1167
StdStrBuf ToString(int flags=0) const
Definition: C4NetIO.cpp:605
void Cancel(const char *szReason)
C4Application Application
Definition: C4Globals.cpp:44
C4InteractiveThread InteractiveThread
Definition: C4Application.h:45
static C4TimeMilliseconds Now()

Here is the call graph for this function:

bool StdSchedulerProc::ExecuteUntil ( int  iTimeout = -1)
inherited

Definition at line 46 of file StdScheduler.cpp.

References StdSchedulerProc::Execute(), and C4TimeMilliseconds::Now().

Referenced by main().

47 {
48  // Infinite?
49  if (iTimeout < 0)
50  for (;;)
51  if (!Execute())
52  return false;
53  // Calculate endpoint
54  C4TimeMilliseconds tStopTime = C4TimeMilliseconds::Now() + iTimeout;
55  for (;;)
56  {
57  // Call execute with given timeout
58  if (!Execute(std::max(iTimeout, 0)))
59  return false;
60  // Calculate timeout
62  if (tTime >= tStopTime)
63  break;
64  iTimeout = tStopTime - tTime;
65  }
66  // All ok.
67  return true;
68 }
virtual bool Execute(int iTimeout=-1, pollfd *readyfds=0)=0
static C4TimeMilliseconds Now()

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4LeagueClient::GetAuthCheckReply ( StdStrBuf pMessage,
const char *  szLeague,
class C4PlayerInfo pPlrInfo 
)

Definition at line 472 of file C4League.cpp.

References StdStrBuf::Copy(), C4LeagueResponseHead::getAccount(), C4LeagueResponseHeadAuthCheck::getClanTag(), C4LeagueResponseHead::getMessage(), C4LeagueResponseHeadAuthCheck::getProgressData(), C4LeagueResponseHeadAuthCheck::getRank(), C4LeagueResponseHeadAuthCheck::getRankSymbol(), C4LeagueResponseHeadAuthCheck::getScore(), C4LeagueResponseHead::isSuccess(), mkNamingAdapt(), C4Network2HTTPClient::ResultString, and C4PlayerInfo::SetLeagueData().

Referenced by C4Network2::LeaguePlrAuthCheck().

473 {
474  // Parse response head
476  if (!CompileFromBuf_LogWarn<StdCompilerINIRead>(mkNamingAdapt(Head, "Response"), ResultString, "Auth Check Reply"))
477  return false;
478  // Get message and additional data
479  if (pMessage)
480  pMessage->Copy(Head.getMessage());
481  if (szLeague && pPlrInfo)
482  pPlrInfo->SetLeagueData(Head.getAccount(), Head.getClanTag(), Head.getScore(szLeague), Head.getRank(szLeague), Head.getRankSymbol(szLeague), Head.getProgressData(szLeague));
483  return Head.isSuccess();
484 }
const char * getClanTag() const
Definition: C4League.h:178
const char * getMessage() const
Definition: C4League.h:120
bool isSuccess() const
Definition: C4League.h:121
const char * getAccount() const
Definition: C4League.h:123
int32_t getRank(const char *szLeague) const
Definition: C4League.cpp:155
StdNamingAdapt< T > mkNamingAdapt(T &&rValue, const char *szName)
Definition: StdAdaptors.h:93
int32_t getScore(const char *szLeague) const
Definition: C4League.cpp:147
const char * getProgressData(const char *szLeague) const
Definition: C4League.cpp:171
int32_t getRankSymbol(const char *szLeague) const
Definition: C4League.cpp:163
void Copy()
Definition: StdBuf.h:475

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4LeagueClient::GetAuthReply ( StdStrBuf pMessage,
StdStrBuf pAUID,
StdStrBuf pAccount,
bool *  pRegister,
StdStrBuf pLoginToken 
)

Definition at line 426 of file C4League.cpp.

References C4LeagueFBIDList::AddFBID(), StdStrBuf::Copy(), C4LeagueResponseHead::getAccount(), C4LeagueResponseHead::getAUID(), C4LeagueResponseHead::getFBID(), C4LeagueResponseHead::getLoginToken(), C4LeagueResponseHead::getMessage(), C4LeagueResponseHead::isStatusRegister(), C4LeagueResponseHead::isSuccess(), LoadResStr(), mkNamingAdapt(), StdStrBuf::Ref(), and C4Network2HTTPClient::ResultString.

Referenced by C4Network2::LeaguePlrAuth().

427 {
429  if (!CompileFromBuf_LogWarn<StdCompilerINIRead>(mkNamingAdapt(Head, "Response"), ResultString, "Auth Reply"))
430  return false;
431  // Get message & account
432  if (pMessage)
433  pMessage->Copy(Head.getMessage());
434  if (pAccount)
435  pAccount->Copy(Head.getAccount());
436  if (pRegister)
437  *pRegister = Head.isStatusRegister();
438  if (pLoginToken)
439  pLoginToken->Copy(Head.getLoginToken());
440  // No success?
441  if (!Head.isSuccess())
442  return false;
443  // Check AUID
444  if (!Head.getAUID() || !*Head.getAUID())
445  {
446  pMessage->Ref(LoadResStr("IDS_MSG_LEAGUESERVERREPLYWITHOUTA"));
447  return false;
448  }
449  // Success
450  if (pAUID)
451  pAUID->Copy(Head.getAUID());
452  FBIDList.AddFBID(Head.getFBID(), Head.getAccount());
453  return true;
454 }
const char * getMessage() const
Definition: C4League.h:120
bool isSuccess() const
Definition: C4League.h:121
const char * getLoginToken() const
Definition: C4League.h:126
const char * getAUID() const
Definition: C4League.h:124
const char * getAccount() const
Definition: C4League.h:123
const char * LoadResStr(const char *id)
Definition: C4Language.h:83
StdNamingAdapt< T > mkNamingAdapt(T &&rValue, const char *szName)
Definition: StdAdaptors.h:93
bool isStatusRegister() const
Definition: C4League.h:122
const char * getFBID() const
Definition: C4League.h:125
void AddFBID(const char *szFBID, const char *szAccount)
Definition: C4League.cpp:238
void Ref(const char *pnData)
Definition: StdBuf.h:463
void Copy()
Definition: StdBuf.h:475

Here is the call graph for this function:

Here is the caller graph for this function:

C4NetIOTCP::ConnectWait * C4NetIOTCP::GetConnectWait ( const addr_t addr)
protectedinherited

Definition at line 1623 of file C4NetIO.cpp.

References C4NetIOTCP::ConnectWait::Next, C4NetIOTCP::pConnectWaits, and C4NetIOTCP::PeerListCSec.

Referenced by C4NetIOTCP::Close().

1624 {
1625  CStdShareLock PeerListLock(&PeerListCSec);
1626  // search
1627  for (ConnectWait *pWait = pConnectWaits; pWait; pWait = pWait->Next)
1628  if (pWait->addr == addr)
1629  return pWait;
1630  return nullptr;
1631 }
CStdCSecEx PeerListCSec
Definition: C4NetIO.h:455
ConnectWait * Next
Definition: C4NetIO.h:451
struct C4NetIOTCP::ConnectWait * pConnectWaits

Here is the caller graph for this function:

bool C4NetIOTCP::GetConnStatistic ( const addr_t addr,
int *  pIRate,
int *  pORate,
int *  pLoss 
)
virtualinherited

Implements C4NetIO.

Definition at line 1362 of file C4NetIO.cpp.

References C4NetIOTCP::Peer::GetIRate(), C4NetIOTCP::Peer::GetORate(), C4NetIOTCP::GetPeer(), C4NetIOTCP::Peer::Open(), and C4NetIOTCP::PeerListCSec.

1363 {
1364  CStdShareLock PeerListLock(&PeerListCSec);
1365  // find peer
1366  Peer *pPeer = GetPeer(addr);
1367  if (!pPeer || !pPeer->Open()) return false;
1368  // return statistics
1369  if (pIRate) *pIRate = pPeer->GetIRate();
1370  if (pORate) *pORate = pPeer->GetORate();
1371  if (pLoss) *pLoss = 0;
1372  return true;
1373 }
CStdCSecEx PeerListCSec
Definition: C4NetIO.h:455
Peer * GetPeer(const addr_t &addr)
Definition: C4NetIO.cpp:1549
friend class Peer
Definition: C4NetIO.h:441

Here is the call graph for this function:

const char* C4LeagueClient::getCSID ( ) const
inline

Definition at line 215 of file C4League.h.

References StdStrBuf::getData().

215 { return CSID.getData(); }
const char * getData() const
Definition: StdBuf.h:450

Here is the call graph for this function:

C4LeagueAction C4LeagueClient::getCurrentAction ( ) const
inline

Definition at line 216 of file C4League.h.

Referenced by C4Network2::Execute(), C4Network2::LeagueUpdateProcessReply(), and C4Network2::LeagueWaitNotBusy().

216 { return eCurrAction; }

Here is the caller graph for this function:

virtual int32_t C4Network2RefClient::GetDefaultPort ( )
inlineprotectedvirtualinherited

Reimplemented from C4Network2HTTPClient.

Definition at line 219 of file C4Network2Reference.h.

References C4NetStdPortRefServer.

219 { return C4NetStdPortRefServer; }
const int16_t C4NetStdPortRefServer
Definition: C4Network2.h:32
size_t C4Network2HTTPClient::getDownloadedSize ( ) const
inlineinherited

Definition at line 177 of file C4Network2Reference.h.

Referenced by C4DownloadDlg::OnIdle().

177 { return iDownloadedSize; }

Here is the caller graph for this function:

bool C4LeagueClient::GetEndReply ( StdStrBuf pMessage,
class C4RoundResultsPlayers pRoundResults 
)

Definition at line 391 of file C4League.cpp.

References StdStrBuf::Copy(), C4LeagueResponseHead::getMessage(), C4LeagueResponseHead::isSuccess(), mkNamingAdapt(), and C4Network2HTTPClient::ResultString.

Referenced by C4Network2::LeagueEnd().

392 {
393  // Parse response head
395  if (!CompileFromBuf_LogWarn<StdCompilerINIRead>(mkNamingAdapt(Head, "Response"), ResultString, "End Reply"))
396  return false;
397  // Get message
398  if (pMessage)
399  pMessage->Copy(Head.getMessage());
400  if (pRoundResults)
401  CompileFromBuf_LogWarn<StdCompilerINIRead>(mkNamingAdapt(mkNamingAdapt(*pRoundResults, "PlayerInfos"), "Response"), ResultString, "Round Results");
402  // Done
403  return Head.isSuccess();
404 }
const char * getMessage() const
Definition: C4League.h:120
bool isSuccess() const
Definition: C4League.h:121
StdNamingAdapt< T > mkNamingAdapt(T &&rValue, const char *szName)
Definition: StdAdaptors.h:93
void Copy()
Definition: StdBuf.h:475

Here is the call graph for this function:

Here is the caller graph for this function:

virtual const char* C4NetIO::GetError ( ) const
inlinevirtualinherited

Definition at line 285 of file C4NetIO.h.

References StdStrBuf::getData().

Referenced by C4Network2IO::Connect(), C4NetIOUDP::DoLoopbackTest(), C4StartupNetDlg::DoRefresh(), C4DownloadDlg::GetError(), C4Network2IO::Init(), C4NetIOUDP::InitBroadcast(), C4Network2::InitLeague(), C4Game::InitNetworkFromAddress(), C4Network2::LeagueEnd(), C4Network2::LeaguePlrAuthCheck(), C4Network2::LeagueStart(), C4Network2::LeagueUpdate(), C4Network2::LeagueUpdateProcessReply(), main(), MyCBClass::OnConn(), C4ChatControl::OnConnectBtn(), MyCBClass::OnPacket(), C4StartupNetListEntry::OnReference(), C4ChatControl::ProcessInput(), C4Network2IOConnection::Send(), and C4StartupNetListEntry::SetRefQuery().

285 { return Error.getData(); }
const char * getData() const
Definition: StdBuf.h:450
StdCopyStrBuf Error
Definition: C4NetIO.h:282

Here is the call graph for this function:

Here is the caller graph for this function:

void C4NetIOTCP::GetFDs ( std::vector< struct pollfd > &  FDs)
virtualinherited

Reimplemented from StdSchedulerProc.

Definition at line 1320 of file C4NetIO.cpp.

References INVALID_SOCKET, C4NetIOTCP::lsock, C4NetIOTCP::Peer::Next, C4NetIOTCP::ConnectWait::Next, C4NetIOTCP::pConnectWaits, C4NetIOTCP::PeerListCSec, C4NetIOTCP::Pipe, and C4NetIOTCP::pPeerList.

Referenced by C4NetIOTCP::Execute().

1321 {
1322  pollfd pfd; pfd.revents = 0;
1323  // add pipe
1324  pfd.fd = Pipe[0]; pfd.events = POLLIN;
1325  fds.push_back(pfd);
1326  // add listener
1327  if (lsock != INVALID_SOCKET)
1328  {
1329  pfd.fd = lsock; pfd.events = POLLIN;
1330  fds.push_back(pfd);
1331  }
1332  // add connect waits (wait for them to become writeable)
1333  CStdShareLock PeerListLock(&PeerListCSec);
1334  for (ConnectWait *pWait = pConnectWaits; pWait; pWait = pWait->Next)
1335  {
1336  pfd.fd = pWait->sock; pfd.events = POLLOUT;
1337  fds.push_back(pfd);
1338  }
1339  // add sockets
1340  for (Peer *pPeer = pPeerList; pPeer; pPeer = pPeer->Next)
1341  if (pPeer->GetSocket())
1342  {
1343  // Wait for socket to become readable
1344  pfd.fd = pPeer->GetSocket(); pfd.events = POLLIN;
1345  // Wait for socket to become writeable, if there is data waiting
1346  if (pPeer->hasWaitingData())
1347  {
1348  pfd.events |= POLLOUT;
1349  }
1350  fds.push_back(pfd);
1351  }
1352 }
#define INVALID_SOCKET
Definition: C4NetIO.h:37
Peer * pPeerList
Definition: C4NetIO.h:443
int Pipe[2]
Definition: C4NetIO.h:470
CStdCSecEx PeerListCSec
Definition: C4NetIO.h:455
friend class Peer
Definition: C4NetIO.h:441
ConnectWait * Next
Definition: C4NetIO.h:451
struct C4NetIOTCP::ConnectWait * pConnectWaits
SOCKET lsock
Definition: C4NetIO.h:463

Here is the caller graph for this function:

std::vector< C4NetIO::HostAddress > C4NetIO::GetLocalAddresses ( )
staticinherited

Definition at line 632 of file C4NetIO.cpp.

References C4NetIO::HostAddress::IsLoopback(), and C4NetIO::HostAddress::SetHost().

Referenced by C4Network2Client::AddLocalAddrs(), and C4NetIOUDP::InitBroadcast().

633 {
634  std::vector<HostAddress> result;
635 
636 #ifdef HAVE_WINSOCK
637  HostAddress addr;
638  const size_t BUFFER_SIZE = 16000;
639  PIP_ADAPTER_ADDRESSES addresses = nullptr;
640  for (int i = 0; i < 3; ++i)
641  {
642  addresses = (PIP_ADAPTER_ADDRESSES) realloc(addresses, BUFFER_SIZE * (i+1));
643  if (!addresses)
644  // allocation failed
645  return result;
646  ULONG bufsz = BUFFER_SIZE * (i+1);
647  DWORD rv = GetAdaptersAddresses(AF_UNSPEC,
648  GAA_FLAG_SKIP_ANYCAST|GAA_FLAG_SKIP_MULTICAST|GAA_FLAG_SKIP_DNS_SERVER|GAA_FLAG_SKIP_FRIENDLY_NAME,
649  nullptr, addresses, &bufsz);
650  if (rv == ERROR_BUFFER_OVERFLOW)
651  // too little space, try again
652  continue;
653  if (rv != NO_ERROR)
654  {
655  // Something else happened
656  free(addresses);
657  return result;
658  }
659  // All okay, add addresses
660  for (PIP_ADAPTER_ADDRESSES address = addresses; address; address = address->Next)
661  {
662  for (PIP_ADAPTER_UNICAST_ADDRESS unicast = address->FirstUnicastAddress; unicast; unicast = unicast->Next)
663  {
664  addr.SetHost(unicast->Address.lpSockaddr);
665  if (addr.IsLoopback())
666  continue;
667  result.push_back(addr);
668  }
669  }
670  }
671  free(addresses);
672 #else
673  bool have_ipv6 = false;
674 
675 #ifdef __linux__
676  // Get IPv6 addresses on Linux from procfs which allows filtering deprecated privacy addresses.
677  FILE *f = fopen("/proc/net/if_inet6", "r");
678  if (f)
679  {
680  sockaddr_in6 sa6 = sockaddr_in6();
681  sa6.sin6_family = AF_INET6;
682  auto a6 = sa6.sin6_addr.s6_addr;
683  uint8_t if_idx, plen, scope, flags;
684  char devname[20];
685  while (fscanf(f, "%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx %02hhx %02hhx %02hhx %02hhx %20s\n",
686  &a6[0], &a6[1], &a6[2], &a6[3], &a6[4], &a6[5], &a6[6], &a6[7],
687  &a6[8], &a6[9], &a6[10], &a6[11], &a6[12], &a6[13], &a6[14], &a6[15],
688  &if_idx, &plen, &scope, &flags, devname) != EOF)
689  {
690  // Skip loopback and deprecated addresses.
691  if (scope == IPV6_ADDR_LOOPBACK || flags & IFA_F_DEPRECATED)
692  continue;
693  sa6.sin6_scope_id = scope == IPV6_ADDR_LINKLOCAL ? if_idx : 0;
694  result.emplace_back((sockaddr*) &sa6);
695  }
696  have_ipv6 = result.size() > 0;
697  fclose(f);
698  }
699 #endif
700 
701  struct ifaddrs* addrs;
702  if (getifaddrs(&addrs) < 0)
703  return result;
704  for (struct ifaddrs* ifaddr = addrs; ifaddr != nullptr; ifaddr = ifaddr->ifa_next)
705  {
706  struct sockaddr* ad = ifaddr->ifa_addr;
707  if (ad == nullptr) continue;
708 
709  if ((ad->sa_family == AF_INET || (!have_ipv6 && ad->sa_family == AF_INET6)) && (~ifaddr->ifa_flags & IFF_LOOPBACK)) // Choose only non-loopback IPv4/6 devices
710  {
711  result.emplace_back(ad);
712  }
713  }
714  freeifaddrs(addrs);
715 #endif
716 
717  return result;
718 }
uint32_t DWORD

Here is the call graph for this function:

Here is the caller graph for this function:

C4TimeMilliseconds C4Network2HTTPClient::GetNextTick ( C4TimeMilliseconds  tNow)
virtualinherited

Reimplemented from StdSchedulerProc.

Definition at line 468 of file C4Network2Reference.cpp.

References StdSchedulerProc::GetNextTick(), and C4TimeMilliseconds::Now().

469 {
470  C4TimeMilliseconds tNetIOTCPTick = C4NetIOTCP::GetNextTick(tNow);
471  if (!fBusy)
472  return tNetIOTCPTick;
473 
474  C4TimeMilliseconds tHTTPClientTick = tNow + 1000 * std::max<time_t>(iRequestTimeout - time(nullptr), 0);
475 
476  C4TimeMilliseconds HappyEyeballsTick = tNow + std::max(HappyEyeballsTimeout - C4TimeMilliseconds::Now(), 0);
477 
478  return std::min({tNetIOTCPTick, tHTTPClientTick, HappyEyeballsTick});
479 }
virtual C4TimeMilliseconds GetNextTick(C4TimeMilliseconds tNow)
static C4TimeMilliseconds Now()

Here is the call graph for this function:

C4NetIOTCP::Peer * C4NetIOTCP::GetPeer ( const addr_t addr)
protectedinherited

Definition at line 1549 of file C4NetIO.cpp.

References C4NetIOTCP::Peer::Next, C4NetIOTCP::PeerListCSec, and C4NetIOTCP::pPeerList.

Referenced by C4NetIOTCP::Close(), C4NetIOTCP::GetConnStatistic(), C4NetIOTCP::Send(), and C4NetIOTCP::SetBroadcast().

1550 {
1551  CStdShareLock PeerListLock(&PeerListCSec);
1552  for (Peer *pPeer = pPeerList; pPeer; pPeer = pPeer->Next)
1553  if (pPeer->Open())
1554  if (pPeer->GetAddr() == addr)
1555  return pPeer;
1556  return nullptr;
1557 }
Peer * pPeerList
Definition: C4NetIO.h:443
CStdCSecEx PeerListCSec
Definition: C4NetIO.h:455
friend class Peer
Definition: C4NetIO.h:441

Here is the caller graph for this function:

bool C4Network2RefClient::GetReferences ( C4Network2Reference **&  rpReferences,
int32_t &  rRefCount 
)
inherited

Definition at line 665 of file C4Network2Reference.cpp.

References StdCompilerINIRead::Begin(), StdCompilerINIRead::End(), StdStrBuf::getData(), C4Network2HTTPClient::getServerAddress(), C4Network2HTTPClient::isBusy(), C4Network2HTTPClient::isSuccess(), mkArrayAdaptMap(), mkNamingAdapt(), mkNamingCountAdapt(), StdCompiler::Exception::Msg, C4NetIO::ResetError(), C4Network2HTTPClient::ResultString, C4NetIO::SetError(), StdCompilerINIRead::setInput(), and StdCompiler::Value().

Referenced by C4Game::InitNetworkFromAddress(), and C4StartupNetListEntry::OnReference().

666 {
667  // Sanity check
668  if (isBusy() || !isSuccess()) return false;
669  // local update test
670  try
671  {
672  // Create compiler
673  StdCompilerINIRead Comp;
674  Comp.setInput(ResultString);
675  Comp.Begin();
676  // Read reference count
677  Comp.Value(mkNamingCountAdapt(rRefCount, "Reference"));
678  // Create reference array and initialize
679  rpReferences = new C4Network2Reference *[rRefCount];
680  for (int i = 0; i < rRefCount; i++)
681  rpReferences[i] = nullptr;
682  // Get references
683  Comp.Value(mkNamingAdapt(mkArrayAdaptMap(rpReferences, rRefCount, mkPtrAdaptNoNull<C4Network2Reference>), "Reference"));
684  mkPtrAdaptNoNull<C4Network2Reference>(*rpReferences);
685  // Done
686  Comp.End();
687  }
688  catch (StdCompiler::Exception *pExc)
689  {
690  SetError(pExc->Msg.getData());
691  return false;
692  }
693  // Set source ip
694  for (int i = 0; i < rRefCount; i++)
695  rpReferences[i]->SetSourceAddress(getServerAddress());
696  // Done
697  ResetError();
698  return true;
699 }
const char * getData() const
Definition: StdBuf.h:450
void ResetError()
Definition: C4NetIO.h:286
StdNamingCountAdapt< int_t > mkNamingCountAdapt(int_t &iCount, const char *szName)
Definition: StdAdaptors.h:977
void SetError(const char *strnError, bool fSockErr=false)
Definition: C4NetIO.cpp:754
void setInput(const InT &In)
Definition: StdCompiler.h:639
StdNamingAdapt< T > mkNamingAdapt(T &&rValue, const char *szName)
Definition: StdAdaptors.h:93
void Value(const T &rStruct)
Definition: StdCompiler.h:171
const C4NetIO::addr_t & getServerAddress() const
virtual void Begin() override
virtual void End() override
StdArrayAdapt< T, M > mkArrayAdaptMap(T *pArray, int iSize, M &&map)
Definition: StdAdaptors.h:314

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4LeagueClient::GetReportDisconnectReply ( StdStrBuf pMessage)

Definition at line 501 of file C4League.cpp.

References StdStrBuf::Copy(), C4LeagueResponseHead::getMessage(), C4LeagueResponseHead::isSuccess(), mkNamingAdapt(), and C4Network2HTTPClient::ResultString.

Referenced by C4Network2::LeagueNotifyDisconnect().

502 {
503  // Parse response head
505  if (!CompileFromBuf_LogWarn<StdCompilerINIRead>(mkNamingAdapt(Head, "Response"), ResultString, "Report Disconnect"))
506  return false;
507  // Get message
508  if (pMessage)
509  pMessage->Copy(Head.getMessage());
510  // Done
511  return Head.isSuccess();
512 }
const char * getMessage() const
Definition: C4League.h:120
bool isSuccess() const
Definition: C4League.h:121
StdNamingAdapt< T > mkNamingAdapt(T &&rValue, const char *szName)
Definition: StdAdaptors.h:93
void Copy()
Definition: StdBuf.h:475

Here is the call graph for this function:

Here is the caller graph for this function:

const char* C4Network2HTTPClient::getRequest ( ) const
inlineinherited

Definition at line 181 of file C4Network2Reference.h.

References StdStrBuf::getData().

Referenced by C4DownloadDlg::OnIdle().

181 { return RequestPath.getData(); }
const char * getData() const
Definition: StdBuf.h:450

Here is the call graph for this function:

Here is the caller graph for this function:

const StdBuf& C4Network2HTTPClient::getResultBin ( ) const
inlineinherited

Definition at line 178 of file C4Network2Reference.h.

References C4Network2HTTPClient::ResultBin.

Referenced by C4DownloadDlg::ShowModal().

178 { assert(fBinary); return ResultBin; }

Here is the caller graph for this function:

const char* C4Network2HTTPClient::getResultString ( ) const
inlineinherited

Definition at line 179 of file C4Network2Reference.h.

References StdStrBuf::getData().

179 { assert(!fBinary); return ResultString.getData(); }
const char * getData() const
Definition: StdBuf.h:450

Here is the call graph for this function:

const C4NetIO::addr_t& C4Network2HTTPClient::getServerAddress ( ) const
inlineinherited

Definition at line 182 of file C4Network2Reference.h.

Referenced by C4Network2RefClient::GetReferences().

182 { return ServerAddr; }

Here is the caller graph for this function:

const char* C4Network2HTTPClient::getServerName ( ) const
inlineinherited

Definition at line 180 of file C4Network2Reference.h.

References StdStrBuf::getData().

Referenced by C4StartupNetListEntry::GetJoinAddress(), C4Network2::LeagueEnd(), C4Network2::LeaguePlrAuth(), C4Network2::LeagueStart(), and C4StartupNetListEntry::SetRefQuery().

180 { return Server.getData(); }
const char * getData() const
Definition: StdBuf.h:450

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4LeagueClient::GetStartReply ( StdStrBuf pMessage,
StdStrBuf pLeague,
StdStrBuf pStreamingAddr,
int32_t *  pSeed,
int32_t *  pMaxPlayers 
)

Definition at line 313 of file C4League.cpp.

References C4LA_Start, StdStrBuf::Copy(), C4LeagueResponseHead::getCSID(), C4LeagueResponseHeadStart::getLeague(), C4LeagueResponseHeadStart::getMaxPlayers(), C4LeagueResponseHead::getMessage(), C4LeagueResponseHeadStart::getSeed(), C4LeagueResponseHeadStart::getStreamingAddr(), C4LeagueResponseHeadStart::haveSeed(), C4LeagueResponseHead::isSuccess(), C4Network2HTTPClient::isSuccess(), LoadResStr(), mkNamingAdapt(), and C4Network2HTTPClient::ResultString.

Referenced by C4Network2::LeagueStart().

314 {
315  if (!isSuccess() || eCurrAction != C4LA_Start) return false;
316  // Parse response head
318  if (!CompileFromBuf_LogWarn<StdCompilerINIRead>(mkNamingAdapt(Head, "Response"), ResultString, "Start Reply"))
319  return false;
320  // Get message, league and seed
321  if (pMessage)
322  pMessage->Copy(Head.getMessage());
323  if (pLeague)
324  pLeague->Copy(Head.getLeague());
325  if (pStreamingAddr)
326  pStreamingAddr->Copy(Head.getStreamingAddr());
327  if (pSeed && Head.haveSeed())
328  *pSeed = Head.getSeed();
329  if (pMaxPlayers)
330  *pMaxPlayers = Head.getMaxPlayers();
331  // No success?
332  if (!Head.isSuccess())
333  return false;
334  // Got no CSID or empty CSID?
335  if (!Head.getCSID() || !*Head.getCSID() || *Head.getCSID() == '\0')
336  {
337  if (pMessage)
338  pMessage->Copy(LoadResStr("IDS_LGA_INVALIDRESPONSE3"));
339  return false;
340  }
341  // So save back CSID
342  CSID = Head.getCSID();
343  return true;
344 }
const char * getMessage() const
Definition: C4League.h:120
bool isSuccess() const
Definition: C4League.h:121
const char * getStreamingAddr() const
Definition: C4League.h:142
const char * getLeague() const
Definition: C4League.h:141
int32_t getMaxPlayers() const
Definition: C4League.h:145
const char * LoadResStr(const char *id)
Definition: C4Language.h:83
StdNamingAdapt< T > mkNamingAdapt(T &&rValue, const char *szName)
Definition: StdAdaptors.h:93
int32_t getSeed() const
Definition: C4League.h:144
bool haveSeed() const
Definition: C4League.h:143
const char * getCSID() const
Definition: C4League.h:119
void Copy()
Definition: StdBuf.h:475

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4NetIOTCP::GetStatistic ( int *  pBroadcastRate)
virtualinherited

Implements C4NetIO.

Definition at line 1355 of file C4NetIO.cpp.

1356 {
1357  // no broadcast
1358  if (pBroadcastRate) *pBroadcastRate = 0;
1359  return true;
1360 }
size_t C4Network2HTTPClient::getTotalSize ( ) const
inlineinherited

Definition at line 176 of file C4Network2Reference.h.

Referenced by C4DownloadDlg::OnIdle().

176 { return iTotalSize; }

Here is the caller graph for this function:

bool C4LeagueClient::GetUpdateReply ( StdStrBuf pMessage,
C4ClientPlayerInfos pPlayerLeagueInfos 
)

Definition at line 361 of file C4League.cpp.

References StdStrBuf::Copy(), C4LeagueResponseHead::getMessage(), C4LeagueResponseHeadUpdate::GetPlrInfos(), mkNamingAdapt(), and C4Network2HTTPClient::ResultString.

Referenced by C4Network2::LeagueUpdateProcessReply().

362 {
364  if (!CompileFromBuf_LogWarn<StdCompilerINIRead>(mkNamingAdapt(Reply, "Response"), ResultString, "Update Reply"))
365  return false;
366  // Get message
367  if (pMessage)
368  pMessage->Copy(Reply.getMessage());
369  // get plr infos
370  if (pPlayerLeagueInfos)
371  *pPlayerLeagueInfos = Reply.GetPlrInfos();
372  // Success
373  return true;
374 }
const char * getMessage() const
Definition: C4League.h:120
const C4ClientPlayerInfos & GetPlrInfos() const
Definition: C4League.h:158
StdNamingAdapt< T > mkNamingAdapt(T &&rValue, const char *szName)
Definition: StdAdaptors.h:93
void Copy()
Definition: StdBuf.h:475

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4NetIOTCP::Init ( uint16_t  iPort = addr_t::IPPORT_NONE)
virtualinherited

Implements C4NetIO.

Reimplemented in C4AulDebug.

Definition at line 824 of file C4NetIO.cpp.

References C4NetIOTCP::Close(), C4NetIOTCP::fInit, C4NetIO::EndpointAddress::IPPORT_NONE, C4NetIOTCP::Listen(), C4NetIOTCP::Pipe, and C4NetIO::SetError().

Referenced by C4StartupNetDlg::CheckVersionUpdate(), C4Network2IRCClient::Connect(), C4AulDebug::Init(), C4Network2IO::Init(), C4Network2::InitLeague(), C4Game::InitNetworkFromAddress(), main(), C4StartupNetListEntry::SetRefQuery(), C4DownloadDlg::ShowModal(), and C4Network2::StartStreaming().

825 {
826  // already init? close first
827  if (fInit) Close();
828 
829 #ifdef HAVE_WINSOCK
830  // init winsock
831  if (!AcquireWinSock())
832  {
833  SetError("could not start winsock");
834  return false;
835  }
836 #endif
837 
838 #ifdef STDSCHEDULER_USE_EVENTS
839  // create event
840  if ((Event = WSACreateEvent()) == WSA_INVALID_EVENT)
841  {
842  SetError("could not create socket event", true); // to do: more error information
843  return false;
844  }
845 #else
846  // create pipe
847  if (pipe(Pipe) != 0)
848  {
849  SetError("could not create pipe", true);
850  return false;
851  }
852 #endif
853 
854  // create listen socket (if necessary)
855  if (iPort != addr_t::IPPORT_NONE)
856  if (!Listen(iPort))
857  return false;
858 
859  // ok
860  fInit = true;
861  return true;
862 }
void SetError(const char *strnError, bool fSockErr=false)
Definition: C4NetIO.cpp:754
bool Listen(uint16_t inListenPort)
Definition: C4NetIO.cpp:1494
int Pipe[2]
Definition: C4NetIO.h:470
virtual bool Close()
Definition: C4NetIO.cpp:870
bool fInit
Definition: C4NetIO.h:459
static const uint16_t IPPORT_NONE
Definition: C4NetIO.h:137

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4NetIOTCP::InitBroadcast ( addr_t pBroadcastAddr)
virtualinherited

Definition at line 864 of file C4NetIO.cpp.

Referenced by main().

865 {
866  // ignore
867  return true;
868 }

Here is the caller graph for this function:

bool C4NetIO::InitIPv6Socket ( SOCKET  socket)
protectedinherited

Definition at line 734 of file C4NetIO.cpp.

References C4NetIO::SetError(), and SOCKET_ERROR.

Referenced by C4NetIOTCP::Connect(), C4NetIOSimpleUDP::Init(), and C4NetIOTCP::Listen().

735 {
736  int opt = 0;
737  if (setsockopt(socket, IPPROTO_IPV6, IPV6_V6ONLY, reinterpret_cast<char*>(&opt), sizeof(opt)) == SOCKET_ERROR)
738  {
739  SetError("could not enable dual-stack socket", true);
740  return false;
741  }
742 
743 #ifdef IPV6_ADDR_PREFERENCES
744  // Prefer stable addresses. This should prevent issues with address
745  // deprecation while a match is running. No error handling - if the call
746  // fails, we just take any address.
747  opt = IPV6_PREFER_SRC_PUBLIC;
748  setsockopt(socket, IPPROTO_IPV6, IPV6_ADDR_PREFERENCES, reinterpret_cast<char*>(&opt), sizeof(opt));
749 #endif
750 
751  return true;
752 }
void SetError(const char *strnError, bool fSockErr=false)
Definition: C4NetIO.cpp:754
#define SOCKET_ERROR
Definition: C4NetIO.cpp:53

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Network2HTTPClient::isConnected ( ) const
inlineinherited

Definition at line 175 of file C4Network2Reference.h.

Referenced by C4DownloadDlg::OnIdle().

175 { return fConnected; }

Here is the caller graph for this function:

virtual bool StdSchedulerProc::IsLowPriority ( )
inlinevirtualinherited

Definition at line 86 of file StdScheduler.h.

86 { return false; }
virtual bool C4NetIO::IsNotify ( )
inlinevirtualinherited

Reimplemented from StdSchedulerProc.

Definition at line 259 of file C4NetIO.h.

259 { return true; }
bool StdSchedulerProc::IsSignaled ( )
inherited
bool C4Network2HTTPClient::isSuccess ( ) const
inlineinherited
bool C4NetIOTCP::Listen ( uint16_t  inListenPort)
protectedinherited

Definition at line 1494 of file C4NetIO.cpp.

References C4NetIO::HostAddress::Any, StdSchedulerProc::Changed(), closesocket, C4NetIOTCP::iListenPort, C4NetIO::InitIPv6Socket(), INVALID_SOCKET, C4NetIO::EndpointAddress::IPPORT_NONE, C4NetIOTCP::lsock, C4NetIO::SetError(), C4NetIO::EndpointAddress::SetPort(), SOCK_CLOEXEC, and SOCKET_ERROR.

Referenced by C4NetIOTCP::Execute(), and C4NetIOTCP::Init().

1495 {
1496  // already listening?
1497  if (lsock != INVALID_SOCKET)
1498  // close existing socket
1499  closesocket(lsock);
1501 
1502  // create socket
1503  if ((lsock = ::socket(AF_INET6, SOCK_STREAM | SOCK_CLOEXEC, IPPROTO_TCP)) == INVALID_SOCKET)
1504  {
1505  SetError("socket creation failed", true);
1506  return false;
1507  }
1508  if (!InitIPv6Socket(lsock))
1509  return false;
1510  // To be able to reuse the port after close
1511 #if !defined(_DEBUG) && !defined(_WIN32)
1512  int reuseaddr = 1;
1513  setsockopt(lsock, SOL_SOCKET, SO_REUSEADDR, reinterpret_cast<const char *>(&reuseaddr), sizeof(reuseaddr));
1514 #endif
1515  // bind listen socket
1516  addr_t addr = addr_t::Any;
1517  addr.SetPort(inListenPort);
1518  if (::bind(lsock, &addr, sizeof(addr)) == SOCKET_ERROR)
1519  {
1520  SetError("socket bind failed", true);
1522  return false;
1523  }
1524 
1525 #ifdef STDSCHEDULER_USE_EVENTS
1526  // set event callback
1527  if (::WSAEventSelect(lsock, Event, FD_ACCEPT | FD_CLOSE) == SOCKET_ERROR)
1528  {
1529  SetError("could not set event for listen socket", true);
1531  return false;
1532  }
1533 #endif
1534 
1535  // start listening
1536  if (::listen(lsock, SOMAXCONN) == SOCKET_ERROR)
1537  {
1538  SetError("socket listen failed", true);
1540  return false;
1541  }
1542 
1543  // ok
1544  iListenPort = inListenPort;
1545  Changed();
1546  return true;
1547 }
#define INVALID_SOCKET
Definition: C4NetIO.h:37
void SetError(const char *strnError, bool fSockErr=false)
Definition: C4NetIO.cpp:754
bool InitIPv6Socket(SOCKET socket)
Definition: C4NetIO.cpp:734
EndpointAddress addr_t
Definition: C4NetIO.h:212
#define SOCK_CLOEXEC
Definition: C4NetIO.h:51
#define closesocket
Definition: C4NetIO.cpp:52
static const uint16_t IPPORT_NONE
Definition: C4NetIO.h:137
SOCKET lsock
Definition: C4NetIO.h:463
uint16_t iListenPort
Definition: C4NetIO.h:462
#define SOCKET_ERROR
Definition: C4NetIO.cpp:53

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Network2HTTPClient::OnConn ( const C4NetIO::addr_t AddrPeer,
const C4NetIO::addr_t AddrConnect,
const addr_t pOwnAddr,
C4NetIO pNetIO 
)
protectedvirtualinherited

Reimplemented from C4NetIO::CBClass.

Definition at line 409 of file C4Network2Reference.cpp.

References StdBuf::Clear(), C4NetIO::Error, StdStrBuf::Format(), StdStrBuf::getData(), and C4NetIOTCP::Send().

410 {
411  // Make sure we're actually waiting for this connection
412  if (fConnected || (AddrConnect != ServerAddr && AddrConnect != ServerAddrFallback))
413  return false;
414  // Save pack peer address
415  PeerAddr = AddrPeer;
416  // Send the request
417  if (!Send(C4NetIOPacket(Request, AddrPeer)))
418  {
419  Error.Format("Unable to send HTTP request: %s", Error.getData());
420  }
421  Request.Clear();
422  fConnected = true;
423  return true;
424 }
const char * getData() const
Definition: StdBuf.h:450
void Clear()
Definition: StdBuf.h:198
StdCopyStrBuf Error
Definition: C4NetIO.h:282
void Format(const char *szFmt,...) GNUC_FORMAT_ATTRIBUTE_O
Definition: StdBuf.cpp:181
virtual bool Send(const C4NetIOPacket &rPacket)
Definition: C4NetIO.cpp:1266

Here is the call graph for this function:

void C4Network2HTTPClient::OnDisconn ( const C4NetIO::addr_t AddrPeer,
C4NetIO pNetIO,
const char *  szReason 
)
protectedvirtualinherited

Reimplemented from C4NetIO::CBClass.

Definition at line 426 of file C4Network2Reference.cpp.

References C4NetIO::Error, Ev_HTTP_Response, StdStrBuf::Format(), StdStrBuf::isNull(), and C4InteractiveThread::PushEvent().

427 {
428  // Got no complete packet? Failure...
429  if (!fSuccess && Error.isNull())
430  {
431  fBusy = false;
432  Error.Format("Unexpected disconnect: %s", szReason);
433  }
434  fConnected = false;
435  // Notify
436  if (pNotify)
437  pNotify->PushEvent(Ev_HTTP_Response, this);
438 }
StdCopyStrBuf Error
Definition: C4NetIO.h:282
void Format(const char *szFmt,...) GNUC_FORMAT_ATTRIBUTE_O
Definition: StdBuf.cpp:181
bool PushEvent(C4InteractiveEventType eEventType, void *pData=nullptr)
bool isNull() const
Definition: StdBuf.h:449

Here is the call graph for this function:

void C4Network2HTTPClient::OnPacket ( const class C4NetIOPacket rPacket,
C4NetIO pNetIO 
)
protectedvirtualinherited

Implements C4NetIO::CBClass.

Definition at line 440 of file C4Network2Reference.cpp.

References Ev_HTTP_Response, and C4InteractiveThread::PushEvent().

Referenced by C4Network2HTTPClient::UnpackPacket().

441 {
442  // Everything worthwhile was already done in UnpackPacket. Only do notify callback
443  if (pNotify)
444  pNotify->PushEvent(Ev_HTTP_Response, this);
445 }
bool PushEvent(C4InteractiveEventType eEventType, void *pData=nullptr)

Here is the call graph for this function:

Here is the caller graph for this function:

void C4NetIOTCP::OnShareFree ( CStdCSecEx pCSec)
protectedvirtualinherited

Implements CStdCSecExCallback.

Definition at line 1559 of file C4NetIO.cpp.

References C4NetIOTCP::Peer::Next, C4NetIOTCP::ConnectWait::Next, C4NetIOTCP::Peer::Open(), C4NetIOTCP::pConnectWaits, C4NetIOTCP::PeerListCSec, C4NetIOTCP::pPeerList, and C4NetIOTCP::ConnectWait::sock.

1560 {
1561  if (pCSec == &PeerListCSec)
1562  {
1563  // clear up
1564  Peer *pPeer = pPeerList, *pLast = nullptr;
1565  while (pPeer)
1566  {
1567  // delete?
1568  if (!pPeer->Open())
1569  {
1570  // unlink
1571  Peer *pDelete = pPeer;
1572  pPeer = pPeer->Next;
1573  (pLast ? pLast->Next : pPeerList) = pPeer;
1574  // delete
1575  delete pDelete;
1576  }
1577  else
1578  {
1579  // next peer
1580  pLast = pPeer;
1581  pPeer = pPeer->Next;
1582  }
1583  }
1584  ConnectWait *pWait = pConnectWaits, *pWLast = nullptr;
1585  while (pWait)
1586  {
1587  // delete?
1588  if (!pWait->sock)
1589  {
1590  // unlink
1591  ConnectWait *pDelete = pWait;
1592  pWait = pWait->Next;
1593  (pWLast ? pWLast->Next : pConnectWaits) = pWait;
1594  // delete
1595  delete pDelete;
1596  }
1597  else
1598  {
1599  // next peer
1600  pWLast = pWait;
1601  pWait = pWait->Next;
1602  }
1603  }
1604  }
1605 }
Peer * pPeerList
Definition: C4NetIO.h:443
CStdCSecEx PeerListCSec
Definition: C4NetIO.h:455
friend class Peer
Definition: C4NetIO.h:441
ConnectWait * Next
Definition: C4NetIO.h:451
struct C4NetIOTCP::ConnectWait * pConnectWaits

Here is the call graph for this function:

void C4Network2HTTPClient::PackPacket ( const C4NetIOPacket rPacket,
StdBuf rOutBuf 
)
protectedvirtualinherited

Reimplemented from C4NetIOTCP.

Definition at line 262 of file C4Network2Reference.cpp.

References StdBuf::Append().

263 {
264  // Just append the packet
265  rOutBuf.Append(rPacket);
266 }
void Append(const void *pnData, size_t inSize)
Definition: StdBuf.h:262

Here is the call graph for this function:

bool C4Network2HTTPClient::Query ( const StdBuf Data,
bool  fBinary 
)
inherited

Definition at line 481 of file C4Network2Reference.cpp.

References StdBuf::Append(), C4Network2HTTPHappyEyeballsTimeout, C4Network2HTTPClient::Cancel(), StdStrBuf::Clear(), Config, C4NetIOTCP::Connect(), StdStrBuf::Format(), C4Config::General, StdStrBuf::getData(), StdStrBuf::getLength(), StdBuf::getSize(), StdStrBuf::GrabPointer(), C4NetIO::EndpointAddress::IsNull(), StdStrBuf::isNull(), C4ConfigGeneral::LanguageEx, C4TimeMilliseconds::Now(), C4TimeMilliseconds::PositiveInfinity, C4NetIO::ResetError(), C4Network2HTTPClient::ResetRequestTimeout(), C4Network2HTTPClient::ResultString, and StdBuf::Take().

Referenced by Auth(), AuthCheck(), End(), C4Network2RefClient::QueryReferences(), C4Network2UpdateClient::QueryUpdateURL(), ReportDisconnect(), C4DownloadDlg::ShowModal(), Start(), C4Network2::StreamOut(), and Update().

482 {
483  if (Server.isNull()) return false;
484  // Cancel previous request
485  if (fBusy)
486  Cancel("Cancelled");
487  // No result known yet
489  // store mode
490  this->fBinary = fBinary;
491  // Create request
492  StdStrBuf Header;
493  if (Data.getSize())
494  Header.Format(
495  "POST %s HTTP/1.0\r\n"
496  "Host: %s\r\n"
497  "Connection: Close\r\n"
498  "Content-Length: %lu\r\n"
499  "Content-Type: text/plain; charset=utf-8\r\n"
500  "Accept-Charset: utf-8\r\n"
501  "Accept-Encoding: gzip\r\n"
502  "Accept-Language: %s\r\n"
503  "User-Agent: " C4ENGINENAME "/" C4VERSION "\r\n"
504  "\r\n",
505  RequestPath.getData(),
506  Server.getData(),
507  static_cast<unsigned long>(Data.getSize()),
509  else
510  Header.Format(
511  "GET %s HTTP/1.0\r\n"
512  "Host: %s\r\n"
513  "Connection: Close\r\n"
514  "Accept-Charset: utf-8\r\n"
515  "Accept-Encoding: gzip\r\n"
516  "Accept-Language: %s\r\n"
517  "User-Agent: " C4ENGINENAME "/" C4VERSION "\r\n"
518  "\r\n",
519  RequestPath.getData(),
520  Server.getData(),
522  // Compose query
523  Request.Take(Header.GrabPointer(), Header.getLength());
524  Request.Append(Data);
525  // Start connecting
526  if (!Connect(ServerAddr))
527  return false;
528  // Also try the fallback address after some time (if there is one)
529  if (!ServerAddrFallback.IsNull())
531  else
532  HappyEyeballsTimeout = C4TimeMilliseconds::PositiveInfinity;
533  // Okay, request will be performed when connection is complete
534  fBusy = true;
535  iDataOffset = 0;
537  ResetError();
538  return true;
539 }
const char * getData() const
Definition: StdBuf.h:450
void ResetError()
Definition: C4NetIO.h:286
C4Config Config
Definition: C4Config.cpp:837
char * GrabPointer()
Definition: StdBuf.h:467
void Take(void *pnData, size_t inSize)
Definition: StdBuf.h:132
void Clear()
Definition: StdBuf.h:474
C4ConfigGeneral General
Definition: C4Config.h:252
virtual bool Connect(const addr_t &addr)
Definition: C4NetIO.cpp:1167
void Format(const char *szFmt,...) GNUC_FORMAT_ATTRIBUTE_O
Definition: StdBuf.cpp:181
size_t getSize() const
Definition: StdBuf.h:109
void Cancel(const char *szReason)
char LanguageEx[CFG_MaxString+1]
Definition: C4Config.h:38
void Append(const void *pnData, size_t inSize)
Definition: StdBuf.h:262
const uint32_t C4Network2HTTPHappyEyeballsTimeout
bool isNull() const
Definition: StdBuf.h:449
bool IsNull() const
Definition: C4NetIO.cpp:509
size_t getLength() const
Definition: StdBuf.h:453
static C4TimeMilliseconds Now()

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Network2HTTPClient::Query ( const char *  szData,
bool  fBinary 
)
inlineinherited

Definition at line 171 of file C4Network2Reference.h.

References C4Network2HTTPClient::Query(), and SLen().

Referenced by C4Network2HTTPClient::Query().

171 { return Query(StdBuf(szData, SLen(szData)), fBinary); }
Definition: StdBuf.h:37
size_t SLen(const char *sptr)
Definition: Standard.h:78
bool Query(const StdBuf &Data, bool fBinary)

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Network2RefClient::QueryReferences ( )
inherited

Definition at line 659 of file C4Network2Reference.cpp.

References C4Network2HTTPClient::Query().

Referenced by C4Game::InitNetworkFromAddress().

660 {
661  // Perform an Query query
662  return Query(nullptr, false);
663 }
bool Query(const StdBuf &Data, bool fBinary)

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4LeagueClient::ReportDisconnect ( const C4ClientPlayerInfos rSendPlayerFBIDs,
C4LeagueDisconnectReason  eReason 
)

Definition at line 486 of file C4League.cpp.

References C4LA_ReportDisconnect, StdStrBuf::getData(), mkInsertAdapt(), mkNamingAdapt(), and C4Network2HTTPClient::Query().

Referenced by C4Network2::LeagueNotifyDisconnect().

487 {
488  // Build header
489  eCurrAction = C4LA_ReportDisconnect;
490  C4LeagueReportDisconnectHead Head(CSID.getData(), eReason);
491  // Create query
492  StdStrBuf QueryText = DecompileToBuf<StdCompilerINIWrite>(
494  mkNamingAdapt(Head, "Request"),
495  mkNamingAdapt(DisconnectData(FBIDList, rFeedbackClient), "PlayerInfos"),
496  false));
497  // Perform query
498  return Query(QueryText.getData(), false);
499 }
const char * getData() const
Definition: StdBuf.h:450
StdNamingAdapt< T > mkNamingAdapt(T &&rValue, const char *szName)
Definition: StdAdaptors.h:93
StdInsertAdapt< T, I > mkInsertAdapt(T &&rObj, I &&rIns, bool fBefore=true)
Definition: StdAdaptors.h:438
bool Query(const StdBuf &Data, bool fBinary)

Here is the call graph for this function:

Here is the caller graph for this function:

void C4LeagueClient::ResetCurrentAction ( )
inline

Definition at line 217 of file C4League.h.

References C4LA_None.

Referenced by C4Network2::LeagueUpdateProcessReply().

217 { eCurrAction = C4LA_None; }

Here is the caller graph for this function:

void C4NetIO::ResetError ( )
inlineinherited

Definition at line 286 of file C4NetIO.h.

References StdStrBuf::Clear().

Referenced by C4NetIO::C4NetIO(), C4NetIOTCP::Close(), C4NetIOSimpleUDP::Close(), C4NetIOUDP::CloseBroadcast(), C4Network2IO::Connect(), C4NetIOSimpleUDP::Execute(), C4NetIOUDP::Execute(), C4Network2RefClient::GetReferences(), C4NetIOSimpleUDP::Init(), C4NetIOSimpleUDP::InitBroadcast(), C4NetIOUDP::InitBroadcast(), C4Network2HTTPClient::Query(), C4Network2IOConnection::Send(), C4NetIOSimpleUDP::Send(), and C4Network2HTTPClient::SetServer().

286 { Error.Clear(); }
void Clear()
Definition: StdBuf.h:474
StdCopyStrBuf Error
Definition: C4NetIO.h:282

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Network2HTTPClient::ResetRequestTimeout ( )
protectedinherited

Definition at line 541 of file C4Network2Reference.cpp.

References C4Network2HTTPQueryTimeout.

Referenced by C4Network2HTTPClient::Query(), and C4Network2HTTPClient::UnpackPacket().

542 {
543  // timeout C4Network2HTTPQueryTimeout seconds from this point
544  iRequestTimeout = time(nullptr) + C4Network2HTTPQueryTimeout;
545 }
const int C4Network2HTTPQueryTimeout

Here is the caller graph for this function:

virtual bool C4NetIO::Send ( const class C4NetIOPacket rPacket)
pure virtualinherited

Referenced by main(), MyCBClass::OnConn(), MyCBClass::OnPacket(), C4Network2IOConnection::Send(), and C4Network2IO::SendPuncherPacket().

Here is the caller graph for this function:

bool C4NetIOTCP::Send ( const C4NetIOPacket rPacket)
virtualinherited

Definition at line 1266 of file C4NetIO.cpp.

References C4NetIOPacket::getAddr(), C4NetIOTCP::GetPeer(), C4NetIOTCP::PeerListCSec, and C4NetIOTCP::Peer::Send().

Referenced by C4NetIOTCP::Broadcast(), C4Network2HTTPClient::OnConn(), C4Network2IRCClient::Send(), and C4NetIOTCP::Peer::Send().

1267 {
1268  CStdShareLock PeerListLock(&PeerListCSec);
1269  // find peer
1270  Peer *pPeer = GetPeer(rPacket.getAddr());
1271  // not found?
1272  if (!pPeer) return false;
1273  // send
1274  return pPeer->Send(rPacket);
1275 }
const C4NetIO::addr_t & getAddr() const
Definition: C4NetIO.h:316
CStdCSecEx PeerListCSec
Definition: C4NetIO.h:455
Peer * GetPeer(const addr_t &addr)
Definition: C4NetIO.cpp:1549
friend class Peer
Definition: C4NetIO.h:441
bool Send(const C4NetIOPacket &rPacket)
Definition: C4NetIO.cpp:1707

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4NetIOTCP::SetBroadcast ( const addr_t addr,
bool  fSet = true 
)
virtualinherited

Implements C4NetIO.

Definition at line 1277 of file C4NetIO.cpp.

References C4NetIOTCP::GetPeer(), C4NetIOTCP::PeerListCSec, and C4NetIOTCP::Peer::SetBroadcast().

1278 {
1279  CStdShareLock PeerListLock(&PeerListCSec);
1280  // find peer
1281  Peer *pPeer = GetPeer(addr);
1282  if (!pPeer) return false;
1283  // set flag
1284  pPeer->SetBroadcast(fSet);
1285  return true;
1286 }
CStdCSecEx PeerListCSec
Definition: C4NetIO.h:455
Peer * GetPeer(const addr_t &addr)
Definition: C4NetIO.cpp:1549
friend class Peer
Definition: C4NetIO.h:441

Here is the call graph for this function:

virtual void C4NetIO::SetCallback ( CBClass pnCallback)
pure virtualinherited

Referenced by C4NetIOMan::AddIO(), and C4Network2IO::Init().

Here is the caller graph for this function:

virtual void C4NetIOTCP::SetCallback ( CBClass *  pnCallback)
inlinevirtualinherited

Definition at line 487 of file C4NetIO.h.

Referenced by C4Network2HTTPClient::C4Network2HTTPClient(), C4Network2IRCClient::Connect(), and C4AulDebug::Init().

487 { pCB = pnCallback; };

Here is the caller graph for this function:

void C4NetIO::SetError ( const char *  strnError,
bool  fSockErr = false 
)
protectedinherited

Definition at line 754 of file C4NetIO.cpp.

References StdStrBuf::Copy(), C4NetIO::Error, StdStrBuf::Format(), GetSocketErrorMsg(), and HaveSocketError().

Referenced by C4NetIOTCP::Accept(), C4NetIOSimpleUDP::CloseBroadcast(), C4Network2IRCClient::Connect(), C4NetIOTCP::Connect(), C4NetIOUDP::DoLoopbackTest(), C4NetIOTCP::Execute(), C4NetIOSimpleUDP::Execute(), C4NetIOUDP::Execute(), C4Network2RefClient::GetReferences(), C4Network2UpdateClient::GetUpdateURL(), C4Network2UpdateClient::GetVersion(), C4NetIOTCP::Init(), C4NetIOSimpleUDP::Init(), C4NetIOSimpleUDP::InitBroadcast(), C4NetIOUDP::InitBroadcast(), C4NetIO::InitIPv6Socket(), C4Network2IRCClient::Join(), C4NetIOTCP::Listen(), C4Network2IRCClient::Send(), C4NetIOSimpleUDP::Send(), C4Network2HTTPClient::SetServer(), C4NetIOTCP::UnBlock(), and C4NetIOSimpleUDP::UnBlock().

755 {
756  fSockErr &= HaveSocketError();
757  if (fSockErr)
758  Error.Format("%s (%s)", strnError, GetSocketErrorMsg());
759  else
760  Error.Copy(strnError);
761 }
const char * GetSocketErrorMsg(int iError)
Definition: C4NetIO.cpp:196
StdCopyStrBuf Error
Definition: C4NetIO.h:282
void Format(const char *szFmt,...) GNUC_FORMAT_ATTRIBUTE_O
Definition: StdBuf.cpp:181
bool HaveSocketError()
Definition: C4NetIO.cpp:205
void Copy()
Definition: StdBuf.h:475

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Network2HTTPClient::SetNotify ( class C4InteractiveThread pnNotify)
inlineinherited

Definition at line 189 of file C4Network2Reference.h.

Referenced by C4StartupNetDlg::CheckVersionUpdate(), and C4StartupNetListEntry::SetRefQuery().

189 { pNotify = pnNotify; }

Here is the caller graph for this function:

bool C4Network2HTTPClient::SetServer ( const char *  szServerAddress)
inherited

Definition at line 566 of file C4Network2Reference.cpp.

References C4NetIO::EndpointAddress::Clear(), StdStrBuf::CopyUntil(), FormatString(), StdStrBuf::getData(), C4Network2HTTPClient::GetDefaultPort(), C4NetIO::HostAddress::GetFamily(), C4NetIO::HostAddress::IPv4, C4NetIO::HostAddress::IPv6, C4NetIO::EndpointAddress::IsNull(), C4NetIO::ResetError(), C4NetIO::EndpointAddress::SetAddress(), C4NetIO::EndpointAddress::SetDefaultPort(), C4NetIO::SetError(), and StdStrBuf::SetLength().

Referenced by C4StartupNetDlg::CheckVersionUpdate(), C4Network2::InitLeague(), C4Game::InitNetworkFromAddress(), C4StartupNetListEntry::SetRefQuery(), C4DownloadDlg::ShowModal(), and C4Network2::StreamOut().

567 {
568  // Split address
569  const char *pRequestPath;
570  if ((pRequestPath = strchr(szServerAddress, '/')))
571  {
572  Server.CopyUntil(szServerAddress, '/');
573  RequestPath = pRequestPath;
574  }
575  else
576  {
577  Server = szServerAddress;
578  RequestPath = "/";
579  }
580  // Resolve address
581  ServerAddr.SetAddress(Server);
582  if (ServerAddr.IsNull())
583  {
584  SetError(FormatString("Could not resolve server address %s!", Server.getData()).getData());
585  return false;
586  }
587  ServerAddr.SetDefaultPort(GetDefaultPort());
588  if (ServerAddr.GetFamily() == C4NetIO::HostAddress::IPv6)
589  {
590  // Try to find a fallback IPv4 address for Happy Eyeballs.
591  ServerAddrFallback.SetAddress(Server, C4NetIO::HostAddress::IPv4);
592  ServerAddrFallback.SetDefaultPort(GetDefaultPort());
593  }
594  else
595  ServerAddrFallback.Clear();
596  // Remove port
597  const char *firstColon = strchr(Server.getData(), ':');
598  const char *lastColon = strrchr(Server.getData(), ':');
599  if (firstColon)
600  // hostname/IPv4 address or IPv6 address with port (e.g. [::1]:1234)
601  if (firstColon == lastColon || (Server[0] == '[' && *(lastColon - 1) == ']'))
602  Server.SetLength(lastColon - Server.getData());
603 
604  // Done
605  ResetError();
606  return true;
607 }
const char * getData() const
Definition: StdBuf.h:450
void ResetError()
Definition: C4NetIO.h:286
void SetError(const char *strnError, bool fSockErr=false)
Definition: C4NetIO.cpp:754
virtual int32_t GetDefaultPort()
void SetAddress(const sockaddr *addr)
Definition: C4NetIO.cpp:370
AddressFamily GetFamily() const
Definition: C4NetIO.cpp:526
void CopyUntil(const char *szString, char cUntil)
Definition: StdBuf.h:621
bool IsNull() const
Definition: C4NetIO.cpp:509
void SetLength(size_t iLength)
Definition: StdBuf.h:517
void SetDefaultPort(uint16_t port)
Definition: C4NetIO.cpp:542
StdStrBuf FormatString(const char *szFmt,...)
Definition: StdBuf.cpp:277

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4LeagueClient::Start ( const C4Network2Reference Ref)

Definition at line 299 of file C4League.cpp.

References C4LA_Start, StdStrBuf::getData(), mkDecompileAdapt(), mkInsertAdapt(), mkNamingAdapt(), and C4Network2HTTPClient::Query().

Referenced by C4Network2::LeagueStart().

300 {
301  // Create query
302  eCurrAction = C4LA_Start;
303  C4LeagueRequestHead Head(eCurrAction);
304  StdStrBuf QueryText = DecompileToBuf<StdCompilerINIWrite>(
306  mkNamingAdapt(Head, "Request"),
307  mkNamingAdapt(mkDecompileAdapt(Ref), "Reference"),
308  false));
309  // Perform query
310  return Query(QueryText.getData(), false);
311 }
const char * getData() const
Definition: StdBuf.h:450
StdNamingAdapt< T > mkNamingAdapt(T &&rValue, const char *szName)
Definition: StdAdaptors.h:93
StdDecompileAdapt< T > mkDecompileAdapt(const T &rValue)
Definition: StdAdaptors.h:154
StdInsertAdapt< T, I > mkInsertAdapt(T &&rObj, I &&rIns, bool fBefore=true)
Definition: StdAdaptors.h:438
bool Query(const StdBuf &Data, bool fBinary)

Here is the call graph for this function:

Here is the caller graph for this function:

virtual uint32_t StdSchedulerProc::TimerInterval ( )
inlinevirtualinherited

Reimplemented in CStdTimerProc.

Definition at line 88 of file StdScheduler.h.

Referenced by SCHAdditions::assignAdditionForProc:.

88 { return 0; }

Here is the caller graph for this function:

void C4NetIOTCP::UnBlock ( )
virtualinherited

Definition at line 1299 of file C4NetIO.cpp.

References C4NetIOTCP::Pipe, and C4NetIO::SetError().

Referenced by C4NetIOTCP::AddConnectWait().

1300 {
1301 #ifdef STDSCHEDULER_USE_EVENTS
1302  // unblock WaitForSingleObject in C4NetIOTCP::Execute manually
1303  // by setting the Event
1304  WSASetEvent(Event);
1305 #else
1306  // write one character to the pipe, this will unblock everything that
1307  // waits for the FD set returned by GetFDs.
1308  char c = 1;
1309  if (write(Pipe[1], &c, 1) == -1)
1310  SetError("write failed");
1311 #endif
1312 }
void SetError(const char *strnError, bool fSockErr=false)
Definition: C4NetIO.cpp:754
int Pipe[2]
Definition: C4NetIO.h:470

Here is the call graph for this function:

Here is the caller graph for this function:

size_t C4Network2HTTPClient::UnpackPacket ( const StdBuf rInBuf,
const C4NetIO::addr_t addr 
)
protectedvirtualinherited

Reimplemented from C4NetIOTCP.

Definition at line 268 of file C4Network2Reference.cpp.

References C4NetIOTCP::Close(), StdBuf::Copy(), StdStrBuf::Copy(), StdStrBuf::getData(), StdBuf::getPart(), StdBuf::getSize(), C4Network2HTTPClient::OnPacket(), C4Network2HTTPClient::ResetRequestTimeout(), C4Network2HTTPClient::ResultBin, C4Network2HTTPClient::ResultString, and SSearch().

269 {
270  // since new data arrived, increase timeout time
272  // Check for complete header
273  if (!iDataOffset)
274  {
275  // Copy data into string buffer (terminate)
276  StdStrBuf Data; Data.Copy(getBufPtr<char>(rInBuf), rInBuf.getSize());
277  const char *pData = Data.getData();
278  // Header complete?
279  const char *pContent = SSearch(pData, "\r\n\r\n");
280  if (!pContent)
281  return 0;
282  // Read the header
283  if (!ReadHeader(Data))
284  {
285  fBusy = fSuccess = false;
286  Close(addr);
287  return rInBuf.getSize();
288  }
289  }
290  iDownloadedSize = rInBuf.getSize() - iDataOffset;
291  // Check if the packet is complete
292  if (iTotalSize > iDownloadedSize)
293  {
294  return 0;
295  }
296  // Get data, uncompress it if needed
297  StdBuf Data = rInBuf.getPart(iDataOffset, iTotalSize);
298  if (fCompressed)
299  if (!Decompress(&Data))
300  {
301  fBusy = fSuccess = false;
302  Close(addr);
303  return rInBuf.getSize();
304  }
305  // Save the result
306  if (fBinary)
307  ResultBin.Copy(Data);
308  else
309  ResultString.Copy(getBufPtr<char>(Data), Data.getSize());
310  fBusy = false; fSuccess = true;
311  // Callback
312  OnPacket(C4NetIOPacket(Data, addr), this);
313  // Done
314  Close(addr);
315  return rInBuf.getSize();
316 }
const char * getData() const
Definition: StdBuf.h:450
Definition: StdBuf.h:37
const char * SSearch(const char *szString, const char *szIndex)
Definition: Standard.cpp:340
size_t getSize() const
Definition: StdBuf.h:109
StdBuf getPart(size_t iStart, size_t inSize) const
Definition: StdBuf.h:115
void OnPacket(const class C4NetIOPacket &rPacket, C4NetIO *pNetIO)
void Copy(size_t inSize)
Definition: StdBuf.h:233
virtual bool Close()
Definition: C4NetIO.cpp:870
void Copy()
Definition: StdBuf.h:475

Here is the call graph for this function:

bool C4LeagueClient::Update ( const C4Network2Reference Ref)

Definition at line 346 of file C4League.cpp.

References C4LA_Update, StdStrBuf::getData(), StdStrBuf::getLength(), mkDecompileAdapt(), mkInsertAdapt(), mkNamingAdapt(), and C4Network2HTTPClient::Query().

Referenced by C4Network2::LeagueUpdate().

347 {
348  assert(CSID.getLength());
349  // Create query
350  eCurrAction = C4LA_Update;
351  C4LeagueRequestHead Head(eCurrAction, CSID.getData());
352  StdStrBuf QueryText = DecompileToBuf<StdCompilerINIWrite>(
354  mkNamingAdapt(Head, "Request"),
355  mkNamingAdapt(mkDecompileAdapt(Ref), "Reference"),
356  false));
357  // Perform query
358  return Query(QueryText.getData(), false);
359 }
const char * getData() const
Definition: StdBuf.h:450
StdNamingAdapt< T > mkNamingAdapt(T &&rValue, const char *szName)
Definition: StdAdaptors.h:93
StdDecompileAdapt< T > mkDecompileAdapt(const T &rValue)
Definition: StdAdaptors.h:154
StdInsertAdapt< T, I > mkInsertAdapt(T &&rObj, I &&rIns, bool fBefore=true)
Definition: StdAdaptors.h:438
size_t getLength() const
Definition: StdBuf.h:453
bool Query(const StdBuf &Data, bool fBinary)

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

bool C4NetIOTCP::fInit
protectedinherited

Definition at line 459 of file C4NetIO.h.

Referenced by C4NetIOTCP::Close(), C4NetIOTCP::Execute(), and C4NetIOTCP::Init().

uint16_t C4NetIOTCP::iListenPort
protectedinherited

Definition at line 462 of file C4NetIO.h.

Referenced by C4NetIOTCP::Execute(), and C4NetIOTCP::Listen().

SOCKET C4NetIOTCP::lsock
protectedinherited
CStdCSec C4NetIOTCP::PeerListAddCSec
protectedinherited

Definition at line 456 of file C4NetIO.h.

Referenced by C4NetIOTCP::Accept(), and C4NetIOTCP::AddConnectWait().

int C4NetIOTCP::Pipe[2]
protectedinherited
StdCopyBuf C4Network2HTTPClient::ResultBin
protectedinherited
const int C4NetIO::TO_INF = -1
staticinherited

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