| 396 | // ---------------------------------------------------------------------------------------- |
| 397 | |
| 398 | bool connection:: |
| 399 | readable ( |
| 400 | unsigned long timeout |
| 401 | ) const |
| 402 | { |
| 403 | fd_set read_set; |
| 404 | // initialize read_set |
| 405 | FD_ZERO(&read_set); |
| 406 | |
| 407 | // add the listening socket to read_set |
| 408 | FD_SET(connection_socket, &read_set); |
| 409 | |
| 410 | // setup a timeval structure |
| 411 | timeval time_to_wait; |
| 412 | time_to_wait.tv_sec = static_cast<long>(timeout/1000); |
| 413 | time_to_wait.tv_usec = static_cast<long>((timeout%1000)*1000); |
| 414 | |
| 415 | // wait on select |
| 416 | int status = select(0,&read_set,0,0,&time_to_wait); |
| 417 | |
| 418 | // if select timed out or there was an error |
| 419 | if (status <= 0) |
| 420 | return false; |
| 421 | |
| 422 | // data is ready to be read |
| 423 | return true; |
| 424 | } |
| 425 | |
| 426 | // ---------------------------------------------------------------------------------------- |
| 427 | |