Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7761


Ignore:
Timestamp:
Dec 15, 2010, 1:39:56 PM (13 years ago)
Author:
smerkli
Message:

disconnect implemented, getting ready for testing.

Location:
code/branches/presentation/src/libraries/network
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation/src/libraries/network/MasterServerComm.cc

    r7756 r7761  
    4949    this->event = (ENetEvent *)calloc( sizeof(ENetEvent), 1 );
    5050   
    51     /* install atexit handler for enet */
    52     atexit( enet_deinitialize );
    5351
    5452    /* initiate the client */
     
    7270    /* destroy the enet facilities */
    7371    enet_host_destroy(this->client);
     72
     73    /* install atexit handler for enet */
     74    enet_deinitialize();
    7475  }
    7576
     
    101102
    102103    /* all fine */
     104    return 0;
     105  }
     106
     107  int MasterServerComm::disconnect( void )
     108  {
     109    enet_peer_disconnect( this->peer, 0 );
     110
     111    /* Allow up to 1 second for the disconnect to succeed
     112     * and drop any packets received packets.
     113     */
     114    while (enet_host_service (this->client, this->event, 1000) > 0)
     115    {
     116      switch (this->event->type)
     117      {
     118        case ENET_EVENT_TYPE_RECEIVE:
     119          enet_packet_destroy (event->packet);
     120          break;
     121
     122        case ENET_EVENT_TYPE_DISCONNECT:
     123          COUT(4) << "Disconnect from master server successful.\n";
     124          return 0;
     125        default: break;
     126      }
     127    }
     128
     129    /* We've arrived here, so the disconnect attempt didn't
     130     * succeed yet, hence: force the connection down.           
     131     */
     132    enet_peer_reset( this->peer );
     133
     134    /* done */
    103135    return 0;
    104136  }
  • code/branches/presentation/src/libraries/network/MasterServerComm.h

    r7756 r7761  
    6262      int connect( const char *address, unsigned int port );
    6363
     64      /** \return 0 for success, other for error
     65       *
     66       * Disconnect from master server.
     67       */
     68      int disconnect();
     69
    6470      /** \param data The data to be sent.
    6571       * \return 0 for success, other for error.
  • code/branches/presentation/src/libraries/network/Server.cc

    r7756 r7761  
    152152    this->disconnectClients();
    153153    this->closeListener();
     154    this->msc.disconnect();
    154155    LANDiscoverable::setActivity(false);
    155156    return;
Note: See TracChangeset for help on using the changeset viewer.