107 throw std::runtime_error(
"Failed to get socket mode");
111 const int flags = fcntl(
_sock, F_GETFL, 0);
113 throw std::runtime_error(
"Failed to get socket flags");
121 u_long newMode = temporaryNonBlocking ? 1 : 0;
123 throw std::runtime_error(
"Failed to set socket mode");
125 if (
const int newFlags = temporaryNonBlocking ? (flags | O_NONBLOCK) : (flags & ~O_NONBLOCK);
126 fcntl(
_sock, F_SETFL, newFlags) == -1)
127 throw std::runtime_error(
"Failed to set socket mode");
162 if (
const int flags = fcntl(
_sock, F_GETFL, 0); flags != -1)
164 const int newFlags =
_wasBlocking ? (flags & ~O_NONBLOCK) : (flags | O_NONBLOCK);
165 fcntl(
_sock, F_SETFL, newFlags);
SOCKET _sock
Socket descriptor being managed for temporary mode override.
Definition ScopedBlockingMode.hpp:176
bool _wasBlocking
Whether the socket was originally in blocking mode.
Definition ScopedBlockingMode.hpp:177
~ScopedBlockingMode()
Restore the socket's original blocking mode on destruction.
Definition ScopedBlockingMode.hpp:154
ScopedBlockingMode(const SOCKET sock, bool temporaryNonBlocking)
Construct a ScopedBlockingMode that temporarily overrides the socket's blocking mode.
Definition ScopedBlockingMode.hpp:102
Implementation-only utilities and platform abstractions for jsocketpp.
Definition BufferView.hpp:49
int ioctlsocket(const SOCKET fd, const long cmd, u_long *argp)
Definition common.hpp:243
int SOCKET
Definition common.hpp:219
constexpr SOCKET SOCKET_ERROR
Definition common.hpp:221