16#include <sys/socket.h>
115 throw std::runtime_error(
"Failed to get socket mode");
119 const int flags = fcntl(
_sock, F_GETFL, 0);
121 throw std::runtime_error(
"Failed to get socket flags");
129 u_long newMode = temporaryNonBlocking ? 1 : 0;
131 throw std::runtime_error(
"Failed to set socket mode");
133 if (
const int newFlags = temporaryNonBlocking ? (flags | O_NONBLOCK) : (flags & ~O_NONBLOCK);
134 fcntl(
_sock, F_SETFL, newFlags) == -1)
135 throw std::runtime_error(
"Failed to set socket mode");
170 if (
const int flags = fcntl(
_sock, F_GETFL, 0); flags != -1)
172 const int newFlags =
_wasBlocking ? (flags & ~O_NONBLOCK) : (flags | O_NONBLOCK);
173 fcntl(
_sock, F_SETFL, newFlags);
SOCKET _sock
Socket descriptor being managed for temporary mode override.
Definition ScopedBlockingMode.hpp:184
bool _wasBlocking
Whether the socket was originally in blocking mode.
Definition ScopedBlockingMode.hpp:185
~ScopedBlockingMode()
Restore the socket's original blocking mode on destruction.
Definition ScopedBlockingMode.hpp:162
ScopedBlockingMode(const SOCKET sock, bool temporaryNonBlocking)
Construct a ScopedBlockingMode that temporarily overrides the socket's blocking mode.
Definition ScopedBlockingMode.hpp:110
Implementation-only utilities and platform abstractions for jsocketpp.
Definition BufferView.hpp:52
int ioctlsocket(const SOCKET fd, const long cmd, u_long *argp)
Definition common.hpp:287
int SOCKET
Definition common.hpp:263
constexpr SOCKET SOCKET_ERROR
Definition common.hpp:265