Browse Source

fix array usage

Kolja Strohm 2 năm trước cách đây
mục cha
commit
f0687e7574
2 tập tin đã thay đổi với 6 bổ sung12 xóa
  1. 6 11
      AnmeldungServer/AnmeldungServer.cpp
  2. 0 1
      AnmeldungServer/AnmeldungServer.h

+ 6 - 11
AnmeldungServer/AnmeldungServer.cpp

@@ -11,7 +11,6 @@ AnmeldungServer::AnmeldungServer( InitDatei *zIni )
     Network::Start( 100 );
     std::cout << "AS: Verbindung mit Datenbank wird hergestellt...\n";
     db = new ASDatenbank( zIni );
-    klientAnzahl = 0;
     klients = new RCArray< ASKlient >();
     empfangen = 0;
     gesendet = 0;
@@ -87,8 +86,7 @@ void AnmeldungServer::thread()
         Framework::getThreadRegister()->cleanUpClosedThreads();
         ASKlient *clHandle = new ASKlient( klient, dynamic_cast<AnmeldungServer *>( getThis() ) );
         EnterCriticalSection( &cs );
-        klients->set( clHandle, klientAnzahl );
-        klientAnzahl++;
+        klients->add( clHandle );
         LeaveCriticalSection( &cs );
         clHandle->start();
     }
@@ -102,10 +100,9 @@ void AnmeldungServer::close()
     warteAufThread( 1000 );
 #endif
     EnterCriticalSection( &cs );
-    for( int i = 0; i < klientAnzahl; i++ )
-        klients->z( i )->absturz();
+    for( ASKlient *client : *klients )
+        client->absturz();
     klients = ( RCArray<ASKlient>* )klients->release();
-    klientAnzahl = 0;
     LeaveCriticalSection( &cs );
     ende();
     run = 0;
@@ -207,13 +204,12 @@ bool AnmeldungServer::absturzKlient( int klientId )
 {
     bool gefunden = 0;
     EnterCriticalSection( &cs );
-    for( int i = 0; i < klientAnzahl; i++ )
+    for( int i = 0; i < klients->getEintragAnzahl(); i++ )
     {
         if( klients->z( i )->getKlientNummer() == klientId )
         {
             klients->z( i )->absturz();
             klients->remove( i );
-            klientAnzahl--;
             gefunden = 1;
             break;
         }
@@ -226,12 +222,11 @@ bool AnmeldungServer::removeKlient( ASKlient *zKlient )
 {
     bool gefunden = 0;
     EnterCriticalSection( &cs );
-    for( int i = 0; i < klientAnzahl; i++ )
+    for( int i = 0; i < klients->getEintragAnzahl(); i++ )
     {
         if( klients->z( i ) == zKlient )
         {
             klients->remove( i );
-            klientAnzahl--;
             gefunden = 1;
             break;
         }
@@ -268,7 +263,7 @@ ASDatenbank *AnmeldungServer::zDB() const
 
 bool AnmeldungServer::hatClients() const
 {
-    return klientAnzahl > 0;
+    return klients->hat(0);
 }
 
 int AnmeldungServer::getId() const

+ 0 - 1
AnmeldungServer/AnmeldungServer.h

@@ -23,7 +23,6 @@ private:
     CRITICAL_SECTION cs;
     RCArray< ASKlient > *klients;
     Text *fehler;
-    int klientAnzahl;
     int id;
     bool nichtPausiert;
     int empfangen;