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

#include <C4Network2IRC.h>

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

Public Types

typedef EndpointAddress addr_t
 

Public Member Functions

 C4Network2IRCClient ()
 
 ~C4Network2IRCClient () override
 
CStdCSecgetCSec ()
 
C4Network2IRCChannelgetFirstChannel () const
 
C4Network2IRCChannelgetNextChannel (C4Network2IRCChannel *pPrevChan) const
 
C4Network2IRCChannelgetChannel (const char *szName) const
 
C4Network2IRCMessagegetMessageLog () const
 
C4Network2IRCMessagegetUnreadMessageLog () const
 
void ClearMessageLog ()
 
void MarkMessageLogRead ()
 
const char * getUserName () const
 
bool Connect (const char *szServer, const char *szNick, const char *szRealName, const char *szPassword=nullptr, const char *szChannel=nullptr)
 
bool Close () override
 
bool Send (const char *szCommand, const char *szParameters=nullptr)
 
void SetNotify (class C4InteractiveThread *pnNotify)
 
bool Quit (const char *szReason)
 
bool Join (const char *szChannel)
 
bool Part (const char *szChannel)
 
bool Message (const char *szTarget, const char *szText)
 
bool Notice (const char *szTarget, const char *szText)
 
bool Action (const char *szTarget, const char *szText)
 
bool ChangeNick (const char *szNewNick)
 
bool RegisterNick (const char *szPassword, const char *szMail)
 
bool IsActive () const
 
bool IsConnected () const
 
bool Init (uint16_t iPort=addr_t::IPPORT_NONE) override
 
virtual bool InitBroadcast (addr_t *pBroadcastAddr)
 
bool Close (const addr_t &addr) override
 
virtual bool CloseBroadcast ()
 
bool Execute (int iMaxTime=TO_INF, pollfd *readyfds=nullptr) override
 
bool Connect (const addr_t &addr) override
 
bool Send (const C4NetIOPacket &rPacket) override
 
virtual bool Send (const class C4NetIOPacket &rPacket)=0
 
bool Broadcast (const C4NetIOPacket &rPacket) override
 
virtual bool Broadcast (const class C4NetIOPacket &rPacket)=0
 
bool SetBroadcast (const addr_t &addr, bool fSet=true) override
 
virtual void UnBlock ()
 
void GetFDs (std::vector< struct pollfd > &FDs) override
 
bool GetStatistic (int *pBroadcastRate) override
 
bool GetConnStatistic (const addr_t &addr, int *pIRate, int *pORate, int *pLoss) override
 
void ClearStatistic () override
 
void SetCallback (CBClass *pnCallback) override
 
virtual void SetCallback (CBClass *pnCallback)=0
 
bool IsNotify () override
 
virtual const char * GetError () const
 
void ResetError ()
 
bool ExecuteUntil (int iTimeout=-1)
 
virtual C4TimeMilliseconds GetNextTick (C4TimeMilliseconds tNow)
 
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

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) override
 
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

PeerpPeerList {nullptr}
 
struct C4NetIOTCP::ConnectWait nullptr
 
CStdCSecEx PeerListCSec
 
CStdCSec PeerListAddCSec
 
bool fInit {false}
 
uint16_t iListenPort
 
SOCKET lsock
 
int Pipe [2]
 
StdCopyStrBuf Error
 

Detailed Description

Definition at line 122 of file C4Network2IRC.h.

Member Typedef Documentation

typedef EndpointAddress C4NetIO::addr_t
inherited

Definition at line 211 of file C4NetIO.h.

Constructor & Destructor Documentation

C4Network2IRCClient::C4Network2IRCClient ( )
default
C4Network2IRCClient::~C4Network2IRCClient ( )
override

Definition at line 182 of file C4Network2IRC.cpp.

References Close().

183 {
184  Close();
185 }
bool Close() override

Here is the call graph for this function:

Member Function Documentation

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

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

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

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Network2IRCClient::Action ( const char *  szTarget,
const char *  szText 
)

Definition at line 422 of file C4Network2IRC.cpp.

References FormatString(), StdStrBuf::getData(), MSG_Action, and Send().

Referenced by C4ChatControl::ProcessInput().

423 {
424  if (!Send("PRIVMSG", FormatString("%s :\1ACTION %s\1", szTarget, szText).getData()))
425  return false;
426  PushMessage(MSG_Action, Nick.getData(), szTarget, szText);
427  return true;
428 }
const char * getData() const
Definition: StdBuf.h:442
bool Send(const char *szCommand, const char *szParameters=nullptr)
StdStrBuf FormatString(const char *szFmt,...)
Definition: StdBuf.cpp:270

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 1589 of file C4NetIO.cpp.

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

Referenced by C4NetIOTCP::Connect().

1590 {
1591  CStdShareLock PeerListLock(&PeerListCSec);
1592  CStdLock PeerListAddLock(&PeerListAddCSec);
1593  // create new entry, add to list
1594  ConnectWait *pnWait = new ConnectWait;
1595  pnWait->sock = sock; pnWait->addr = addr;
1596  pnWait->Next = pConnectWaits;
1597  pConnectWaits = pnWait;
1598 #ifndef STDSCHEDULER_USE_EVENTS
1599  // unblock, so new FD can be realized
1600  UnBlock();
1601 #endif
1602  Changed();
1603 }
virtual void UnBlock()
Definition: C4NetIO.cpp:1281
CStdCSecEx PeerListCSec
Definition: C4NetIO.h:454
CStdCSec PeerListAddCSec
Definition: C4NetIO.h:455

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)
overrideinherited

Definition at line 1270 of file C4NetIO.cpp.

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

1271 {
1272  CStdShareLock PeerListLock(&PeerListCSec);
1273  // just send to all clients
1274  bool fSuccess = true;
1275  for (Peer *pPeer = pPeerList; pPeer; pPeer = pPeer->Next)
1276  if (pPeer->Open() && pPeer->doBroadcast())
1277  fSuccess &= Send(C4NetIOPacket(rPacket.getRef(), pPeer->GetAddr()));
1278  return fSuccess;
1279 }
bool Send(const C4NetIOPacket &rPacket) override
Definition: C4NetIO.cpp:1248
C4NetIOPacket getRef() const
Definition: C4NetIO.h:323
Peer * pPeerList
Definition: C4NetIO.h:442
CStdCSecEx PeerListCSec
Definition: C4NetIO.h:454
friend class Peer
Definition: C4NetIO.h:440

Here is the call graph for this function:

void StdSchedulerProc::Changed ( )
protectedinherited

Definition at line 108 of file StdScheduler.cpp.

References s.

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

109 {
110  auto s = scheduler;
111  if (s)
112  s->Changed(this);
113 }
#define s

Here is the caller graph for this function:

bool C4Network2IRCClient::ChangeNick ( const char *  szNewNick)

Definition at line 430 of file C4Network2IRC.cpp.

References Send().

Referenced by C4ChatControl::ProcessInput().

431 {
432  return Send("NICK", szNewNick);
433 }
bool Send(const char *szCommand, const char *szParameters=nullptr)

Here is the call graph for this function:

Here is the caller graph for this function:

void C4NetIOTCP::ClearConnectWaits ( )
protectedinherited

Definition at line 1615 of file C4NetIO.cpp.

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

Referenced by C4NetIOTCP::Close().

1616 {
1617  CStdShareLock PeerListLock(&PeerListCSec);
1618  for (ConnectWait *pWait = pConnectWaits; pWait; pWait = pWait->Next)
1619  if (pWait->sock)
1620  {
1621  closesocket(pWait->sock);
1622  pWait->sock = 0;
1623  }
1624 }
CStdCSecEx PeerListCSec
Definition: C4NetIO.h:454
#define closesocket
Definition: C4NetIO.cpp:46

Here is the caller graph for this function:

void C4Network2IRCClient::ClearMessageLog ( )

Definition at line 284 of file C4Network2IRC.cpp.

Referenced by Close().

285 {
286  // Clear log
287  while (iLogLength)
288  PopMessage();
289 }

Here is the caller graph for this function:

void C4NetIOTCP::ClearStatistic ( )
overridevirtualinherited

Implements C4NetIO.

Definition at line 1357 of file C4NetIO.cpp.

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

1358 {
1359  CStdShareLock PeerListLock(&PeerListCSec);
1360  // clear all peer statistics
1361  for (Peer *pPeer = pPeerList; pPeer; pPeer = pPeer->Next)
1362  pPeer->ClearStatistics();
1363 }
Peer * pPeerList
Definition: C4NetIO.h:442
CStdCSecEx PeerListCSec
Definition: C4NetIO.h:454
friend class Peer
Definition: C4NetIO.h:440
bool C4Network2IRCClient::Close ( )
overridevirtual

Reimplemented from C4NetIOTCP.

Definition at line 331 of file C4Network2IRC.cpp.

References StdStrBuf::Append(), C4ConfigIRC::Channel, ClearMessageLog(), C4NetIOTCP::Close(), Config, StdStrBuf::getData(), C4Network2IRCChannel::getName(), and C4Config::IRC.

Referenced by C4Application::Clear(), Connect(), Quit(), C4ChatDlg::StopChat(), C4ChatControl::UserQueryQuit(), and ~C4Network2IRCClient().

332 {
333  // Close network
335  // Save & Clear channels
336  if(pChannels) // Don't override empty
337  {
338  // It's somewhat weird to loop backward through a singly linked list, but it's necessary to keep the order
339  StdStrBuf chanstr;
340  C4Network2IRCChannel * pChan = pChannels;
341  while(pChan->Next)
342  pChan = pChan->Next;
343  chanstr.Append(pChan->getName());
344  while (pChan != pChannels)
345  {
346  C4Network2IRCChannel * pChanPrev = pChannels;
347  while(pChanPrev->Next != pChan)
348  pChanPrev = pChanPrev->Next;
349  pChan = pChanPrev;
350  chanstr.Append(",");
351  chanstr.Append(pChan->getName());
352  }
353  strncpy(Config.IRC.Channel, chanstr.getData(), sizeof(Config.IRC.Channel)-1);
354  }
355  while (pChannels)
356  DeleteChannel(pChannels);
357  // Clear log
358  ClearMessageLog();
359  // Reset flags
360  fConnected = fConnecting = false;
361  return true;
362 }
const char * getData() const
Definition: StdBuf.h:442
C4Config Config
Definition: C4Config.cpp:833
const char * getName() const
void Append(const char *pnData, size_t iChars)
Definition: StdBuf.h:519
C4ConfigIRC IRC
Definition: C4Config.h:257
bool Close() override
Definition: C4NetIO.cpp:852
char Channel[CFG_MaxString+1]
Definition: C4Config.h:208

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4NetIOTCP::Close ( const addr_t addr)
overridevirtualinherited

Implements C4NetIO.

Reimplemented in C4AulDebug.

Definition at line 1217 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.

1218 {
1219  CStdShareLock PeerListLock(&PeerListCSec);
1220  // find connect wait
1221  ConnectWait *pWait = GetConnectWait(addr);
1222  if (pWait)
1223  {
1224  // close socket, do callback
1225  closesocket(pWait->sock); pWait->sock = 0;
1226  if (pCB) pCB->OnDisconn(pWait->addr, this, "closed");
1227  }
1228  else
1229  {
1230  // find peer
1231  Peer *pPeer = GetPeer(addr);
1232  if (pPeer)
1233  {
1234  C4NetIO::addr_t addr = pPeer->GetAddr();
1235  // close peer
1236  pPeer->Close();
1237  // do callback
1238  if (pCB) pCB->OnDisconn(addr, this, "closed");
1239  }
1240  // not found
1241  else
1242  return false;
1243  }
1244  // ok
1245  return true;
1246 }
CStdCSecEx PeerListCSec
Definition: C4NetIO.h:454
Peer * GetPeer(const addr_t &addr)
Definition: C4NetIO.cpp:1531
friend class Peer
Definition: C4NetIO.h:440
#define closesocket
Definition: C4NetIO.cpp:46
virtual void OnDisconn(const addr_t &AddrPeer, C4NetIO *pNetIO, const char *szReason)
Definition: C4NetIO.h:220
ConnectWait * GetConnectWait(const addr_t &addr)
Definition: C4NetIO.cpp:1605

Here is the call graph for this function:

bool C4NetIOTCP::CloseBroadcast ( )
virtualinherited

Definition at line 900 of file C4NetIO.cpp.

901 {
902  return true;
903 }
bool C4Network2IRCClient::Connect ( const char *  szServer,
const char *  szNick,
const char *  szRealName,
const char *  szPassword = nullptr,
const char *  szChannel = nullptr 
)

Definition at line 301 of file C4Network2IRC.cpp.

References Close(), C4NetIOTCP::Connect(), StdStrBuf::getLength(), C4NetIOTCP::Init(), C4NetIO::EndpointAddress::IsNull(), C4NetIO::EndpointAddress::SetAddress(), C4NetIOTCP::SetCallback(), C4NetIO::EndpointAddress::SetDefaultPort(), C4NetIO::SetError(), and StdStrBuf::SetLength().

Referenced by C4ChatControl::OnConnectBtn().

302 {
303  // Already connected? Close connection
304  if (fConnecting || fConnected)
305  Close();
306  // Initialize
308  if (!Init())
309  return false;
310  // Resolve address
311  ServerAddr.SetAddress(StdStrBuf(szServer));
312  if (ServerAddr.IsNull())
313  { SetError("Could no resolve server address!"); return false; }
314  ServerAddr.SetDefaultPort(6666);
315  // Set connection data
316  Nick = szNick; RealName = szRealName;
317  Password = szPassword; AutoJoin = szAutoJoin;
318  // Truncate password
319  if (Password.getLength() > 31)
320  Password.SetLength(31);
321  // Start connecting
322  if (!C4NetIOTCP::Connect(ServerAddr))
323  return false;
324  // Reset status data
325  Prefixes = "(ov)@+";
326  // Okay, let's wait for the connection.
327  fConnecting = true;
328  return true;
329 }
void SetError(const char *strnError, bool fSockErr=false)
Definition: C4NetIO.cpp:745
void SetCallback(CBClass *pnCallback) override
Definition: C4NetIO.h:486
void SetAddress(const sockaddr *addr)
Definition: C4NetIO.cpp:364
bool Close() override
bool Init(uint16_t iPort=addr_t::IPPORT_NONE) override
Definition: C4NetIO.cpp:806
bool IsNull() const
Definition: C4NetIO.cpp:503
size_t getLength() const
Definition: StdBuf.h:445
void SetLength(size_t iLength)
Definition: StdBuf.h:509
void SetDefaultPort(uint16_t port)
Definition: C4NetIO.cpp:536
bool Connect(const addr_t &addr) override
Definition: C4NetIO.cpp:1149

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4NetIOTCP::Connect ( const addr_t addr)
overridevirtualinherited

Implements C4NetIO.

Definition at line 1149 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 Connect(), C4Network2HTTPClient::Execute(), main(), and C4Network2HTTPClient::Query().

1150 {
1151  // create new socket
1152  SOCKET nsock = ::socket(addr.GetFamily() == HostAddress::IPv6 ? AF_INET6 : AF_INET, SOCK_STREAM | SOCK_CLOEXEC, IPPROTO_TCP);
1153  if (nsock == INVALID_SOCKET)
1154  {
1155  SetError("socket creation failed", true);
1156  return false;
1157  }
1158 
1159  if (addr.GetFamily() == HostAddress::IPv6)
1160  if (!InitIPv6Socket(nsock))
1161  return false;
1162 
1163 #ifdef STDSCHEDULER_USE_EVENTS
1164  // set event
1165  if (::WSAEventSelect(nsock, Event, FD_CONNECT) == SOCKET_ERROR)
1166  {
1167  // set error
1168  SetError("connect failed: could not set event", true);
1169  closesocket(nsock);
1170  return false;
1171  }
1172 
1173  // add to list
1174  AddConnectWait(nsock, addr);
1175 
1176 #elif defined(HAVE_WINSOCK)
1177  // disable blocking
1178  unsigned long iBlock = 1;
1179  if (::ioctlsocket(nsock, FIONBIO, &iBlock) == SOCKET_ERROR)
1180  {
1181  // set error
1182  SetError("connect failed: could not disable blocking", true);
1183  close(nsock);
1184  return false;
1185  }
1186 #else
1187  // disable blocking
1188  if (::fcntl(nsock, F_SETFL, fcntl(nsock, F_GETFL) | O_NONBLOCK) == SOCKET_ERROR)
1189  {
1190  // set error
1191  SetError("connect failed: could not disable blocking", true);
1192  close(nsock);
1193  return false;
1194  }
1195 #endif
1196 
1197  // connect (async)
1198  if (::connect(nsock, &addr, sizeof addr) == SOCKET_ERROR)
1199  {
1200  if (!HaveWouldBlockError()) // expected
1201  {
1202  SetError("socket connection failed", true);
1203  closesocket(nsock);
1204  return false;
1205  }
1206  }
1207 
1208 #ifndef STDSCHEDULER_USE_EVENTS
1209  // add to list
1210  AddConnectWait(nsock, addr);
1211 #endif
1212 
1213  // ok
1214  return true;
1215 }
#define INVALID_SOCKET
Definition: C4NetIO.h:36
void SetError(const char *strnError, bool fSockErr=false)
Definition: C4NetIO.cpp:745
#define ioctlsocket
Definition: C4NetIO.cpp:45
bool InitIPv6Socket(SOCKET socket)
Definition: C4NetIO.cpp:725
void AddConnectWait(SOCKET sock, const addr_t &addr)
Definition: C4NetIO.cpp:1589
#define SOCKET
Definition: C4NetIO.h:35
bool HaveWouldBlockError()
Definition: C4NetIO.cpp:203
#define SOCK_CLOEXEC
Definition: C4NetIO.h:50
#define closesocket
Definition: C4NetIO.cpp:46
#define SOCKET_ERROR
Definition: C4NetIO.cpp:47

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4NetIOTCP::Execute ( int  iMaxTime = TO_INF,
pollfd *  readyfds = nullptr 
)
overridevirtualinherited

Implements C4NetIO.

Reimplemented in C4Network2HTTPClient.

Definition at line 914 of file C4NetIO.cpp.

References C4NetIOTCP::Accept(), C4NetIOTCP::fInit, C4NetIOTCP::GetFDs(), GetSocketErrorMsg(), HaveWouldBlockError(), C4NetIOTCP::iListenPort, INFINITE, INVALID_SOCKET, ioctlsocket, C4NetIOTCP::Listen(), C4NetIOTCP::lsock, C4NetIOTCP::Peer::Next, C4NetIO::CBClass::OnDisconn(), C4NetIOTCP::PeerListCSec, C4NetIOTCP::Pipe, C4NetIOTCP::pPeerList, ResetSocketError(), C4NetIO::SetError(), SOCKET, SOCKET_ERROR, and C4NetIO::TO_INF.

Referenced by C4AulDebug::DebugStep(), and C4Network2HTTPClient::Execute().

915 {
916  // security
917  if (!fInit) return false;
918 
919 #ifdef STDSCHEDULER_USE_EVENTS
920  // wait for something to happen
921  if (WaitForSingleObject(Event, iMaxTime == C4NetIO::TO_INF ? INFINITE : iMaxTime) == WAIT_TIMEOUT)
922  // timeout -> nothing happened
923  return true;
924  WSAResetEvent(Event);
925 
926  WSANETWORKEVENTS wsaEvents;
927 #else
928 
929 #ifdef __APPLE__
930  iMaxTime = fix_poll_timeout(iMaxTime);
931 #endif
932 
933  std::vector<pollfd> fdvec;
934  std::map<SOCKET, const pollfd*> fdmap;
935  if (!fds)
936  {
937  // build socket sets
938  GetFDs(fdvec);
939  fds = &fdvec[0];
940  // wait for something to happen
941  int ret = poll(fds, fdvec.size(), iMaxTime);
942  // error
943  if (ret < 0)
944  {
945  SetError("poll failed");
946  return false;
947  }
948  // nothing happened
949  if (ret == 0)
950  return true;
951  }
952  else
953  {
954  // We need to know the size of fdvec, so construct the vector
955  GetFDs(fdvec);
956  // Now overwrite with the poll result
957  std::copy(fds, fds + fdvec.size(), fdvec.begin());
958  }
959 
960  // flush pipe
961  assert(fdvec[0].fd == Pipe[0]);
962  if (fdvec[0].events & fdvec[0].revents)
963  {
964  char c;
965  if (::read(Pipe[0], &c, 1) == -1)
966  SetError("read failed");
967  }
968 
969  for (std::vector<pollfd>::const_iterator i = fdvec.begin(); i != fdvec.end(); ++i)
970  fdmap[i->fd] = &*i;
971  std::map<SOCKET, const pollfd*>::const_iterator cur_fd;
972 #endif
973 
974  // check sockets for events
975 
976  // first: the listen socket
977  if (lsock != INVALID_SOCKET)
978  {
979 
980 #ifdef STDSCHEDULER_USE_EVENTS
981  // get event list
982  if (::WSAEnumNetworkEvents(lsock, nullptr, &wsaEvents) == SOCKET_ERROR)
983  return false;
984 
985  // a connection waiting for accept?
986  if (wsaEvents.lNetworkEvents & FD_ACCEPT)
987 #else
988  cur_fd = fdmap.find(lsock);
989  // a connection waiting for accept?
990  if (cur_fd != fdmap.end() && (cur_fd->second->events & cur_fd->second->revents))
991 #endif
992  if (!Accept())
993  return false;
994  // (note: what happens if there are more connections waiting?)
995 
996 #ifdef STDSCHEDULER_USE_EVENTS
997  // closed?
998  if (wsaEvents.lNetworkEvents & FD_CLOSE)
999  // try to recreate the listen socket
1001 #endif
1002  }
1003 
1004  // second: waited-for connection
1005  CStdShareLock PeerListLock(&PeerListCSec);
1006  for (ConnectWait *pWait = pConnectWaits, *pNext; pWait; pWait = pNext)
1007  {
1008  pNext = pWait->Next;
1009 
1010  // not closed?
1011  if (pWait->sock)
1012  {
1013 #ifdef STDSCHEDULER_USE_EVENTS
1014  // get event list
1015  if (::WSAEnumNetworkEvents(pWait->sock, nullptr, &wsaEvents) == SOCKET_ERROR)
1016  return false;
1017 
1018  if (wsaEvents.lNetworkEvents & FD_CONNECT)
1019 #else
1020  // got connection?
1021  cur_fd = fdmap.find(pWait->sock);
1022  if (cur_fd != fdmap.end() && (cur_fd->second->events & cur_fd->second->revents))
1023 #endif
1024  {
1025  // remove from list
1026  SOCKET sock = pWait->sock; pWait->sock = 0;
1027 
1028 #ifdef STDSCHEDULER_USE_EVENTS
1029  // error?
1030  if (wsaEvents.iErrorCode[FD_CONNECT_BIT])
1031  {
1032  // disconnect-callback
1033  if (pCB) pCB->OnDisconn(pWait->addr, this, GetSocketErrorMsg(wsaEvents.iErrorCode[FD_CONNECT_BIT]));
1034  }
1035  else
1036 #else
1037  // get error code
1038  int iErrCode; socklen_t iErrCodeLen = sizeof(iErrCode);
1039  if (getsockopt(sock, SOL_SOCKET, SO_ERROR, reinterpret_cast<char *>(&iErrCode), &iErrCodeLen) != 0)
1040  {
1041  close(sock);
1042  if (pCB) pCB->OnDisconn(pWait->addr, this, GetSocketErrorMsg());
1043  }
1044  // error?
1045  else if (iErrCode)
1046  {
1047  close(sock);
1048  if (pCB) pCB->OnDisconn(pWait->addr, this, GetSocketErrorMsg(iErrCode));
1049  }
1050  else
1051 #endif
1052  // accept connection, do callback
1053  if (!Accept(sock, pWait->addr))
1054  return false;
1055  }
1056  }
1057 
1058  }
1059 
1060  // last: all connected sockets
1061  for (Peer *pPeer = pPeerList; pPeer; pPeer = pPeer->Next)
1062  if (pPeer->Open())
1063  {
1064  SOCKET sock = pPeer->GetSocket();
1065 
1066 #ifdef STDSCHEDULER_USE_EVENTS
1067  // get event list
1068  if (::WSAEnumNetworkEvents(sock, nullptr, &wsaEvents) == SOCKET_ERROR)
1069  return false;
1070 
1071  // something to read from socket?
1072  if (wsaEvents.lNetworkEvents & FD_READ)
1073 #else
1074  // something to read from socket?
1075  cur_fd = fdmap.find(sock);
1076  if (cur_fd != fdmap.end() && (POLLIN & cur_fd->second->revents))
1077 #endif
1078  for (;;)
1079  {
1080  // how much?
1081 #ifdef _WIN32
1082  DWORD iBytesToRead;
1083 #else
1084  int iBytesToRead;
1085 #endif
1086  if (::ioctlsocket(pPeer->GetSocket(), FIONREAD, &iBytesToRead) == SOCKET_ERROR)
1087  {
1088  pPeer->Close();
1089  if (pCB) pCB->OnDisconn(pPeer->GetAddr(), this, GetSocketErrorMsg());
1090  break;
1091  }
1092  // The following two lines of code will make sure that if the variable
1093  // "iBytesToRead" is zero, it will be increased by one.
1094  // In this case, it will hold the value 1 after the operation.
1095  // Note it doesn't do anything for negative values.
1096  // (This comment has been sponsored by Sven2)
1097  if (!iBytesToRead)
1098  ++iBytesToRead;
1099  // get buffer
1100  void *pBuf = pPeer->GetRecvBuf(iBytesToRead);
1101  // read a buffer full of data from socket
1102  int iBytesRead;
1103  if ((iBytesRead = ::recv(sock, reinterpret_cast<char *>(pBuf), iBytesToRead, 0)) == SOCKET_ERROR)
1104  {
1105  // Would block? Ok, let's try this again later
1106  if (HaveWouldBlockError()) { ResetSocketError(); break; }
1107  // So he's serious after all...
1108  pPeer->Close ();
1109  if (pCB) pCB->OnDisconn(pPeer->GetAddr(), this, GetSocketErrorMsg());
1110  break;
1111  }
1112  // nothing? this means the conection was closed, if you trust in linux manpages.
1113  if (!iBytesRead)
1114  {
1115  pPeer->Close();
1116  if (pCB) pCB->OnDisconn(pPeer->GetAddr(), this, "connection closed");
1117  break;
1118  }
1119  // pass to Peer::OnRecv
1120  pPeer->OnRecv(iBytesRead);
1121  }
1122 
1123  // socket has become writeable?
1124 #ifdef STDSCHEDULER_USE_EVENTS
1125  if (wsaEvents.lNetworkEvents & FD_WRITE)
1126 #else
1127  if (cur_fd != fdmap.end() && (POLLOUT & cur_fd->second->revents))
1128 #endif
1129  // send remaining data
1130  pPeer->Send();
1131 
1132 #ifdef STDSCHEDULER_USE_EVENTS
1133  // socket was closed?
1134  if (wsaEvents.lNetworkEvents & FD_CLOSE)
1135  {
1136  const char *szReason = wsaEvents.iErrorCode[FD_CLOSE_BIT] ? GetSocketErrorMsg(wsaEvents.iErrorCode[FD_CLOSE_BIT]) : "closed by peer";
1137  // close socket
1138  pPeer->Close();
1139  // do callback
1140  if (pCB) pCB->OnDisconn(pPeer->GetAddr(), this, szReason);
1141  }
1142 #endif
1143  }
1144 
1145  // done
1146  return true;
1147 }
#define INVALID_SOCKET
Definition: C4NetIO.h:36
const char * GetSocketErrorMsg(int iError)
Definition: C4NetIO.cpp:190
void SetError(const char *strnError, bool fSockErr=false)
Definition: C4NetIO.cpp:745
#define ioctlsocket
Definition: C4NetIO.cpp:45
bool Listen(uint16_t inListenPort)
Definition: C4NetIO.cpp:1476
Peer * pPeerList
Definition: C4NetIO.h:442
Peer * Accept(SOCKET nsock=INVALID_SOCKET, const addr_t &ConnectAddr=addr_t())
Definition: C4NetIO.cpp:1365
int Pipe[2]
Definition: C4NetIO.h:469
CStdCSecEx PeerListCSec
Definition: C4NetIO.h:454
void ResetSocketError()
Definition: C4NetIO.cpp:211
friend class Peer
Definition: C4NetIO.h:440
#define SOCKET
Definition: C4NetIO.h:35
void GetFDs(std::vector< struct pollfd > &FDs) override
Definition: C4NetIO.cpp:1302
bool HaveWouldBlockError()
Definition: C4NetIO.cpp:203
static const int TO_INF
Definition: C4NetIO.h:66
bool fInit
Definition: C4NetIO.h:458
SOCKET lsock
Definition: C4NetIO.h:462
virtual void OnDisconn(const addr_t &AddrPeer, C4NetIO *pNetIO, const char *szReason)
Definition: C4NetIO.h:220
#define INFINITE
Definition: StdSync.h:58
uint32_t DWORD
uint16_t iListenPort
Definition: C4NetIO.h:461
#define SOCKET_ERROR
Definition: C4NetIO.cpp:47

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 33 of file StdScheduler.cpp.

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

Referenced by main().

34 {
35  // Infinite?
36  if (iTimeout < 0)
37  for (;;)
38  if (!Execute())
39  return false;
40  // Calculate endpoint
41  C4TimeMilliseconds tStopTime = C4TimeMilliseconds::Now() + iTimeout;
42  for (;;)
43  {
44  // Call execute with given timeout
45  if (!Execute(std::max(iTimeout, 0)))
46  return false;
47  // Calculate timeout
49  if (tTime >= tStopTime)
50  break;
51  iTimeout = tStopTime - tTime;
52  }
53  // All ok.
54  return true;
55 }
virtual bool Execute(int iTimeout=-1, pollfd *readyfds=nullptr)=0
static C4TimeMilliseconds Now()

Here is the call graph for this function:

Here is the caller graph for this function:

C4Network2IRCChannel * C4Network2IRCClient::getChannel ( const char *  szName) const

Definition at line 276 of file C4Network2IRC.cpp.

References SEqualNoCase().

Referenced by C4ChatControl::Update().

277 {
278  for (C4Network2IRCChannel *pChan = pChannels; pChan; pChan = pChan->Next)
279  if (SEqualNoCase(pChan->getName(), szName))
280  return pChan;
281  return nullptr;
282 }
bool SEqualNoCase(const char *szStr1, const char *szStr2, int iLen)
Definition: Standard.cpp:207

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 1605 of file C4NetIO.cpp.

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

Referenced by C4NetIOTCP::Close().

1606 {
1607  CStdShareLock PeerListLock(&PeerListCSec);
1608  // search
1609  for (ConnectWait *pWait = pConnectWaits; pWait; pWait = pWait->Next)
1610  if (pWait->addr == addr)
1611  return pWait;
1612  return nullptr;
1613 }
CStdCSecEx PeerListCSec
Definition: C4NetIO.h:454

Here is the caller graph for this function:

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

Implements C4NetIO.

Definition at line 1344 of file C4NetIO.cpp.

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

1345 {
1346  CStdShareLock PeerListLock(&PeerListCSec);
1347  // find peer
1348  Peer *pPeer = GetPeer(addr);
1349  if (!pPeer || !pPeer->Open()) return false;
1350  // return statistics
1351  if (pIRate) *pIRate = pPeer->GetIRate();
1352  if (pORate) *pORate = pPeer->GetORate();
1353  if (pLoss) *pLoss = 0;
1354  return true;
1355 }
CStdCSecEx PeerListCSec
Definition: C4NetIO.h:454
Peer * GetPeer(const addr_t &addr)
Definition: C4NetIO.cpp:1531
friend class Peer
Definition: C4NetIO.h:440

Here is the call graph for this function:

CStdCSec* C4Network2IRCClient::getCSec ( )
inline

Definition at line 165 of file C4Network2IRC.h.

Referenced by C4ChatControl::ProcessInput(), and C4ChatControl::Update().

165 { return &CSec; }

Here is the caller graph for this function:

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

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

284 { return Error.getData(); }
const char * getData() const
Definition: StdBuf.h:442
StdCopyStrBuf Error
Definition: C4NetIO.h:281

Here is the call graph for this function:

Here is the caller graph for this function:

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

Reimplemented from StdSchedulerProc.

Definition at line 1302 of file C4NetIO.cpp.

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

Referenced by C4NetIOTCP::Execute().

1303 {
1304  pollfd pfd; pfd.revents = 0;
1305  // add pipe
1306  pfd.fd = Pipe[0]; pfd.events = POLLIN;
1307  fds.push_back(pfd);
1308  // add listener
1309  if (lsock != INVALID_SOCKET)
1310  {
1311  pfd.fd = lsock; pfd.events = POLLIN;
1312  fds.push_back(pfd);
1313  }
1314  // add connect waits (wait for them to become writeable)
1315  CStdShareLock PeerListLock(&PeerListCSec);
1316  for (ConnectWait *pWait = pConnectWaits; pWait; pWait = pWait->Next)
1317  {
1318  pfd.fd = pWait->sock; pfd.events = POLLOUT;
1319  fds.push_back(pfd);
1320  }
1321  // add sockets
1322  for (Peer *pPeer = pPeerList; pPeer; pPeer = pPeer->Next)
1323  if (pPeer->GetSocket())
1324  {
1325  // Wait for socket to become readable
1326  pfd.fd = pPeer->GetSocket(); pfd.events = POLLIN;
1327  // Wait for socket to become writeable, if there is data waiting
1328  if (pPeer->hasWaitingData())
1329  {
1330  pfd.events |= POLLOUT;
1331  }
1332  fds.push_back(pfd);
1333  }
1334 }
#define INVALID_SOCKET
Definition: C4NetIO.h:36
Peer * pPeerList
Definition: C4NetIO.h:442
int Pipe[2]
Definition: C4NetIO.h:469
CStdCSecEx PeerListCSec
Definition: C4NetIO.h:454
friend class Peer
Definition: C4NetIO.h:440
SOCKET lsock
Definition: C4NetIO.h:462

Here is the caller graph for this function:

C4Network2IRCChannel * C4Network2IRCClient::getFirstChannel ( ) const

Definition at line 266 of file C4Network2IRC.cpp.

Referenced by C4ChatControl::Update().

267 {
268  return pChannels;
269 }

Here is the caller graph for this function:

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

Definition at line 626 of file C4NetIO.cpp.

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

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

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

Here is the call graph for this function:

Here is the caller graph for this function:

C4Network2IRCMessage* C4Network2IRCClient::getMessageLog ( ) const
inline

Definition at line 171 of file C4Network2IRC.h.

Referenced by C4ChatControl::Update().

171 { return pLog; }

Here is the caller graph for this function:

C4Network2IRCChannel * C4Network2IRCClient::getNextChannel ( C4Network2IRCChannel pPrevChan) const

Definition at line 271 of file C4Network2IRC.cpp.

Referenced by C4ChatControl::Update().

272 {
273  return pPrevChan ? pPrevChan->Next : pChannels;
274 }

Here is the caller graph for this function:

C4TimeMilliseconds StdSchedulerProc::GetNextTick ( C4TimeMilliseconds  tNow)
virtualinherited

Reimplemented in C4NetIOUDP, C4Network2HTTPClient, C4Network2IO, and CStdTimerProc.

Definition at line 115 of file StdScheduler.cpp.

References C4TimeMilliseconds::PositiveInfinity.

Referenced by C4Network2HTTPClient::GetNextTick().

Here is the caller graph for this function:

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

Definition at line 1531 of file C4NetIO.cpp.

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

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

1532 {
1533  CStdShareLock PeerListLock(&PeerListCSec);
1534  for (Peer *pPeer = pPeerList; pPeer; pPeer = pPeer->Next)
1535  if (pPeer->Open())
1536  if (pPeer->GetAddr() == addr)
1537  return pPeer;
1538  return nullptr;
1539 }
Peer * pPeerList
Definition: C4NetIO.h:442
CStdCSecEx PeerListCSec
Definition: C4NetIO.h:454
friend class Peer
Definition: C4NetIO.h:440

Here is the caller graph for this function:

bool C4NetIOTCP::GetStatistic ( int *  pBroadcastRate)
overridevirtualinherited

Implements C4NetIO.

Definition at line 1337 of file C4NetIO.cpp.

1338 {
1339  // no broadcast
1340  if (pBroadcastRate) *pBroadcastRate = 0;
1341  return true;
1342 }
C4Network2IRCMessage* C4Network2IRCClient::getUnreadMessageLog ( ) const
inline

Definition at line 172 of file C4Network2IRC.h.

References C4Network2IRCMessage::getNext().

Referenced by C4ChatControl::Update().

172 { return pLogLastRead ? pLogLastRead->getNext() : pLog; }
C4Network2IRCMessage * getNext() const
Definition: C4Network2IRC.h:57

Here is the call graph for this function:

Here is the caller graph for this function:

const char* C4Network2IRCClient::getUserName ( ) const
inline

Definition at line 175 of file C4Network2IRC.h.

References StdStrBuf::getData().

Referenced by C4ChatControl::Update().

175 { return Nick.getData(); }
const char * getData() const
Definition: StdBuf.h:442

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)
overridevirtualinherited

Implements C4NetIO.

Reimplemented in C4AulDebug.

Definition at line 806 of file C4NetIO.cpp.

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

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

807 {
808  // already init? close first
809  if (fInit) Close();
810 
811 #ifdef HAVE_WINSOCK
812  // init winsock
813  if (!AcquireWinSock())
814  {
815  SetError("could not start winsock");
816  return false;
817  }
818 #endif
819 
820 #ifdef STDSCHEDULER_USE_EVENTS
821  // create event
822  if ((Event = WSACreateEvent()) == WSA_INVALID_EVENT)
823  {
824  SetError("could not create socket event", true); // to do: more error information
825  return false;
826  }
827 #else
828  // create pipe
829  if (pipe(Pipe) != 0)
830  {
831  SetError("could not create pipe", true);
832  return false;
833  }
834 #endif
835 
836  // create listen socket (if necessary)
837  if (iPort != addr_t::IPPORT_NONE)
838  if (!Listen(iPort))
839  return false;
840 
841  // ok
842  fInit = true;
843  return true;
844 }
void SetError(const char *strnError, bool fSockErr=false)
Definition: C4NetIO.cpp:745
bool Listen(uint16_t inListenPort)
Definition: C4NetIO.cpp:1476
int Pipe[2]
Definition: C4NetIO.h:469
bool Close() override
Definition: C4NetIO.cpp:852
bool fInit
Definition: C4NetIO.h:458
static const uint16_t IPPORT_NONE
Definition: C4NetIO.h:136

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 846 of file C4NetIO.cpp.

Referenced by main().

847 {
848  // ignore
849  return true;
850 }

Here is the caller graph for this function:

bool C4NetIO::InitIPv6Socket ( SOCKET  socket)
protectedinherited

Definition at line 725 of file C4NetIO.cpp.

References C4NetIO::SetError(), and SOCKET_ERROR.

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

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

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Network2IRCClient::IsActive ( ) const
inline

Definition at line 199 of file C4Network2IRC.h.

Referenced by C4ChatDlg::IsChatActive(), C4ChatControl::UpdateShownPage(), and C4ChatControl::UserQueryQuit().

199 { return fConnecting || fConnected; }

Here is the caller graph for this function:

bool C4Network2IRCClient::IsConnected ( ) const
inline

Definition at line 200 of file C4Network2IRC.h.

Referenced by C4ChatControl::ProcessInput().

200 { return fConnected; }

Here is the caller graph for this function:

virtual bool StdSchedulerProc::IsLowPriority ( )
inlinevirtualinherited

Definition at line 82 of file StdScheduler.h.

82 { return false; }
bool C4NetIO::IsNotify ( )
inlineoverridevirtualinherited

Reimplemented from StdSchedulerProc.

Definition at line 258 of file C4NetIO.h.

258 { return true; }
bool StdSchedulerProc::IsSignaled ( )
inherited
bool C4Network2IRCClient::Join ( const char *  szChannel)

Definition at line 386 of file C4Network2IRC.cpp.

References C4ConfigIRC::AllowAllChannels, Application, Config, C4GUI::Ico_Error, C4Application::InteractiveThread, C4Config::IRC, LoadResStr(), MSG_Status, pGUI, Send(), C4NetIO::SetError(), C4GUI::Screen::ShowMessage(), SWildcardMatchEx(), and C4InteractiveThread::ThreadPostAsync().

Referenced by C4ChatControl::ProcessInput().

387 {
388  // Newbie limitation: can only join channels beginning with #clonk
390  if (!SWildcardMatchEx(szChannel, "#*clonk*"))
391  {
392  const char* message = LoadResStr("IDS_ERR_CHANNELNOTALLOWED");
393  PushMessage(MSG_Status, "", "", message);
394  SetError("Joining this channel not allowed");
395  Application.InteractiveThread.ThreadPostAsync<bool>(std::bind(&C4GUI::Screen::ShowMessage, ::pGUI, message, LoadResStr("IDS_DLG_CHAT"), C4GUI::Ico_Error, static_cast<int32_t* const &>(nullptr)));
396  return false;
397  }
398  return Send("JOIN", szChannel);
399 }
C4Config Config
Definition: C4Config.cpp:833
bool Send(const char *szCommand, const char *szParameters=nullptr)
void SetError(const char *strnError, bool fSockErr=false)
Definition: C4NetIO.cpp:745
bool ThreadPostAsync(Functor function)
const char * LoadResStr(const char *id)
Definition: C4Language.h:83
C4GUIScreen * pGUI
Definition: C4Gui.cpp:1191
bool SWildcardMatchEx(const char *szString, const char *szWildcard)
Definition: Standard.cpp:629
C4ConfigIRC IRC
Definition: C4Config.h:257
bool ShowMessage(const char *szMessage, const char *szCaption, Icons icoIcon, int32_t *piConfigDontShowAgainSetting=nullptr)
int32_t AllowAllChannels
Definition: C4Config.h:210
C4Application Application
Definition: C4Globals.cpp:44
C4InteractiveThread InteractiveThread
Definition: C4Application.h:45

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4NetIOTCP::Listen ( uint16_t  inListenPort)
protectedinherited

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

1477 {
1478  // already listening?
1479  if (lsock != INVALID_SOCKET)
1480  // close existing socket
1481  closesocket(lsock);
1483 
1484  // create socket
1485  if ((lsock = ::socket(AF_INET6, SOCK_STREAM | SOCK_CLOEXEC, IPPROTO_TCP)) == INVALID_SOCKET)
1486  {
1487  SetError("socket creation failed", true);
1488  return false;
1489  }
1490  if (!InitIPv6Socket(lsock))
1491  return false;
1492  // To be able to reuse the port after close
1493 #if !defined(_DEBUG) && !defined(_WIN32)
1494  int reuseaddr = 1;
1495  setsockopt(lsock, SOL_SOCKET, SO_REUSEADDR, reinterpret_cast<const char *>(&reuseaddr), sizeof(reuseaddr));
1496 #endif
1497  // bind listen socket
1498  addr_t addr = addr_t::Any;
1499  addr.SetPort(inListenPort);
1500  if (::bind(lsock, &addr, sizeof(addr)) == SOCKET_ERROR)
1501  {
1502  SetError("socket bind failed", true);
1504  return false;
1505  }
1506 
1507 #ifdef STDSCHEDULER_USE_EVENTS
1508  // set event callback
1509  if (::WSAEventSelect(lsock, Event, FD_ACCEPT | FD_CLOSE) == SOCKET_ERROR)
1510  {
1511  SetError("could not set event for listen socket", true);
1513  return false;
1514  }
1515 #endif
1516 
1517  // start listening
1518  if (::listen(lsock, SOMAXCONN) == SOCKET_ERROR)
1519  {
1520  SetError("socket listen failed", true);
1522  return false;
1523  }
1524 
1525  // ok
1526  iListenPort = inListenPort;
1527  Changed();
1528  return true;
1529 }
#define INVALID_SOCKET
Definition: C4NetIO.h:36
void SetError(const char *strnError, bool fSockErr=false)
Definition: C4NetIO.cpp:745
bool InitIPv6Socket(SOCKET socket)
Definition: C4NetIO.cpp:725
EndpointAddress addr_t
Definition: C4NetIO.h:211
#define SOCK_CLOEXEC
Definition: C4NetIO.h:50
#define closesocket
Definition: C4NetIO.cpp:46
static const uint16_t IPPORT_NONE
Definition: C4NetIO.h:136
SOCKET lsock
Definition: C4NetIO.h:462
uint16_t iListenPort
Definition: C4NetIO.h:461
#define SOCKET_ERROR
Definition: C4NetIO.cpp:47

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Network2IRCClient::MarkMessageLogRead ( )

Definition at line 291 of file C4Network2IRC.cpp.

References C4NetIRCMaxReadLogLength.

Referenced by C4ChatControl::Update().

292 {
293  // set read marker to last message
294  pLogLastRead = pLogEnd;
295  iUnreadLogLength = 0;
296  // message buffer is smaller for messages already read: Remove old ones
297  while (iLogLength > C4NetIRCMaxReadLogLength)
298  PopMessage();
299 }
const int C4NetIRCMaxReadLogLength
Definition: C4Network2IRC.h:31

Here is the caller graph for this function:

bool C4Network2IRCClient::Message ( const char *  szTarget,
const char *  szText 
)

Definition at line 406 of file C4Network2IRC.cpp.

References FormatString(), StdStrBuf::getData(), MSG_Message, and Send().

Referenced by C4ChatControl::ProcessInput().

407 {
408  if (!Send("PRIVMSG", FormatString("%s :%s", szTarget, szText).getData()))
409  return false;
410  PushMessage(MSG_Message, Nick.getData(), szTarget, szText);
411  return true;
412 }
const char * getData() const
Definition: StdBuf.h:442
bool Send(const char *szCommand, const char *szParameters=nullptr)
StdStrBuf FormatString(const char *szFmt,...)
Definition: StdBuf.cpp:270

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Network2IRCClient::Notice ( const char *  szTarget,
const char *  szText 
)

Definition at line 414 of file C4Network2IRC.cpp.

References FormatString(), StdStrBuf::getData(), MSG_Notice, and Send().

Referenced by C4ChatControl::ProcessInput().

415 {
416  if (!Send("NOTICE", FormatString("%s :%s", szTarget, szText).getData()))
417  return false;
418  PushMessage(MSG_Notice, Nick.getData(), szTarget, szText);
419  return true;
420 }
const char * getData() const
Definition: StdBuf.h:442
bool Send(const char *szCommand, const char *szParameters=nullptr)
StdStrBuf FormatString(const char *szFmt,...)
Definition: StdBuf.cpp:270

Here is the call graph for this function:

Here is the caller graph for this function:

void C4NetIOTCP::OnShareFree ( CStdCSecEx pCSec)
overrideprotectedvirtualinherited

Implements CStdCSecExCallback.

Definition at line 1541 of file C4NetIO.cpp.

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

1542 {
1543  if (pCSec == &PeerListCSec)
1544  {
1545  // clear up
1546  Peer *pPeer = pPeerList, *pLast = nullptr;
1547  while (pPeer)
1548  {
1549  // delete?
1550  if (!pPeer->Open())
1551  {
1552  // unlink
1553  Peer *pDelete = pPeer;
1554  pPeer = pPeer->Next;
1555  (pLast ? pLast->Next : pPeerList) = pPeer;
1556  // delete
1557  delete pDelete;
1558  }
1559  else
1560  {
1561  // next peer
1562  pLast = pPeer;
1563  pPeer = pPeer->Next;
1564  }
1565  }
1566  ConnectWait *pWait = pConnectWaits, *pWLast = nullptr;
1567  while (pWait)
1568  {
1569  // delete?
1570  if (!pWait->sock)
1571  {
1572  // unlink
1573  ConnectWait *pDelete = pWait;
1574  pWait = pWait->Next;
1575  (pWLast ? pWLast->Next : pConnectWaits) = pWait;
1576  // delete
1577  delete pDelete;
1578  }
1579  else
1580  {
1581  // next peer
1582  pWLast = pWait;
1583  pWait = pWait->Next;
1584  }
1585  }
1586  }
1587 }
Peer * pPeerList
Definition: C4NetIO.h:442
CStdCSecEx PeerListCSec
Definition: C4NetIO.h:454
friend class Peer
Definition: C4NetIO.h:440

Here is the call graph for this function:

bool C4Network2IRCClient::Part ( const char *  szChannel)

Definition at line 401 of file C4Network2IRC.cpp.

References Send().

Referenced by C4ChatControl::ProcessInput().

402 {
403  return Send("PART", szChannel);
404 }
bool Send(const char *szCommand, const char *szParameters=nullptr)

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Network2IRCClient::Quit ( const char *  szReason)

Definition at line 378 of file C4Network2IRC.cpp.

References Close(), FormatString(), and Send().

Referenced by C4ChatControl::ProcessInput().

379 {
380  if (!Send("QUIT", FormatString(":%s", szReason).getData()))
381  return false;
382  // Must be last message
383  return Close();
384 }
bool Send(const char *szCommand, const char *szParameters=nullptr)
bool Close() override
StdStrBuf FormatString(const char *szFmt,...)
Definition: StdBuf.cpp:270

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Network2IRCClient::RegisterNick ( const char *  szPassword,
const char *  szMail 
)

Definition at line 435 of file C4Network2IRC.cpp.

References FormatString(), and Send().

436 {
437  return Send("PRIVMSG", FormatString("NickServ :REGISTER %s %s", szPassword, szMail).getData());
438 }
bool Send(const char *szCommand, const char *szParameters=nullptr)
StdStrBuf FormatString(const char *szFmt,...)
Definition: StdBuf.cpp:270

Here is the call graph for this function:

void C4NetIO::ResetError ( )
inlineinherited

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

285 { Error.Clear(); }
void Clear()
Definition: StdBuf.h:466
StdCopyStrBuf Error
Definition: C4NetIO.h:281

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Network2IRCClient::Send ( const char *  szCommand,
const char *  szParameters = nullptr 
)

Definition at line 364 of file C4Network2IRC.cpp.

References StdStrBuf::Format(), StdStrBuf::getData(), StdStrBuf::getLength(), StdStrBuf::Ref(), C4NetIOTCP::Send(), and C4NetIO::SetError().

Referenced by Action(), ChangeNick(), Join(), Message(), Notice(), Part(), C4ChatControl::ProcessInput(), Quit(), and RegisterNick().

365 {
366  if (!fConnected)
367  { SetError("not connected"); return false; }
368  // Create message
369  StdStrBuf Msg;
370  if (szParameters)
371  Msg.Format("%s %s", szCommand, szParameters);
372  else
373  Msg.Ref(szCommand);
374  // Send
375  return C4NetIOTCP::Send(C4NetIOPacket(Msg.getData(), Msg.getLength(), false, PeerAddr));
376 }
const char * getData() const
Definition: StdBuf.h:442
bool Send(const C4NetIOPacket &rPacket) override
Definition: C4NetIO.cpp:1248
void SetError(const char *strnError, bool fSockErr=false)
Definition: C4NetIO.cpp:745
void Format(const char *szFmt,...) GNUC_FORMAT_ATTRIBUTE_O
Definition: StdBuf.cpp:174
void Ref(const char *pnData)
Definition: StdBuf.h:455
size_t getLength() const
Definition: StdBuf.h:445

Here is the call graph for this function:

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)
overrideinherited

Definition at line 1248 of file C4NetIO.cpp.

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

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

1249 {
1250  CStdShareLock PeerListLock(&PeerListCSec);
1251  // find peer
1252  Peer *pPeer = GetPeer(rPacket.getAddr());
1253  // not found?
1254  if (!pPeer) return false;
1255  // send
1256  return pPeer->Send(rPacket);
1257 }
const C4NetIO::addr_t & getAddr() const
Definition: C4NetIO.h:315
CStdCSecEx PeerListCSec
Definition: C4NetIO.h:454
Peer * GetPeer(const addr_t &addr)
Definition: C4NetIO.cpp:1531
friend class Peer
Definition: C4NetIO.h:440
bool Send(const C4NetIOPacket &rPacket)
Definition: C4NetIO.cpp:1689

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 
)
overridevirtualinherited

Implements C4NetIO.

Definition at line 1259 of file C4NetIO.cpp.

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

1260 {
1261  CStdShareLock PeerListLock(&PeerListCSec);
1262  // find peer
1263  Peer *pPeer = GetPeer(addr);
1264  if (!pPeer) return false;
1265  // set flag
1266  pPeer->SetBroadcast(fSet);
1267  return true;
1268 }
CStdCSecEx PeerListCSec
Definition: C4NetIO.h:454
Peer * GetPeer(const addr_t &addr)
Definition: C4NetIO.cpp:1531
friend class Peer
Definition: C4NetIO.h:440

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:

void C4NetIOTCP::SetCallback ( CBClass *  pnCallback)
inlineoverrideinherited

Definition at line 486 of file C4NetIO.h.

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

486 { pCB = pnCallback; };

Here is the caller graph for this function:

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

Definition at line 745 of file C4NetIO.cpp.

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

Referenced by C4NetIOTCP::Accept(), C4NetIOSimpleUDP::CloseBroadcast(), 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(), Join(), C4NetIOTCP::Listen(), Send(), C4NetIOSimpleUDP::Send(), C4Network2HTTPClient::SetServer(), C4NetIOTCP::UnBlock(), and C4NetIOSimpleUDP::UnBlock().

746 {
747  fSockErr &= HaveSocketError();
748  if (fSockErr)
749  Error.Format("%s (%s)", strnError, GetSocketErrorMsg());
750  else
751  Error.Copy(strnError);
752 }
const char * GetSocketErrorMsg(int iError)
Definition: C4NetIO.cpp:190
StdCopyStrBuf Error
Definition: C4NetIO.h:281
void Format(const char *szFmt,...) GNUC_FORMAT_ATTRIBUTE_O
Definition: StdBuf.cpp:174
bool HaveSocketError()
Definition: C4NetIO.cpp:199
void Copy()
Definition: StdBuf.h:467

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Network2IRCClient::SetNotify ( class C4InteractiveThread pnNotify)
inline

Definition at line 186 of file C4Network2IRC.h.

Referenced by C4ChatControl::OnConnectBtn().

186 { pNotify = pnNotify; }

Here is the caller graph for this function:

virtual uint32_t StdSchedulerProc::TimerInterval ( )
inlinevirtualinherited

Reimplemented in CStdTimerProc.

Definition at line 84 of file StdScheduler.h.

Referenced by SCHAdditions::assignAdditionForProc:.

84 { return 0; }

Here is the caller graph for this function:

void C4NetIOTCP::UnBlock ( )
virtualinherited

Definition at line 1281 of file C4NetIO.cpp.

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

Referenced by C4NetIOTCP::AddConnectWait().

1282 {
1283 #ifdef STDSCHEDULER_USE_EVENTS
1284  // unblock WaitForSingleObject in C4NetIOTCP::Execute manually
1285  // by setting the Event
1286  WSASetEvent(Event);
1287 #else
1288  // write one character to the pipe, this will unblock everything that
1289  // waits for the FD set returned by GetFDs.
1290  char c = 1;
1291  if (write(Pipe[1], &c, 1) == -1)
1292  SetError("write failed");
1293 #endif
1294 }
void SetError(const char *strnError, bool fSockErr=false)
Definition: C4NetIO.cpp:745
int Pipe[2]
Definition: C4NetIO.h:469

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

bool C4NetIOTCP::fInit {false}
protectedinherited

Definition at line 458 of file C4NetIO.h.

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

uint16_t C4NetIOTCP::iListenPort
protectedinherited

Definition at line 461 of file C4NetIO.h.

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

SOCKET C4NetIOTCP::lsock
protectedinherited
struct C4NetIOTCP::ConnectWait C4NetIOTCP::nullptr
protectedinherited
CStdCSec C4NetIOTCP::PeerListAddCSec
protectedinherited

Definition at line 455 of file C4NetIO.h.

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

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

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