| 432 | } |
| 433 | |
| 434 | SelectResult SocketSet::select(u32 timeout_ms) |
| 435 | { |
| 436 | struct timeval tv; |
| 437 | tv.tv_sec = timeout_ms / 1000; |
| 438 | tv.tv_usec = timeout_ms % 1000 * 1000; |
| 439 | |
| 440 | SelectResult sr; |
| 441 | sr.num_ready = 0; |
| 442 | int ret = ::select( |
| 443 | #if CROWN_PLATFORM_WINDOWS |
| 444 | 0 // Ignored: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-select |
| 445 | #else |
| 446 | _priv->maxfd + 1 |
| 447 | #endif |
| 448 | , &_priv->fdset |
| 449 | , NULL |
| 450 | , NULL |
| 451 | , (timeout_ms == UINT32_MAX) ? NULL : &tv |
| 452 | ); |
| 453 | |
| 454 | if (ret == SOCKET_ERROR) { |
| 455 | sr.error = SelectResult::GENERIC_ERROR; |
| 456 | } else if (ret == 0) { |
| 457 | sr.error = SelectResult::TIMEOUT; |
| 458 | } else { |
| 459 | sr.error = SelectResult::SUCCESS; |
| 460 | sr.num_ready = ret; |
| 461 | } |
| 462 | |
| 463 | return sr; |
| 464 | } |
| 465 | |
| 466 | } // namespace crown |