| 163 | } |
| 164 | |
| 165 | void Socket::setNonBlocking(bool nonBlocking) { |
| 166 | ReadLocker locker(m_mutex); |
| 167 | checkOpen("Socket::setNonBlocking"); |
| 168 | #ifdef WIN32 |
| 169 | unsigned long mode = nonBlocking ? 1 : 0; |
| 170 | if (ioctlsocket(m_impl->socketDesc, FIONBIO, &mode) != 0) |
| 171 | throw NetworkException::format("Cannot set socket non-blocking mode: {}", netErrorString()); |
| 172 | #else |
| 173 | int flags = fcntl(m_impl->socketDesc, F_GETFL, 0); |
| 174 | if (flags < 0) |
| 175 | throw NetworkException::format("fcntl failure getting socket flags: {}", netErrorString()); |
| 176 | flags = nonBlocking ? (flags | O_NONBLOCK) : (flags & ~O_NONBLOCK); |
| 177 | if (fcntl(m_impl->socketDesc, F_SETFL, flags) != 0) |
| 178 | throw NetworkException::format("fcntl failure setting non-blocking mode: {}", netErrorString()); |
| 179 | #endif |
| 180 | } |
| 181 | |
| 182 | NetworkMode Socket::networkMode() const { |
| 183 | ReadLocker locker(m_mutex); |