- Timestamp:
- Dec 11, 2010, 9:07:55 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation/src/libraries/network/MasterServerComm.cc
r7745 r7756 38 38 } 39 39 40 41 40 int MasterServerComm::initialize() 42 41 { … … 52 51 /* install atexit handler for enet */ 53 52 atexit( enet_deinitialize ); 54 55 53 56 54 /* initiate the client */ … … 87 85 if (this->peer == NULL ) 88 86 { COUT(2) << "ERROR: No available peers for initiating an ENet connection.\n"; 89 return -1;87 return -1; 90 88 } 91 89 … … 102 100 } 103 101 104 return 0; 105 } 106 107 int MasterServerComm::pollForReply( int (*callback)( char*, ENetEvent* ) ) 102 /* all fine */ 103 return 0; 104 } 105 106 /* NOTE this is to be reimplemented soon to return 107 * a structure containing 108 * - addrconv 109 * - the event 110 * so we can also make callbacks from objects 111 */ 112 int MasterServerComm::pollForReply( int (*callback)( char*, ENetEvent* ), 113 int delayms ) 108 114 { 109 115 /* see whether anything happened */ … … 117 123 /* enet_host_service returns 0 if no event occured */ 118 124 /* just newly set below test to >0 from >= 0, to be tested */ 119 if( enet_host_service( this->client, this->event, 1000) > 0 )125 if( enet_host_service( this->client, this->event, delayms ) > 0 ) 120 126 { 121 127 /* check what type of event it is and react accordingly */ … … 140 146 141 147 /* DEBUG */ 142 COUT(3) << "A packet of length " << this->event->packet->dataLength 148 COUT(3) << "MasterServer Debug: A packet of length " 149 << this->event->packet->dataLength 143 150 << " containing " << this->event->packet->data 144 151 << " was received from " << addrconv 145 152 << " on channel " << this->event->channelID; 146 //printf( "A packet of length %u containing %s was "147 //"received from %s on channel %u.\n",148 //this->event->packet->dataLength,149 //this->event->packet->data,150 //addrconv,151 //this->event->channelID );152 153 /* END DEBUG */ 153 154 … … 156 157 retval = (*callback)( addrconv, (this->event) ); 157 158 159 /* clean up */ 158 160 enet_packet_destroy( event->packet ); 159 if( addrconv ) free( addrconv ); 161 if( addrconv ) 162 free( addrconv ); 163 160 164 break; 161 165 default: break; … … 211 215 212 216 } 213 214 215 /* DON'T DELETE THIS I MIGHT NEED IT AGAIN -smerkli */216 /* not needed anymore, only here for testing purposes */217 /*218 //[> sample callback to output debugging info. <]219 //int callb( char *addr, ENetEvent *ev )220 //{221 //printf( "A packet of length %u containing %s was "222 //"received from %s on channel %u.\n",223 //ev->packet->dataLength,224 //ev->packet->data,225 //addr,226 //ev->channelID );227 //return 0;228 //}229 230 //[> small testing implementation <]231 //int232 //main( int argc, char *argv[] )233 //{234 //[> setup object and connect <]235 //MasterServerComm msc = MasterServerComm();236 //if( msc.connect( argv[1], 1234 ) )237 //exit(EXIT_FAILURE);238 239 //[> send some data and poll for replies <]240 //char *theinput = (char *)calloc( 100,1 );241 //while( true )242 //{243 //fgets( theinput, 90, stdin );244 //if( !strncmp( theinput, "quit", 4 ) )245 //break;246 247 //msc.sendRequest( theinput );248 //msc.pollForReply( &callb );249 //}250 251 //}252 */
Note: See TracChangeset
for help on using the changeset viewer.