[Orxonox-commit 3066] r7761 - code/branches/presentation/src/libraries/network

smerkli at orxonox.net smerkli at orxonox.net
Wed Dec 15 13:39:56 CET 2010


Author: smerkli
Date: 2010-12-15 13:39:56 +0100 (Wed, 15 Dec 2010)
New Revision: 7761

Modified:
   code/branches/presentation/src/libraries/network/MasterServerComm.cc
   code/branches/presentation/src/libraries/network/MasterServerComm.h
   code/branches/presentation/src/libraries/network/Server.cc
Log:
disconnect implemented, getting ready for testing.

Modified: code/branches/presentation/src/libraries/network/MasterServerComm.cc
===================================================================
--- code/branches/presentation/src/libraries/network/MasterServerComm.cc	2010-12-15 09:59:10 UTC (rev 7760)
+++ code/branches/presentation/src/libraries/network/MasterServerComm.cc	2010-12-15 12:39:56 UTC (rev 7761)
@@ -48,8 +48,6 @@
     /* initialize the event holder */
     this->event = (ENetEvent *)calloc( sizeof(ENetEvent), 1 );
     
-    /* install atexit handler for enet */
-    atexit( enet_deinitialize );
 
     /* initiate the client */
     this->client = enet_host_create( NULL /* create a client host */,
@@ -71,6 +69,9 @@
   {
     /* destroy the enet facilities */
     enet_host_destroy(this->client);
+
+    /* install atexit handler for enet */
+    enet_deinitialize();
   }
 
   int MasterServerComm::connect( const char *address, unsigned int port )
@@ -103,6 +104,37 @@
     return 0;
   }
 
+  int MasterServerComm::disconnect( void )
+  {
+    enet_peer_disconnect( this->peer, 0 );
+
+    /* Allow up to 1 second for the disconnect to succeed
+     * and drop any packets received packets.
+     */
+    while (enet_host_service (this->client, this->event, 1000) > 0)
+    {
+      switch (this->event->type)
+      {
+        case ENET_EVENT_TYPE_RECEIVE:
+          enet_packet_destroy (event->packet);
+          break;
+
+        case ENET_EVENT_TYPE_DISCONNECT:
+          COUT(4) << "Disconnect from master server successful.\n"; 
+          return 0;
+        default: break;
+      }
+    }
+
+    /* We've arrived here, so the disconnect attempt didn't
+     * succeed yet, hence: force the connection down.            
+     */
+    enet_peer_reset( this->peer );
+
+    /* done */
+    return 0;
+  }
+
   /* NOTE this is to be reimplemented soon to return 
    * a structure containing 
    * - addrconv

Modified: code/branches/presentation/src/libraries/network/MasterServerComm.h
===================================================================
--- code/branches/presentation/src/libraries/network/MasterServerComm.h	2010-12-15 09:59:10 UTC (rev 7760)
+++ code/branches/presentation/src/libraries/network/MasterServerComm.h	2010-12-15 12:39:56 UTC (rev 7761)
@@ -61,6 +61,12 @@
        */
       int connect( const char *address, unsigned int port );
 
+      /** \return 0 for success, other for error
+       * 
+       * Disconnect from master server.
+       */
+      int disconnect();
+
       /** \param data The data to be sent. 
        * \return 0 for success, other for error. 
        * 

Modified: code/branches/presentation/src/libraries/network/Server.cc
===================================================================
--- code/branches/presentation/src/libraries/network/Server.cc	2010-12-15 09:59:10 UTC (rev 7760)
+++ code/branches/presentation/src/libraries/network/Server.cc	2010-12-15 12:39:56 UTC (rev 7761)
@@ -151,6 +151,7 @@
     COUT(4) << "closing server" << endl;
     this->disconnectClients();
     this->closeListener();
+    this->msc.disconnect();
     LANDiscoverable::setActivity(false);
     return;
   }




More information about the Orxonox-commit mailing list