![]() |
jsocketpp 1.0
A cross-platform C++20 socket library.
|
RAII helper for temporarily overriding a socket's blocking mode. More...
#include <ScopedBlockingMode.hpp>
Public Member Functions | |
ScopedBlockingMode (const SOCKET sock, bool temporaryNonBlocking) | |
Construct a ScopedBlockingMode that temporarily overrides the socket's blocking mode. | |
~ScopedBlockingMode () | |
Restore the socket's original blocking mode on destruction. |
Private Attributes | |
SOCKET | _sock |
Socket descriptor being managed for temporary mode override. | |
bool | _wasBlocking {} |
Whether the socket was originally in blocking mode. |
RAII helper for temporarily overriding a socket's blocking mode.
This class manages a temporary change to a socket's blocking/non-blocking state. On construction, it queries the socket's current mode and applies the requested override. When the object is destroyed (typically at the end of a scope), the original blocking mode is restored automatically, ensuring consistent socket state even in the presence of exceptions.
Primarily used in socket operations like connect() that require temporarily switching to non-blocking mode to perform select()-based timeout handling without permanently altering the socket's mode.
|
private |
Socket descriptor being managed for temporary mode override.
|
private |
Whether the socket was originally in blocking mode.