| 33 | } |
| 34 | |
| 35 | void SocketUtil::SetBlock(SOCKET fd, int write_timeout) |
| 36 | { |
| 37 | #if defined(__linux) || defined(__linux__) |
| 38 | int flags = fcntl(fd, F_GETFL, 0); |
| 39 | fcntl(fd, F_SETFL, flags&(~O_NONBLOCK)); |
| 40 | #elif defined(WIN32) || defined(_WIN32) |
| 41 | unsigned long on = 0; |
| 42 | ioctlsocket(fd, FIONBIO, &on); |
| 43 | #else |
| 44 | #endif |
| 45 | if(write_timeout > 0) |
| 46 | { |
| 47 | #ifdef SO_SNDTIMEO |
| 48 | #if defined(__linux) || defined(__linux__) |
| 49 | struct timeval tv = {write_timeout/1000, (write_timeout%1000)*1000}; |
| 50 | setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, (char*)&tv, sizeof tv); |
| 51 | #elif defined(WIN32) || defined(_WIN32) |
| 52 | unsigned long ms = (unsigned long)write_timeout; |
| 53 | setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, (char *)&ms, sizeof(unsigned long)); |
| 54 | #else |
| 55 | #endif |
| 56 | #endif |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | void SocketUtil::SetReuseAddr(SOCKET sockfd) |
| 61 | { |
nothing calls this directly
no outgoing calls
no test coverage detected