jsocketpp 1.0
A cross-platform C++20 socket library.
Loading...
Searching...
No Matches

Implementation-only utilities for internal use. More...

Collaboration diagram for Internal Helpers:

Namespaces

namespace  jsocketpp::internal
 Implementation-only utilities and platform abstractions for jsocketpp.

Classes

class  jsocketpp::internal::ScopedBlockingMode
 RAII helper for temporarily overriding a socket's blocking mode. More...

Functions

std::vector< WSABUF > jsocketpp::internal::toWSABUF (const BufferView *buffers, const std::size_t count)
 Convert a raw array of BufferView elements into a WSABUF array for use with Windows socket APIs.
std::vector< WSABUF > jsocketpp::internal::toWSABUF (const std::span< const BufferView > buffers)
 Convert a span of BufferView elements into a WSABUF array (Windows).
std::vector< iovec > jsocketpp::internal::toIOVec (const BufferView *buffers, const std::size_t count)
 Convert a raw array of BufferView elements into an iovec array for POSIX readv/writev.
std::vector< iovec > jsocketpp::internal::toIOVec (const std::span< const BufferView > buffers)
 Convert a span of BufferView elements into an iovec array for POSIX vectorized I/O.
 jsocketpp::internal::ScopedBlockingMode::ScopedBlockingMode (const SOCKET sock, bool temporaryNonBlocking)
 Construct a ScopedBlockingMode that temporarily overrides the socket's blocking mode.
 jsocketpp::internal::ScopedBlockingMode::~ScopedBlockingMode ()
 Restore the socket's original blocking mode on destruction.

Detailed Description

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.

Function Documentation

◆ 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
sockThe native socket descriptor (platform-specific type: SOCKET on Windows, int on POSIX).
temporaryNonBlockingIf 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_errorif 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]buffersPointer to a contiguous array of BufferView elements.
[in]countThe 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
[in]buffersA span of BufferView elements.
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]buffersPointer to a contiguous array of BufferView structures.
[in]countThe 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]buffersA 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()