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 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 socket read operations.

This constant defines the default size (4096 bytes / 4 KB) of the internal read buffer used across various socket classes in the library unless explicitly overridden.

Applies to

  • TCP client sockets (Socket) when constructed without a custom internalBufferSize
  • Accepted TCP sockets via ServerSocket::accept()
  • UDP sockets (DatagramSocket) when no explicit bufferSize is passed
  • May also serve as a guideline for other buffer sizes (e.g., send/receive buffers)

Rationale

  • Memory-efficient: 4096 bytes aligns with the typical memory page size on most systems.
  • Performance-optimized: Large enough for common protocol messages (e.g., HTTP, DNS, WebSocket)
  • Concurrency-friendly: Balances throughput and memory usage across many simultaneous sockets.

Customization

Override this value by:

  • Passing a custom buffer size to socket constructors (e.g., DatagramSocket(port, 8192))
  • Calling setInternalBufferSize() after construction
  • Tuning system-level buffers via setReceiveBufferSize() or setSendBufferSize()

When to Adjust

Increase if:

  • Your application transfers large datagrams or stream data (e.g., file uploads, media streams)
  • You want to reduce syscall overhead by reading more per call

Decrease if:

  • Operating in memory-constrained environments (e.g., embedded systems)
  • Managing a large number of idle sockets where footprint matters more than speed
See also
Socket
ServerSocket
DatagramSocket
Socket::setInternalBufferSize()
SocketOptions::setReceiveBufferSize()
SocketOptions::setSendBufferSize()