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

Internal types, platform abstractions, and utility functions used across the jsocketpp library. More...

Collaboration diagram for Core Utilities and Types:

Namespaces

namespace  jsocketpp::net
 Endianness utilities for network byte order conversion.

Classes

struct  jsocketpp::BufferView
 Represents a raw writable memory region for scatter/gather I/O. More...

Typedefs

using jsocketpp::Port = std::uint16_t
 Type alias representing a TCP or UDP port number (1–65535).

Functions

bool jsocketpp::isIPv4MappedIPv6 (const sockaddr_in6 *addr6)
 Checks if a given sockaddr_in6 represents an IPv4-mapped IPv6 address.
sockaddr_in jsocketpp::convertIPv4MappedIPv6ToIPv4 (const sockaddr_in6 &addr6)
 Converts an IPv4-mapped IPv6 address to a pure IPv4 sockaddr_in.

Variables

constexpr std::size_t jsocketpp::DefaultBufferSize = 4096
 Default internal buffer size (in bytes) for TCP socket read operations.

Detailed Description

Internal types, platform abstractions, and utility functions used across the jsocketpp library.

This group contains foundational components of the jsocketpp socket library, including common type aliases, byte-order conversion utilities, and cross-platform compatibility helpers.

Components in this group are typically not used directly by application-level code, but are essential for internal implementation and protocol correctness.

Includes:

  • jsocketpp::Port – type alias for network ports
  • jsocketpp::net – byte order conversion utilities (host ↔ network)
  • Platform-specific type abstractions (SOCKET, INVALID_SOCKET, etc.)
See also
jsocketpp::net
Port

Typedef Documentation

◆ Port

using jsocketpp::Port = std::uint16_t

Type alias representing a TCP or UDP port number (1–65535).

This alias provides strong typing for network port numbers across the jsocketpp library. It improves readability and makes function signatures semantically clearer when dealing with socket operations.

Using Port instead of a plain uint16_t or unsigned short helps:

  • Differentiate port values from other numeric parameters
  • Assist with static analysis and overload resolution
  • Align with best practices in modern C++ design
Note
Although a Port is technically an integer, it represents a well-defined semantic domain (TCP/UDP port number).

Function Documentation

◆ convertIPv4MappedIPv6ToIPv4()

sockaddr_in jsocketpp::convertIPv4MappedIPv6ToIPv4 ( const sockaddr_in6 & addr6)
inline

Converts an IPv4-mapped IPv6 address to a pure IPv4 sockaddr_in.

This function extracts the embedded IPv4 address from an IPv4-mapped IPv6 address. It preserves the port number and fills a fully valid sockaddr_in.

Preconditions

  • The input must be an IPv4-mapped IPv6 address.
  • You should call isIPv4MappedIPv6() before using this function.
Parameters
addr6A sockaddr_in6 known to be IPv4-mapped.
Returns
A sockaddr_in representing the embedded IPv4 address and port.

◆ isIPv4MappedIPv6()

bool jsocketpp::isIPv4MappedIPv6 ( const sockaddr_in6 * addr6)
inline

Checks if a given sockaddr_in6 represents an IPv4-mapped IPv6 address.

IPv4-mapped IPv6 addresses allow IPv6-only sockets to interoperate with IPv4 clients by embedding an IPv4 address inside a special IPv6 format:

::ffff:a.b.c.d // 0000:0000:0000:0000:0000:ffff:abcd:efgh

This function identifies such addresses so they can be normalized to pure IPv4.

Parameters
addr6Pointer to a sockaddr_in6 structure.
Returns
true if the address is IPv4-mapped; false otherwise.

Variable Documentation

◆ DefaultBufferSize

std::size_t jsocketpp::DefaultBufferSize = 4096
inlineconstexpr

Default internal buffer size (in bytes) for TCP socket read operations.

This constant defines the default size (4096 bytes / 4 KB) of the internal read buffer used by both Socket and ServerSocket instances unless explicitly overridden.

It applies to:

Rationale

  • Memory-efficient: 4096 bytes matches the typical memory page size on most operating systems.
  • Performance-optimized: Large enough to hold common protocol messages (e.g., HTTP headers, WebSocket frames) without reallocation or multiple reads.
  • Concurrency-friendly: Balances throughput and memory footprint across thousands of concurrent connections.

Customization

  • You may override this value by:
    • Passing a custom bufferSize to Socket or ServerSocket::accept()
    • Calling setInternalBufferSize() after construction
    • Setting SO_RCVBUF via setReceiveBufferSize() for kernel buffer tuning

When to Adjust

  • Increase if your application routinely expects:
    • High-throughput data transfers
    • Large protocol frames (e.g., file uploads, streaming)
  • Decrease for memory-constrained or embedded environments
See also
Socket
ServerSocket
Socket::setInternalBufferSize()
Socket::setReceiveBufferSize()
Socket::setSendBufferSize()