| 467 | } |
| 468 | |
| 469 | int NetworkServer::accept_select(int sockfd) |
| 470 | { |
| 471 | fd_set set; |
| 472 | struct timeval timeout; |
| 473 | |
| 474 | while(1) |
| 475 | { |
| 476 | timeout.tv_sec = TCP_TIMEOUT_SECONDS; |
| 477 | timeout.tv_usec = 0; |
| 478 | |
| 479 | FD_ZERO(&set); /* clear the set */ |
| 480 | FD_SET(sockfd, &set); /* add our file descriptor to the set */ |
| 481 | |
| 482 | int rv = select(sockfd + 1, &set, NULL, NULL, &timeout); |
| 483 | |
| 484 | if(rv == SOCKET_ERROR || server_online == false) |
| 485 | { |
| 486 | return -1; |
| 487 | } |
| 488 | else if(rv == 0) |
| 489 | { |
| 490 | continue; |
| 491 | } |
| 492 | else |
| 493 | { |
| 494 | // socket has something to read |
| 495 | return(accept(sockfd, NULL, NULL)); |
| 496 | } |
| 497 | } |
| 498 | } |
| 499 | |
| 500 | int NetworkServer::recv_select(SOCKET s, char *buf, int len, int flags) |
| 501 | { |