Changeset 39 for oscpack/trunk/ip/posix
- Timestamp:
- 10/06/05 14:28:01 (3 years ago)
- Files:
-
- oscpack/trunk/ip/posix/UdpSocket.cpp (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
oscpack/trunk/ip/posix/UdpSocket.cpp
r38 r39 302 302 303 303 volatile bool break_; 304 int breakPipe_[2]; // [0] is the reader descriptor and [1] the writer 304 305 305 306 double GetCurrentTimeMs() const … … 315 316 Implementation() 316 317 { 318 if( pipe(breakPipe_) != 0 ) 319 throw std::runtime_error( "creation of asynchronous break pipes failed\n" ); 317 320 } 318 321 319 322 ~Implementation() 320 323 { 324 close( breakPipe_[0] ); 325 close( breakPipe_[1] ); 321 326 } 322 327 … … 370 375 FD_ZERO( &masterfds ); 371 376 FD_ZERO( &tempfds ); 372 int fdmax = 0; 377 378 // in addition to listening to the inbound sockets we 379 // also listen to the asynchronous break pipe, so that AsynchronousBreak() 380 // can break us out of select() from another thread. 381 FD_SET( breakPipe_[0], &masterfds ); 382 int fdmax = breakPipe_[0]; 373 383 374 384 for( std::vector< std::pair< PacketListener*, UdpSocket* > >::iterator i = socketListeners_.begin(); … … 406 416 timeoutMs = 0; 407 417 408 // 1000000 microseconds in a second409 timeout.tv_sec = (long)(timeoutMs * .001);410 timeout.tv_usec = (long)((timeoutMs - (timeout.tv_sec * 1000)) * 1000);418 // 1000000 microseconds in a second 419 timeout.tv_sec = (long)(timeoutMs * .001); 420 timeout.tv_usec = (long)((timeoutMs - (timeout.tv_sec * 1000)) * 1000); 411 421 timeoutPtr = &timeout; 412 422 } … … 415 425 throw std::runtime_error("select failed\n"); 416 426 } 427 428 if ( FD_ISSET( breakPipe_[0], &tempfds ) ){ 429 // clear pending data from the asynchronous break pipe 430 char c; 431 read( breakPipe_[0], &c, 1 ); 432 } 433 417 434 if( break_ ) 418 435 break; … … 460 477 { 461 478 break_ = true; 462 // FIXME: need to do something here to break through the select, not sure what 463 // for now single threaded apps will work fine because ctrl-c will cause464 // our select call to fall out with an E_INTR or something479 480 // Send a termination message to the asynchronous break pipe, so select() will return 481 write( breakPipe_[1], "!", 1 ); 465 482 } 466 483 };
