Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7793 for code/branches


Ignore:
Timestamp:
Dec 22, 2010, 3:05:31 AM (14 years ago)
Author:
scheusso
Message:

some changes in WANDiscovering:

  • fixed a bug which caused memory corruptions (was caused by double frees)
  • separated WANDiscovery into WANDiscoverable and WANDiscovery in order to prevent crashes when destructing GSServer and Closing the Server connection
Location:
code/branches/presentation2/src/libraries/network
Files:
2 added
8 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation2/src/libraries/network/CMakeLists.txt

    r7788 r7793  
    3232  LANDiscoverable.cc
    3333  LANDiscovery.cc
     34  WANDiscoverable.cc
    3435  WANDiscovery.cc
    3536  MasterServerComm.cc
     
    5960  LANDiscoverable.h
    6061  LANDiscovery.h
     62  WANDiscoverable.h
    6163  WANDiscovery.h
    6264  MasterServerComm.h
  • code/branches/presentation2/src/libraries/network/Connection.cc

    r7788 r7793  
    112112  void Connection::communicationThread()
    113113  {
    114     COUT(0) << "starting communication thread" << endl;
    115114    ENetEvent event;
    116115   
  • code/branches/presentation2/src/libraries/network/MasterServerComm.cc

    r7788 r7793  
    4848
    4949    /* initialize the event holder */
    50     this->event = (ENetEvent *)calloc( sizeof(ENetEvent), 1 );
     50//     this->event = (ENetEvent *)calloc( sizeof(ENetEvent), 1 );
    5151   
    5252
     
    9090
    9191    /* Wait up to 2 seconds for the connection attempt to succeed. */
    92     if (enet_host_service (this->client, this->event, 500) > 0 &&
    93         this->event->type == ENET_EVENT_TYPE_CONNECT )
     92    if (enet_host_service (this->client, &this->event, 500) > 0 &&
     93        this->event.type == ENET_EVENT_TYPE_CONNECT )
    9494      COUT(3) << "Connection to master server succeeded.\n";
    9595    else
     
    103103    return 0;
    104104  }
     105 
     106void MasterServerComm::update()
     107{
     108  while( enet_host_service( this->client, &this->event, 1 ) );
     109}
     110
    105111
    106112  int MasterServerComm::disconnect( void )
    107113  {
     114    while( enet_host_service( this->client, &this->event, 1 ) );
    108115    enet_peer_disconnect( this->peer, 0 );
    109116
     
    111118     * and drop any packets received packets.
    112119     */
    113     while (enet_host_service (this->client, this->event, 1000) > 0)
     120    while (enet_host_service (this->client, &this->event, 1000) > 0)
    114121    {
    115       switch (this->event->type)
     122      switch (this->event.type)
    116123      {
    117124        case ENET_EVENT_TYPE_RECEIVE:
    118           enet_packet_destroy (event->packet);
     125          enet_packet_destroy (event.packet);
    119126          break;
    120127
     
    154161    /* enet_host_service returns 0 if no event occured */
    155162    /* just newly set below test to >0 from >= 0, to be tested */
    156     if( enet_host_service( this->client, this->event, delayms ) > 0 )
     163    if( enet_host_service( this->client, &this->event, delayms ) > 0 )
    157164    {
    158165      /* check what type of event it is and react accordingly */
    159       switch (this->event->type)
     166      switch (this->event.type)
    160167      { /* new connection, not supposed to happen. */
    161168        case ENET_EVENT_TYPE_CONNECT: break;
     
    173180
    174181          /* resolve IP */
    175           enet_address_get_host_ip( &(this->event->peer->address),
     182          enet_address_get_host_ip( &(this->event.peer->address),
    176183            addrconv, 49 );
    177184
    178185          /* DEBUG */
    179186          COUT(3) << "MasterServer Debug: A packet of length "
    180             << this->event->packet->dataLength
    181             << " containing " << this->event->packet->data
     187            << this->event.packet->dataLength
     188            << " containing " << this->event.packet->data
    182189            << " was received from " << addrconv
    183             << " on channel " << this->event->channelID;
     190            << " on channel " << this->event.channelID;
    184191          /* END DEBUG */
    185192
    186193          /* call the supplied callback, if any. */
    187194          if( (*callback) != NULL )
    188             retval = (*callback)( addrconv, (this->event) );
     195            retval = (*callback)( addrconv, &(this->event) );
    189196
    190197          /* clean up */
    191           enet_packet_destroy( event->packet );
     198          enet_packet_destroy( event.packet );
    192199          if( addrconv )
    193200            free( addrconv );
     
    220227   
    221228    /* free the packet */
    222     enet_packet_destroy( packet );
     229    // PLEASE: never do this, because enet will free the packet once it's delivered. this will cause double frees
     230//     enet_packet_destroy( packet );
    223231
    224232    /* all done. */
     
    239247    /* One could just use enet_host_service() instead. */
    240248    enet_host_flush( this->client );
    241     enet_packet_destroy( packet );
     249    // PLEASE: never do this, because enet will free the packet once it's delivered. this will cause double frees
     250//     enet_packet_destroy( packet );
    242251
    243252    /* all done. */
  • code/branches/presentation2/src/libraries/network/MasterServerComm.h

    r7770 r7793  
    5353       */
    5454      int initialize();
     55     
     56      void update();
    5557
    5658
     
    9294    private:
    9395      /** client handle */
    94       ENetHost *client;
     96      ENetHost* client;
    9597
    9698      /** event data holder */
    97       ENetEvent *event;
     99      ENetEvent event;
    98100
    99101      /** address holder */
     
    101103
    102104      /** peer data holder */
    103       ENetPeer *peer;
     105      ENetPeer* peer;
    104106  };
    105107
  • code/branches/presentation2/src/libraries/network/Server.cc

    r7788 r7793  
    104104  void Server::helper_ConnectToMasterserver()
    105105  {
    106     WANDiscovery::getInstance().msc.sendRequest( MSPROTO_GAME_SERVER " "
    107       MSPROTO_REGISTER_SERVER );
     106//     WANDiscovery::getInstance().msc.sendRequest( MSPROTO_GAME_SERVER " "
     107//       MSPROTO_REGISTER_SERVER );
    108108  }
    109109
     
    121121
    122122    /* make discoverable on WAN */
     123    WANDiscoverable::setActivity(true);
    123124    /* TODO this needs to be optional, we need a switch from the UI to
    124125     * enable/disable this
    125126     */
    126     helper_ConnectToMasterserver();
     127//     helper_ConnectToMasterserver();
    127128
    128129    /* done */
     
    142143    /* tell master server we're closing */
    143144    COUT(2) << "disconnecting." << endl;
    144     WANDiscovery::getInstance().msc.sendRequest( MSPROTO_GAME_SERVER " "
    145       MSPROTO_SERVERDC );
     145    WANDiscoverable::setActivity(false);   
    146146    COUT(2) << "disconnecting done" << endl;
    147147
     
    202202    // receive and process incoming discovery packets
    203203    LANDiscoverable::update();
    204 
     204   
    205205    // receive and process requests from master server
    206206    /* todo */
  • code/branches/presentation2/src/libraries/network/Server.h

    r7788 r7793  
    4040#include "ServerConnection.h"
    4141#include "LANDiscoverable.h"
    42 #include "MasterServerComm.h"
    43 #include "MasterServerProtocol.h"
     42#include "WANDiscoverable.h"
     43// #include "MasterServerComm.h"
     44// #include "MasterServerProtocol.h"
    4445
    4546
     
    5152  * It implements all functions necessary for a Server
    5253  */
    53   class _NetworkExport Server : public Host, public ServerConnection, public LANDiscoverable{
     54  class _NetworkExport Server : public Host, public ServerConnection, public LANDiscoverable, public WANDiscoverable
     55  {
    5456  public:
    5557    Server();
  • code/branches/presentation2/src/libraries/network/packet/ServerInformation.cc

    r7745 r7793  
    2121 *
    2222 *   Author:
    23  *      Fabian 'x3n' Landau
     23 *      Oliver Scheuss
    2424 *   Co-authors:
    2525 *      ...
     
    6060
    6161      /* Fabian, what is this used for? it crashes the masterserver, hence commenting it */
    62       //assert(strcmp(ack, (const char*)LAN_DISCOVERY_ACK)==0);
     62      // written by Oli: this is just to make sure that loadAndIncrease really writes the whole ACK string into char* ack
     63//       assert(strcmp(ack, (const char*)LAN_DISCOVERY_ACK)==0);
    6364
    6465      // Save Server Name
  • code/branches/presentation2/src/libraries/network/packet/ServerInformation.h

    r7739 r7793  
    2121 *
    2222 *   Author:
    23  *      Fabian 'x3n' Landau
     23 *      Oliver Scheuss
    2424 *   Co-authors:
    2525 *      ...
Note: See TracChangeset for help on using the changeset viewer.