TCP client socket abstraction for jsocketpp.
More...
Go to the source code of this file.
|
| namespace | jsocketpp |
| | A C++ socket library providing Java-style networking interfaces.
|
|
| constexpr std::size_t | DefaultBufferSize |
| | Default internal buffer size (in bytes) for socket read operations.
|
TCP client socket abstraction for jsocketpp.
- Author
- MangaD
- Date
- 2025
- Version
- 1.0
◆ DefaultBufferSize
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()