Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 22, 2010, 7:24:24 PM (13 years ago)
Author:
dafrick
Message:

Merging presentation2 branch back to trunk.

Location:
code/trunk
Files:
1 edited
1 copied

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/libraries/network/MasterServerComm.cc

    r7786 r7801  
    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, 2000) > 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. */
Note: See TracChangeset for help on using the changeset viewer.