Changeset 7801 for code/trunk/src/libraries/network/MasterServerComm.cc
- Timestamp:
- Dec 22, 2010, 7:24:24 PM (13 years ago)
- Location:
- code/trunk
- Files:
-
- 1 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
-
code/trunk/src/libraries/network/MasterServerComm.cc
r7786 r7801 48 48 49 49 /* initialize the event holder */ 50 this->event = (ENetEvent *)calloc( sizeof(ENetEvent), 1 );50 // this->event = (ENetEvent *)calloc( sizeof(ENetEvent), 1 ); 51 51 52 52 … … 90 90 91 91 /* 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 ) 94 94 COUT(3) << "Connection to master server succeeded.\n"; 95 95 else … … 103 103 return 0; 104 104 } 105 106 void MasterServerComm::update() 107 { 108 while( enet_host_service( this->client, &this->event, 1 ) ); 109 } 110 105 111 106 112 int MasterServerComm::disconnect( void ) 107 113 { 114 while( enet_host_service( this->client, &this->event, 1 ) ); 108 115 enet_peer_disconnect( this->peer, 0 ); 109 116 … … 111 118 * and drop any packets received packets. 112 119 */ 113 while (enet_host_service (this->client, this->event, 1000) > 0)120 while (enet_host_service (this->client, &this->event, 1000) > 0) 114 121 { 115 switch (this->event ->type)122 switch (this->event.type) 116 123 { 117 124 case ENET_EVENT_TYPE_RECEIVE: 118 enet_packet_destroy (event ->packet);125 enet_packet_destroy (event.packet); 119 126 break; 120 127 … … 154 161 /* enet_host_service returns 0 if no event occured */ 155 162 /* 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 ) 157 164 { 158 165 /* check what type of event it is and react accordingly */ 159 switch (this->event ->type)166 switch (this->event.type) 160 167 { /* new connection, not supposed to happen. */ 161 168 case ENET_EVENT_TYPE_CONNECT: break; … … 173 180 174 181 /* resolve IP */ 175 enet_address_get_host_ip( &(this->event ->peer->address),182 enet_address_get_host_ip( &(this->event.peer->address), 176 183 addrconv, 49 ); 177 184 178 185 /* DEBUG */ 179 186 COUT(3) << "MasterServer Debug: A packet of length " 180 << this->event ->packet->dataLength181 << " containing " << this->event ->packet->data187 << this->event.packet->dataLength 188 << " containing " << this->event.packet->data 182 189 << " was received from " << addrconv 183 << " on channel " << this->event ->channelID;190 << " on channel " << this->event.channelID; 184 191 /* END DEBUG */ 185 192 186 193 /* call the supplied callback, if any. */ 187 194 if( (*callback) != NULL ) 188 retval = (*callback)( addrconv, (this->event) );195 retval = (*callback)( addrconv, &(this->event) ); 189 196 190 197 /* clean up */ 191 enet_packet_destroy( event ->packet );198 enet_packet_destroy( event.packet ); 192 199 if( addrconv ) 193 200 free( addrconv ); … … 220 227 221 228 /* 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 ); 223 231 224 232 /* all done. */ … … 239 247 /* One could just use enet_host_service() instead. */ 240 248 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 ); 242 251 243 252 /* all done. */
Note: See TracChangeset
for help on using the changeset viewer.