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

TCP client socket abstraction for jsocketpp. More...

Go to the source code of this file.

Classes

class  jsocketpp::Socket
 TCP client connection abstraction (Java-like interface). More...

Namespaces

namespace  jsocketpp
 A C++ socket library providing Java-style networking interfaces.

Variables

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

Detailed Description

TCP client socket abstraction for jsocketpp.

Author
MangaD
Date
2025
Version
1.0

Variable Documentation

◆ DefaultBufferSize

std::size_t jsocketpp::DefaultBufferSize
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:

  • Client-side Socket instances constructed without a custom buffer size
  • Server-accepted Socket instances created via ServerSocket::accept()

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()