OpenClonk
MyCBClass Class Reference
Inheritance diagram for MyCBClass:
[legend]
Collaboration diagram for MyCBClass:
[legend]

Public Member Functions

virtual bool OnConn (const C4NetIO::addr_t &addr, const C4NetIO::addr_t &addr2, C4NetIO *pNetIO)
 
virtual void OnPacket (const class C4NetIOPacket &rPacket, C4NetIO *pNetIO)
 
virtual void OnDisconn (const C4NetIO::addr_t &addr, C4NetIO *pNetIO, const char *szReason)
 
virtual void OnError (const char *strError, C4NetIO *pNetIO)
 
void Clear ()
 
void AddIO (C4NetIO *pNetIO, bool fSetCallback=true)
 
void RemoveIO (C4NetIO *pNetIO)
 
virtual bool OnConn (const addr_t &AddrPeer, const addr_t &AddrConnect, const addr_t *pOwnAddr, C4NetIO *pNetIO)
 
void Set (StdSchedulerProc **ppProcs, int iProcCnt)
 
void Add (StdSchedulerProc *pProc)
 
void Remove (StdSchedulerProc *pProc)
 
bool Start ()
 
void Stop ()
 
int getProcCnt () const
 
bool hasProc (StdSchedulerProc *pProc)
 
bool IsInManualLoop ()
 
void Added (StdSchedulerProc *pProc)
 
void Removing (StdSchedulerProc *pProc)
 
void Changed (StdSchedulerProc *pProc)
 
void StartOnCurrentThread ()
 
C4TimeMilliseconds GetNextTick (C4TimeMilliseconds tNow)
 
bool ScheduleProcs (int iTimeout=1000/36)
 
void UnBlock ()
 

Protected Member Functions

virtual bool DoScheduleProcs (int iTimeout)
 

Protected Attributes

int iNetIOCnt {0}
 
int iNetIOCapacity {0}
 
C4NetIO ** ppNetIO {nullptr}
 

Detailed Description

Definition at line 40 of file TstC4NetIO.cpp.

Member Function Documentation

◆ Add()

void StdSchedulerThread::Add ( StdSchedulerProc pProc)
inherited

Definition at line 183 of file StdScheduler.cpp.

References StdScheduler::Add().

Referenced by C4NetIOMan::AddIO(), and C4InteractiveThread::AddProc().

184 {
185  // Thread is running? Stop it first
186  bool fGotThread = fThread;
187  if (fGotThread) Stop();
188  // Set
189  StdScheduler::Add(pProc);
190  // Restart
191  if (fGotThread) Start();
192 }
void Add(StdSchedulerProc *pProc)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Added()

void StdScheduler::Added ( StdSchedulerProc pProc)
inherited

Definition at line 281 of file StdSchedulerMac.mm.

References SCHAdditions::assignAdditionForProc:, and SCHAdditions::requestAdditionsForScheduler:.

282 {
283  [[SCHAdditions requestAdditionsForScheduler:this] assignAdditionForProc:pProc];
284 }
Here is the call graph for this function:

◆ AddIO()

void C4NetIOMan::AddIO ( C4NetIO pNetIO,
bool  fSetCallback = true 
)
inherited

Definition at line 3989 of file C4NetIO.cpp.

References StdSchedulerThread::Add(), C4NetIOMan::iNetIOCapacity, C4NetIOMan::iNetIOCnt, C4NetIOMan::ppNetIO, and C4NetIO::SetCallback().

Referenced by main().

3990 {
3991  // Set callback
3992  if (fSetCallback)
3993  pNetIO->SetCallback(this);
3994  // Add to i/o list
3995  if (iNetIOCnt + 1 > iNetIOCapacity)
3996  EnlargeIO(1);
3997  ppNetIO[iNetIOCnt++] = pNetIO;
3998  // Register with scheduler
3999  Add(pNetIO);
4000 }
virtual void SetCallback(CBClass *pnCallback)=0
C4NetIO ** ppNetIO
Definition: C4NetIO.h:964
int iNetIOCapacity
Definition: C4NetIO.h:963
int iNetIOCnt
Definition: C4NetIO.h:963
void Add(StdSchedulerProc *pProc)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Changed()

void StdScheduler::Changed ( StdSchedulerProc pProc)
inherited

Definition at line 294 of file StdSchedulerMac.mm.

References SCHAdditions::additionForProc:, SCHAddition::changed, and SCHAdditions::requestAdditionsForScheduler:.

295 {
296  [[[SCHAdditions requestAdditionsForScheduler:this] additionForProc:pProc] changed];
297 }
Here is the call graph for this function:

◆ Clear()

void C4NetIOMan::Clear ( )
inherited

Definition at line 3982 of file C4NetIO.cpp.

References StdSchedulerThread::Clear(), C4NetIOMan::iNetIOCapacity, C4NetIOMan::iNetIOCnt, and C4NetIOMan::ppNetIO.

Referenced by C4NetIOMan::~C4NetIOMan().

3983 {
3984  delete[] ppNetIO; ppNetIO = nullptr;
3985  iNetIOCnt = iNetIOCapacity = 0;
3987 }
C4NetIO ** ppNetIO
Definition: C4NetIO.h:964
int iNetIOCapacity
Definition: C4NetIO.h:963
int iNetIOCnt
Definition: C4NetIO.h:963
Here is the call graph for this function:
Here is the caller graph for this function:

◆ DoScheduleProcs()

virtual bool StdScheduler::DoScheduleProcs ( int  iTimeout)
protectedvirtualinherited

Reimplemented in C4AbstractApp.

Referenced by C4AbstractApp::DoScheduleProcs().

Here is the caller graph for this function:

◆ GetNextTick()

C4TimeMilliseconds StdScheduler::GetNextTick ( C4TimeMilliseconds  tNow)
inherited

Definition at line 120 of file StdScheduler.cpp.

References C4TimeMilliseconds::PositiveInfinity.

Referenced by C4AbstractApp::Run().

121 {
123  for (auto proc : procs)
124  {
125  tProcTick = std::min(tProcTick, proc->GetNextTick(tNow));
126  }
127  return tProcTick;
128 }
Here is the caller graph for this function:

◆ getProcCnt()

int StdScheduler::getProcCnt ( ) const
inlineinherited

Definition at line 245 of file StdScheduler.h.

Referenced by C4InteractiveThread::AddProc(), and C4InteractiveThread::RemoveProc().

245 { return procs.size()-1; } // ignore internal NoopNotifyProc
Here is the caller graph for this function:

◆ hasProc()

bool StdScheduler::hasProc ( StdSchedulerProc pProc)
inlineinherited

Definition at line 246 of file StdScheduler.h.

Referenced by C4InteractiveThread::RemoveProc().

246 { return std::find(procs.begin(), procs.end(), pProc) != procs.end(); }
Here is the caller graph for this function:

◆ IsInManualLoop()

bool StdScheduler::IsInManualLoop ( )
inlineinherited

Definition at line 247 of file StdScheduler.h.

References StdSchedulerProc::Changed(), and StdSchedulerProc::GetNextTick().

247 { return isInManualLoop; }
Here is the call graph for this function:

◆ OnConn() [1/2]

virtual bool MyCBClass::OnConn ( const C4NetIO::addr_t addr,
const C4NetIO::addr_t addr2,
C4NetIO pNetIO 
)
inlinevirtual

Definition at line 44 of file TstC4NetIO.cpp.

References DummyData, fHost, C4NetIO::GetError(), iSize, C4TimeMilliseconds::Now(), and C4NetIO::Send().

45  {
46  cout << "got connection from " << inet_ntoa(addr.sin_addr) << endl;
47  tTime = C4TimeMilliseconds::Now();
48  iPcks = 0;
49 
50 #ifdef ASYNC_CONNECT
51  if (!fHost)
52  {
53  DummyData[0] = 0;
54  if (!pNetIO->Send(C4NetIOPacket(DummyData, iSize, true, addr)))
55  cout << " Fehler: " << (pNetIO->GetError() ? pNetIO->GetError() : "bla") << endl;
56  }
57 #endif
58  return true;
59  }
bool fHost
Definition: TstC4NetIO.cpp:31
char DummyData[1024 *1024]
Definition: TstC4NetIO.cpp:33
virtual bool Send(const class C4NetIOPacket &rPacket)=0
virtual const char * GetError() const
Definition: C4NetIO.h:285
static C4TimeMilliseconds Now()
int iSize
Definition: TstC4NetIO.cpp:32
Here is the call graph for this function:

◆ OnConn() [2/2]

virtual bool C4NetIO::CBClass::OnConn ( const addr_t AddrPeer,
const addr_t AddrConnect,
const addr_t pOwnAddr,
C4NetIO pNetIO 
)
inlinevirtualinherited

Reimplemented in C4NetIO::CBProxy< T >, C4Network2IO, and C4Network2HTTPClient.

Definition at line 220 of file C4NetIO.h.

Referenced by C4NetIOTCP::Accept(), and C4NetIOUDP::Peer::OnConn().

220 { return true; }
Here is the caller graph for this function:

◆ OnDisconn()

virtual void MyCBClass::OnDisconn ( const C4NetIO::addr_t addr,
C4NetIO pNetIO,
const char *  szReason 
)
inlinevirtual

Reimplemented from C4NetIO::CBClass.

Definition at line 85 of file TstC4NetIO.cpp.

86  {
87  cout << "client from " << inet_ntoa(addr.sin_addr) << " disconnected (" << szReason << ")" << endl;
88  }

◆ OnError()

virtual void MyCBClass::OnError ( const char *  strError,
C4NetIO pNetIO 
)
inlinevirtual

Reimplemented from C4NetIOMan.

Definition at line 89 of file TstC4NetIO.cpp.

90  {
91  cout << "network error: " << strError << endl;
92  };

◆ OnPacket()

virtual void MyCBClass::OnPacket ( const class C4NetIOPacket rPacket,
C4NetIO pNetIO 
)
inlinevirtual

Implements C4NetIO::CBClass.

Definition at line 60 of file TstC4NetIO.cpp.

References DummyData, C4NetIOPacket::getAddr(), C4NetIO::GetError(), C4NetIOPacket::getStatus(), iCnt, iSize, C4TimeMilliseconds::Now(), and C4NetIO::Send().

61  {
63  if (tNow > tTime + 1000)
64  {
65  cout << iPcks << " packets in " << tNow - tTime << " ms (" << iPcks * 1000 / (tNow - tTime) << " per second, " << (iPcks ? (tNow - tTime) * 1000 / iPcks : -1u) << "us per packet)" << endl;
66  tTime = C4TimeMilliseconds::Now();
67  iPcks = 0;
68  }
69  if (!rPacket.getStatus())
70  {
71  // dummys
72  DummyData[0] = 1;
73  C4NetIOPacket Dummy(DummyData, iSize, true, rPacket.getAddr());
74  for (int i = 0; i < iCnt; i++)
75  {
76  if (!pNetIO->Send(Dummy))
77  cout << " Fehler: " << (pNetIO->GetError() ? pNetIO->GetError() : "bla") << endl;
78  }
79  // pong
80  pNetIO->Send(rPacket);
81  iPcks++;
82  }
83  // cout << "got " << rPacket.GetSize() << " bytes of data (" << int(*rPacket.GetData()) << ")" << endl;
84  }
int iCnt
Definition: TstC4NetIO.cpp:32
char DummyData[1024 *1024]
Definition: TstC4NetIO.cpp:33
virtual bool Send(const class C4NetIOPacket &rPacket)=0
virtual const char * GetError() const
Definition: C4NetIO.h:285
static C4TimeMilliseconds Now()
int iSize
Definition: TstC4NetIO.cpp:32
Here is the call graph for this function:

◆ Remove()

void StdSchedulerThread::Remove ( StdSchedulerProc pProc)
inherited

Definition at line 194 of file StdScheduler.cpp.

References StdScheduler::Remove().

Referenced by C4InteractiveThread::RemoveProc().

195 {
196  // Thread is running? Stop it first
197  bool fGotThread = fThread;
198  if (fGotThread) Stop();
199  // Set
200  StdScheduler::Remove(pProc);
201  // Restart
202  if (fGotThread) Start();
203 }
void Remove(StdSchedulerProc *pProc)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ RemoveIO()

void C4NetIOMan::RemoveIO ( C4NetIO pNetIO)
inherited

Definition at line 4002 of file C4NetIO.cpp.

References C4NetIOMan::iNetIOCapacity, C4NetIOMan::iNetIOCnt, C4NetIOMan::OnError(), and C4NetIOMan::ppNetIO.

4003 {
4004  // Search
4005  int i;
4006  for (i = 0; i < iNetIOCnt; i++)
4007  if (ppNetIO[i] == pNetIO)
4008  break;
4009  // Not found?
4010  if (i >= iNetIOCnt) return;
4011  // Remove
4012  for (i++; i < iNetIOCnt; i++)
4013  ppNetIO[i-1] = ppNetIO[i];
4014  iNetIOCnt--;
4015 }
C4NetIO ** ppNetIO
Definition: C4NetIO.h:964
int iNetIOCnt
Definition: C4NetIO.h:963
Here is the call graph for this function:

◆ Removing()

void StdScheduler::Removing ( StdSchedulerProc pProc)
inherited

Definition at line 286 of file StdSchedulerMac.mm.

References SCHAdditions::requestAdditionsForScheduler:.

287 {
288  auto x = [SCHAdditions requestAdditionsForScheduler:this];
289  [x removeAdditionForProc:pProc];
290  if ([x numberOfAdditions] == 0)
291  [SCHAdditions removeAdditions:x];
292 }
Here is the call graph for this function:

◆ ScheduleProcs()

bool StdScheduler::ScheduleProcs ( int  iTimeout = 1000/36)
inherited

Definition at line 130 of file StdScheduler.cpp.

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

Referenced by C4AulDebug::DebugStep(), C4Network2::DoLobby(), C4GUI::Dialog::DoModal(), C4ScenarioListLoader::DoProcessCallback(), C4Network2::InitialConnect::Execute(), C4GUI::Dialog::Execute(), C4Network2::FinalInit(), C4Game::InitNetworkFromAddress(), C4Network2::LeaguePlrAuth(), C4Network2::LeagueStart(), C4AulDebug::Listen(), C4Network2::RetrieveRes(), C4AbstractApp::Run(), and C4AppDelegate::suggestQuitting:.

131 {
132  // Needs at least one process to work properly
133  if (!procs.size()) return false;
134 
135  // Get timeout
137  C4TimeMilliseconds tProcTick = GetNextTick(tNow);
138  if (iTimeout == -1 || tNow + iTimeout > tProcTick)
139  {
140  iTimeout = std::max<decltype(iTimeout)>(tProcTick - tNow, 0);
141  }
142 
143  bool old = isInManualLoop;
144  isInManualLoop = true;
145  bool res = DoScheduleProcs(iTimeout);
146  isInManualLoop = old;
147  return res;
148 }
C4TimeMilliseconds GetNextTick(C4TimeMilliseconds tNow)
virtual bool DoScheduleProcs(int iTimeout)
static C4TimeMilliseconds Now()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Set()

void StdSchedulerThread::Set ( StdSchedulerProc **  ppProcs,
int  iProcCnt 
)
inherited

Definition at line 172 of file StdScheduler.cpp.

References StdScheduler::Set().

173 {
174  // Thread is running? Stop it first
175  bool fGotThread = fThread;
176  if (fGotThread) Stop();
177  // Set
178  StdScheduler::Set(ppProcs, iProcCnt);
179  // Restart
180  if (fGotThread) Start();
181 }
void Set(StdSchedulerProc **ppProcs, int iProcCnt)
Here is the call graph for this function:

◆ Start()

bool StdSchedulerThread::Start ( )
inherited

Definition at line 205 of file StdScheduler.cpp.

Referenced by C4InteractiveThread::AddProc(), and main().

206 {
207  // already running? stop
208  if (fThread) Stop();
209  // begin thread
210  fRunThreadRun = true;
211 #ifdef HAVE_WINTHREAD
212  iThread = _beginthread(_ThreadFunc, 0, this);
213  fThread = (iThread != -1);
214 #elif defined(HAVE_PTHREAD)
215  fThread = !pthread_create(&Thread, nullptr, _ThreadFunc, this);
216 #endif
217  // success?
218  return fThread;
219 }
Here is the caller graph for this function:

◆ StartOnCurrentThread()

void StdScheduler::StartOnCurrentThread ( )
inherited

Definition at line 276 of file StdSchedulerMac.mm.

References SCHAdditions::requestAdditionsForScheduler:, and SCHAdditions::start.

Referenced by C4AppDelegate::isEditorAndGameRunning.

277 {
278  [[SCHAdditions requestAdditionsForScheduler:this] start];
279 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Stop()

void StdSchedulerThread::Stop ( )
inherited

Definition at line 221 of file StdScheduler.cpp.

References StdThread::StdThread().

Referenced by main(), and C4InteractiveThread::RemoveProc().

222 {
223  // Not running?
224  if (!fThread) return;
225  // Set flag
226  fRunThreadRun = false;
227  // Unblock
228  UnBlock();
229 #ifdef HAVE_WINTHREAD
230  // Wait for thread to terminate itself
231  HANDLE hThread = reinterpret_cast<HANDLE>(iThread);
232  if (WaitForSingleObject(hThread, 10000) == WAIT_TIMEOUT)
233  // ... or kill it in case it refuses to do so
234  TerminateThread(hThread, -1);
235 #elif defined(HAVE_PTHREAD)
236  // wait for thread to terminate itself
237  // (without security - let's trust these unwashed hackers for once)
238  pthread_join(Thread, nullptr);
239 #endif
240  fThread = false;
241  // ok
242  return;
243 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ UnBlock()

void StdScheduler::UnBlock ( )
inherited

Definition at line 150 of file StdScheduler.cpp.

References StdSchedulerThread::StdSchedulerThread().

151 {
152  Unblocker.Notify();
153 }
Here is the call graph for this function:

Member Data Documentation

◆ iNetIOCapacity

int C4NetIOMan::iNetIOCapacity {0}
protectedinherited

Definition at line 963 of file C4NetIO.h.

Referenced by C4NetIOMan::AddIO(), C4NetIOMan::Clear(), and C4NetIOMan::RemoveIO().

◆ iNetIOCnt

int C4NetIOMan::iNetIOCnt {0}
protectedinherited

Definition at line 963 of file C4NetIO.h.

Referenced by C4NetIOMan::AddIO(), C4NetIOMan::Clear(), and C4NetIOMan::RemoveIO().

◆ ppNetIO

C4NetIO** C4NetIOMan::ppNetIO {nullptr}
protectedinherited

Definition at line 964 of file C4NetIO.h.

Referenced by C4NetIOMan::AddIO(), C4NetIOMan::Clear(), and C4NetIOMan::RemoveIO().


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