OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
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
 
int iNetIOCapacity
 
C4NetIO ** ppNetIO
 

Detailed Description

Definition at line 43 of file TstC4NetIO.cpp.

Member Function Documentation

void StdSchedulerThread::Add ( StdSchedulerProc pProc)
inherited

Definition at line 200 of file StdScheduler.cpp.

References StdScheduler::Add(), StdSchedulerThread::Start(), and StdSchedulerThread::Stop().

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

201 {
202  // Thread is running? Stop it first
203  bool fGotThread = fThread;
204  if (fGotThread) Stop();
205  // Set
206  StdScheduler::Add(pProc);
207  // Restart
208  if (fGotThread) Start();
209 }
void Add(StdSchedulerProc *pProc)

Here is the call graph for this function:

Here is the caller graph for this function:

void StdScheduler::Added ( StdSchedulerProc pProc)
inherited

Definition at line 281 of file StdSchedulerMac.mm.

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

Referenced by StdScheduler::Add().

282 {
283  [[SCHAdditions requestAdditionsForScheduler:this] assignAdditionForProc:pProc];
284 }

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 3950 of file C4NetIO.cpp.

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

Referenced by main().

3951 {
3952  // Set callback
3953  if (fSetCallback)
3954  pNetIO->SetCallback(this);
3955  // Add to i/o list
3956  if (iNetIOCnt + 1 > iNetIOCapacity)
3957  EnlargeIO(1);
3958  ppNetIO[iNetIOCnt++] = pNetIO;
3959  // Register with scheduler
3960  Add(pNetIO);
3961 }
virtual void SetCallback(CBClass *pnCallback)=0
C4NetIO ** ppNetIO
Definition: C4NetIO.h:947
int iNetIOCapacity
Definition: C4NetIO.h:946
int iNetIOCnt
Definition: C4NetIO.h:946
void Add(StdSchedulerProc *pProc)

Here is the call graph for this function:

Here is the caller graph for this function:

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:

void C4NetIOMan::Clear ( )
inherited

Definition at line 3943 of file C4NetIO.cpp.

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

Referenced by C4NetIOMan::~C4NetIOMan().

3944 {
3945  delete[] ppNetIO; ppNetIO = nullptr;
3946  iNetIOCnt = iNetIOCapacity = 0;
3948 }
C4NetIO ** ppNetIO
Definition: C4NetIO.h:947
int iNetIOCapacity
Definition: C4NetIO.h:946
int iNetIOCnt
Definition: C4NetIO.h:946

Here is the call graph for this function:

Here is the caller graph for this function:

virtual bool StdScheduler::DoScheduleProcs ( int  iTimeout)
protectedvirtualinherited

Reimplemented in C4AbstractApp.

Referenced by C4AbstractApp::DoScheduleProcs(), and StdScheduler::ScheduleProcs().

Here is the caller graph for this function:

C4TimeMilliseconds StdScheduler::GetNextTick ( C4TimeMilliseconds  tNow)
inherited

Definition at line 133 of file StdScheduler.cpp.

References C4TimeMilliseconds::PositiveInfinity.

Referenced by C4AbstractApp::Run(), and StdScheduler::ScheduleProcs().

134 {
136  for (auto proc : procs)
137  {
138  tProcTick = std::min(tProcTick, proc->GetNextTick(tNow));
139  }
140  return tProcTick;
141 }

Here is the caller graph for this function:

int StdScheduler::getProcCnt ( ) const
inlineinherited

Definition at line 249 of file StdScheduler.h.

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

249 { return procs.size()-1; } // ignore internal NoopNotifyProc

Here is the caller graph for this function:

bool StdScheduler::hasProc ( StdSchedulerProc pProc)
inlineinherited

Definition at line 250 of file StdScheduler.h.

Referenced by C4InteractiveThread::RemoveProc().

250 { return std::find(procs.begin(), procs.end(), pProc) != procs.end(); }

Here is the caller graph for this function:

bool StdScheduler::IsInManualLoop ( )
inlineinherited

Definition at line 251 of file StdScheduler.h.

251 { return isInManualLoop; }
virtual bool MyCBClass::OnConn ( const C4NetIO::addr_t addr,
const C4NetIO::addr_t addr2,
C4NetIO pNetIO 
)
inlinevirtual

Definition at line 47 of file TstC4NetIO.cpp.

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

48  {
49  cout << "got connection from " << inet_ntoa(addr.sin_addr) << endl;
50  tTime = C4TimeMilliseconds::Now();
51  iPcks = 0;
52 
53 #ifdef ASYNC_CONNECT
54  if (!fHost)
55  {
56  DummyData[0] = 0;
57  if (!pNetIO->Send(C4NetIOPacket(DummyData, iSize, true, addr)))
58  cout << " Fehler: " << (pNetIO->GetError() ? pNetIO->GetError() : "bla") << endl;
59  }
60 #endif
61  return true;
62  }
bool fHost
Definition: TstC4NetIO.cpp:34
virtual const char * GetError() const
Definition: C4NetIO.h:285
char DummyData[1024 *1024]
Definition: TstC4NetIO.cpp:36
virtual bool Send(const class C4NetIOPacket &rPacket)=0
static C4TimeMilliseconds Now()
int iSize
Definition: TstC4NetIO.cpp:35

Here is the call graph for this function:

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:

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

Reimplemented from C4NetIO::CBClass.

Definition at line 88 of file TstC4NetIO.cpp.

89  {
90  cout << "client from " << inet_ntoa(addr.sin_addr) << " disconnected (" << szReason << ")" << endl;
91  }
virtual void MyCBClass::OnError ( const char *  strError,
C4NetIO pNetIO 
)
inlinevirtual

Reimplemented from C4NetIOMan.

Definition at line 92 of file TstC4NetIO.cpp.

93  {
94  cout << "network error: " << strError << endl;
95  };
virtual void MyCBClass::OnPacket ( const class C4NetIOPacket rPacket,
C4NetIO pNetIO 
)
inlinevirtual

Implements C4NetIO::CBClass.

Definition at line 63 of file TstC4NetIO.cpp.

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

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

Here is the call graph for this function:

void StdSchedulerThread::Remove ( StdSchedulerProc pProc)
inherited

Definition at line 211 of file StdScheduler.cpp.

References StdScheduler::Remove(), StdSchedulerThread::Start(), and StdSchedulerThread::Stop().

Referenced by C4InteractiveThread::RemoveProc().

212 {
213  // Thread is running? Stop it first
214  bool fGotThread = fThread;
215  if (fGotThread) Stop();
216  // Set
217  StdScheduler::Remove(pProc);
218  // Restart
219  if (fGotThread) Start();
220 }
void Remove(StdSchedulerProc *pProc)

Here is the call graph for this function:

Here is the caller graph for this function:

void C4NetIOMan::RemoveIO ( C4NetIO pNetIO)
inherited

Definition at line 3963 of file C4NetIO.cpp.

References C4NetIOMan::iNetIOCnt, and C4NetIOMan::ppNetIO.

3964 {
3965  // Search
3966  int i;
3967  for (i = 0; i < iNetIOCnt; i++)
3968  if (ppNetIO[i] == pNetIO)
3969  break;
3970  // Not found?
3971  if (i >= iNetIOCnt) return;
3972  // Remove
3973  for (i++; i < iNetIOCnt; i++)
3974  ppNetIO[i-1] = ppNetIO[i];
3975  iNetIOCnt--;
3976 }
C4NetIO ** ppNetIO
Definition: C4NetIO.h:947
int iNetIOCnt
Definition: C4NetIO.h:946
void StdScheduler::Removing ( StdSchedulerProc pProc)
inherited

Definition at line 286 of file StdSchedulerMac.mm.

References SCHAdditions::requestAdditionsForScheduler:.

Referenced by StdScheduler::Remove().

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:

Here is the caller graph for this function:

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

Definition at line 143 of file StdScheduler.cpp.

References StdScheduler::DoScheduleProcs(), StdScheduler::GetNextTick(), and C4TimeMilliseconds::Now().

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

144 {
145  // Needs at least one process to work properly
146  if (!procs.size()) return false;
147 
148  // Get timeout
150  C4TimeMilliseconds tProcTick = GetNextTick(tNow);
151  if (iTimeout == -1 || tNow + iTimeout > tProcTick)
152  {
153  iTimeout = std::max<decltype(iTimeout)>(tProcTick - tNow, 0);
154  }
155 
156  bool old = isInManualLoop;
157  isInManualLoop = true;
158  bool res = DoScheduleProcs(iTimeout);
159  isInManualLoop = old;
160  return res;
161 }
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:

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

Definition at line 189 of file StdScheduler.cpp.

References StdScheduler::Set(), StdSchedulerThread::Start(), and StdSchedulerThread::Stop().

190 {
191  // Thread is running? Stop it first
192  bool fGotThread = fThread;
193  if (fGotThread) Stop();
194  // Set
195  StdScheduler::Set(ppProcs, iProcCnt);
196  // Restart
197  if (fGotThread) Start();
198 }
void Set(StdSchedulerProc **ppProcs, int iProcCnt)

Here is the call graph for this function:

bool StdSchedulerThread::Start ( )
inherited

Definition at line 222 of file StdScheduler.cpp.

References StdSchedulerThread::Stop().

Referenced by StdSchedulerThread::Add(), C4InteractiveThread::AddProc(), main(), StdSchedulerThread::Remove(), and StdSchedulerThread::Set().

223 {
224  // already running? stop
225  if (fThread) Stop();
226  // begin thread
227  fRunThreadRun = true;
228 #ifdef HAVE_WINTHREAD
229  iThread = _beginthread(_ThreadFunc, 0, this);
230  fThread = (iThread != -1);
231 #elif defined(HAVE_PTHREAD)
232  fThread = !pthread_create(&Thread, nullptr, _ThreadFunc, this);
233 #endif
234  // success?
235  return fThread;
236 }

Here is the call graph for this function:

Here is the caller graph for this function:

void StdScheduler::StartOnCurrentThread ( )
inherited

Definition at line 276 of file StdSchedulerMac.mm.

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

277 {
278  [[SCHAdditions requestAdditionsForScheduler:this] start];
279 }

Here is the call graph for this function:

void StdSchedulerThread::Stop ( )
inherited

Definition at line 238 of file StdScheduler.cpp.

References StdScheduler::UnBlock().

Referenced by StdSchedulerThread::Add(), StdSchedulerThread::Clear(), main(), StdSchedulerThread::Remove(), C4InteractiveThread::RemoveProc(), StdSchedulerThread::Set(), and StdSchedulerThread::Start().

239 {
240  // Not running?
241  if (!fThread) return;
242  // Set flag
243  fRunThreadRun = false;
244  // Unblock
245  UnBlock();
246 #ifdef HAVE_WINTHREAD
247  // Wait for thread to terminate itself
248  HANDLE hThread = reinterpret_cast<HANDLE>(iThread);
249  if (WaitForSingleObject(hThread, 10000) == WAIT_TIMEOUT)
250  // ... or kill it in case it refuses to do so
251  TerminateThread(hThread, -1);
252 #elif defined(HAVE_PTHREAD)
253  // wait for thread to terminate itself
254  // (without security - let's trust these unwashed hackers for once)
255  pthread_join(Thread, nullptr);
256 #endif
257  fThread = false;
258  // ok
259  return;
260 }

Here is the call graph for this function:

Here is the caller graph for this function:

void StdScheduler::UnBlock ( )
inherited

Definition at line 163 of file StdScheduler.cpp.

Referenced by StdSchedulerThread::Stop().

164 {
165  Unblocker.Notify();
166 }

Here is the caller graph for this function:

Member Data Documentation

int C4NetIOMan::iNetIOCapacity
protectedinherited

Definition at line 946 of file C4NetIO.h.

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

int C4NetIOMan::iNetIOCnt
protectedinherited

Definition at line 946 of file C4NetIO.h.

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

C4NetIO** C4NetIOMan::ppNetIO
protectedinherited

Definition at line 947 of file C4NetIO.h.

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


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