| 766 | } |
| 767 | |
| 768 | void setGenericTimeout(THRIFT_SOCKET s, int timeout_ms, int optname) { |
| 769 | if (timeout_ms < 0) { |
| 770 | char errBuf[512]; |
| 771 | sprintf(errBuf, "TSocket::setGenericTimeout with negative input: %d\n", timeout_ms); |
| 772 | TOutput::instance()(errBuf); |
| 773 | return; |
| 774 | } |
| 775 | |
| 776 | if (s == THRIFT_INVALID_SOCKET) { |
| 777 | return; |
| 778 | } |
| 779 | |
| 780 | #ifdef _WIN32 |
| 781 | DWORD platform_time = static_cast<DWORD>(timeout_ms); |
| 782 | #else |
| 783 | struct timeval platform_time = {(int)(timeout_ms / 1000), (int)((timeout_ms % 1000) * 1000)}; |
| 784 | #endif |
| 785 | |
| 786 | int ret = setsockopt(s, SOL_SOCKET, optname, cast_sockopt(&platform_time), sizeof(platform_time)); |
| 787 | if (ret == -1) { |
| 788 | int errno_copy |
| 789 | = THRIFT_GET_SOCKET_ERROR; // Copy THRIFT_GET_SOCKET_ERROR because we're allocating memory. |
| 790 | TOutput::instance().perror("TSocket::setGenericTimeout() setsockopt() ", errno_copy); |
| 791 | } |
| 792 | } |
| 793 | |
| 794 | void TSocket::setRecvTimeout(int ms) { |
| 795 | setGenericTimeout(socket_, ms, SO_RCVTIMEO); |
no test coverage detected