MCPcopy Create free account
hub / github.com/OpenStarbound/OpenStarbound / setNonBlocking

Method setNonBlocking

source/core/StarSocket.cpp:165–180  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

163}
164
165void 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
182NetworkMode Socket::networkMode() const {
183 ReadLocker locker(m_mutex);

Callers 4

openMethod · 0.80
UdpServerMethod · 0.80
TcpServerMethod · 0.80
TESTFunction · 0.80

Calls 2

netErrorStringFunction · 0.85
formatFunction · 0.70

Tested by 1

TESTFunction · 0.64