| 72 | } |
| 73 | |
| 74 | static bool set_sockopt_timeo(ACL_SOCKET fd, int opt, int timeout) |
| 75 | { |
| 76 | if (timeout <= 0) { |
| 77 | return true; |
| 78 | } |
| 79 | |
| 80 | # if defined(_WIN32) || defined(_WIN64) |
| 81 | timeout *= 1000; // From seconds to millisecond. |
| 82 | if (setsockopt(fd, SOL_SOCKET, opt, (const char*) &timeout, sizeof(timeout)) < 0) { |
| 83 | logger_error("setsockopt error=%s, timeout=%d, opt=%d, fd=%d", |
| 84 | last_serror(), timeout, opt, (int) fd); |
| 85 | return false; |
| 86 | } |
| 87 | # else // Must be Linux or __APPLE__. |
| 88 | struct timeval tm; |
| 89 | tm.tv_sec = timeout; |
| 90 | tm.tv_usec = 0; |
| 91 | |
| 92 | if (setsockopt(fd, SOL_SOCKET, opt, &tm, sizeof(tm)) < 0) { |
| 93 | logger_error("setsockopt error=%s, timeout=%d, opt=%d, fd=%d", |
| 94 | last_serror(), timeout, opt, (int) fd); |
| 95 | return false; |
| 96 | } |
| 97 | # endif |
| 98 | |
| 99 | return true; |
| 100 | } |
| 101 | |
| 102 | bool stream::set_rw_timeout(int n, bool use_sockopt /* false */) |
| 103 | { |
no test coverage detected
searching dependent graphs…