Implementation-only utilities for internal use.
More...
|
namespace | jsocketpp::internal |
| Implementation-only utilities and platform abstractions for jsocketpp.
|
Implementation-only utilities for internal use.
These functions and types are not part of the public API. They are intended for internal glue code, platform compatibility, and cross-cutting concerns.
- Warning
- Do not rely on this module from user code. It is subject to change without notice.
◆ ScopedBlockingMode()
jsocketpp::internal::ScopedBlockingMode::ScopedBlockingMode |
( |
const SOCKET | sock, |
|
|
bool | temporaryNonBlocking ) |
|
inline |
Construct a ScopedBlockingMode that temporarily overrides the socket's blocking mode.
This constructor queries the current blocking state of the specified socket and sets it to the desired temporary mode (blocking or non-blocking). Upon destruction, the original mode is restored.
This is typically used to safely override a socket's mode during a scoped operation (e.g. non-blocking connect()), without permanently modifying the socket's configuration.
- Parameters
-
sock | The native socket descriptor (platform-specific type: SOCKET on Windows, int on POSIX). |
temporaryNonBlocking | If true, the socket will be set to non-blocking mode during the scope. If false, it will be temporarily set to blocking mode. |
- Exceptions
-
std::runtime_error | if querying or setting the socket mode fails. |
- Note
- The constructor reads the current mode and only applies a change if necessary.
-
If setNonBlocking() is called on the same socket while the object is alive, the final restored state may be incorrect.
- See also
- ~ScopedBlockingMode()
-
setNonBlocking()
◆ toIOVec() [1/2]
std::vector< iovec > jsocketpp::internal::toIOVec |
( |
const BufferView * | buffers, |
|
|
const std::size_t | count ) |
|
inlinenodiscard |
Convert a raw array of BufferView elements into an iovec array for POSIX readv/writev.
This function converts a contiguous C-style array of BufferView entries into a std::vector<iovec>, which can be passed directly to POSIX I/O functions like readv() and writev(). Each iovec will reflect the same memory range described by the corresponding BufferView.
- Parameters
-
[in] | buffers | Pointer to a contiguous array of BufferView elements. |
[in] | count | The number of elements in the input array. |
- Returns
- A std::vector<iovec> referencing the same memory regions.
- Note
- This function performs shallow conversion—no memory is copied.
-
Only available on non-Windows platforms (i.e., when _WIN32 is not defined).
- See also
- BufferView
-
iovec
-
readv()
-
writev()
◆ toIOVec() [2/2]
std::vector< iovec > jsocketpp::internal::toIOVec |
( |
const std::span< const BufferView > | buffers | ) |
|
|
inlinenodiscard |
Convert a span of BufferView elements into an iovec array for POSIX vectorized I/O.
This overload transforms a std::span<const BufferView> into a std::vector<iovec>, which is suitable for use with POSIX APIs such as readv() and writev().
- Parameters
-
- Returns
- A std::vector<iovec> referencing the same memory described by the span.
- Note
- This function performs shallow conversion—no memory is copied.
-
Only available on non-Windows platforms (i.e., when _WIN32 is not defined).
- See also
- BufferView
-
iovec
-
toIOVec(const BufferView*, std::size_t)
-
readv()
-
writev()
◆ toWSABUF() [1/2]
std::vector< WSABUF > jsocketpp::internal::toWSABUF |
( |
const BufferView * | buffers, |
|
|
const std::size_t | count ) |
|
inlinenodiscard |
Convert a raw array of BufferView elements into a WSABUF array for use with Windows socket APIs.
This utility function transforms a contiguous C-style array of BufferView structures into a std::vector<WSABUF>, suitable for use with Windows socket functions such as WSASend() and WSARecv(). Each WSABUF struct will point to the same memory region described by its corresponding BufferView.
- Parameters
-
[in] | buffers | Pointer to a contiguous array of BufferView structures. |
[in] | count | The number of elements in the buffers array. |
- Returns
- A std::vector<WSABUF> with one entry per buffer, preserving memory addresses and sizes.
- Note
- This function performs shallow conversion—no memory is copied.
-
This function is only available on Windows (_WIN32 defined).
- See also
- BufferView
-
WSABUF
-
WSASend()
-
WSARecv()
◆ toWSABUF() [2/2]
std::vector< WSABUF > jsocketpp::internal::toWSABUF |
( |
const std::span< const BufferView > | buffers | ) |
|
|
inlinenodiscard |
Convert a span of BufferView elements into a WSABUF array (Windows).
This overload provides a convenient interface for converting a std::span<const BufferView> into a std::vector<WSABUF> for use with Windows socket APIs such as WSASend() and WSARecv().
- Parameters
-
[in] | buffers | A std::span containing one or more BufferView elements. |
- Returns
- A std::vector<WSABUF> that references the same memory described by each BufferView.
- Note
- This function performs shallow conversion—no memory is copied.
-
This function is only available on Windows (_WIN32 defined).
- See also
- BufferView
-
WSABUF
-
toWSABUF(const BufferView*, std::size_t)
◆ ~ScopedBlockingMode()
jsocketpp::internal::ScopedBlockingMode::~ScopedBlockingMode |
( |
| ) |
|
|
inline |
Restore the socket's original blocking mode on destruction.
This destructor attempts to revert the socket descriptor to the blocking mode it had at the time of this object's construction. This ensures that any temporary change to the blocking state (via the constructor) is automatically undone, preserving consistent socket behavior after the scope ends.
This restoration is performed even if an exception was thrown inside the guarded scope, making this class suitable for safe use in exception-prone paths such as connect() with timeout logic.
- Note
- Errors during restoration are silently ignored. This is intentional to maintain noexcept destructor semantics and prevent exceptions from escaping destructors.
- Warning
- Do not call setNonBlocking() on the same socket while a ScopedBlockingMode is active, as this will interfere with the mode restoration logic.
- See also
- ScopedBlockingMode()