Sese Framework  2.3.0
A cross-platform framework
Loading...
Searching...
No Matches
sese::net::ReusableSocket Class Reference

Reusable socket builder for address and port. More...

#include <ReusableSocket.h>

Public Member Functions

 ReusableSocket (IPAddress::Ptr address, Socket::Type type=Socket::Type::TCP)
 
socket_t makeRawSocket () noexcept
 
std::optional< SocketmakeSocket () noexcept
 

Protected Member Functions

std::optional< SocketbuiltinMakeSocket () noexcept
 

Protected Attributes

IPAddress::Ptr addr {}
 
Socket::Type type {}
 

Detailed Description

Reusable socket builder for address and port.

Warning
The behavior of sockets built with this builder is inconsistent across platforms

Linux: The kernel handles load balancing, and multiple sockets can receive connections

Darwin: No load balancing, only the last socket can receive connections

Windows: No load balancing, only the first socket can receive connections

See also
https://www.cnblogs.com/xybaby/p/7341579.html

Constructor & Destructor Documentation

◆ ReusableSocket()

ReusableSocket::ReusableSocket ( IPAddress::Ptr address,
Socket::Type type = Socket::Type::TCP )
explicit

Initialize the reusable socket template for address and port

Parameters
addressThe address
typeThe type

Member Function Documentation

◆ builtinMakeSocket()

std::optional< Socket > ReusableSocket::builtinMakeSocket ( )
protectednoexcept

◆ makeRawSocket()

sese::socket_t ReusableSocket::makeRawSocket ( )
noexcept

Build a native socket according to the template

Return values
-1Creation failed
Returns
Native socket

References builtinMakeSocket().

Referenced by sese::service::SystemBalanceLoader::init().

◆ makeSocket()

std::optional< Socket > ReusableSocket::makeSocket ( )
noexcept

Build a sese::net::Socket according to the template

Return values
nullptrCreation failed
Returns
sese::net::Socket

References builtinMakeSocket().

Member Data Documentation

◆ addr

IPAddress::Ptr sese::net::ReusableSocket::addr {}
protected

Referenced by builtinMakeSocket().

◆ type

Socket::Type sese::net::ReusableSocket::type {}
protected

Referenced by builtinMakeSocket().


The documentation for this class was generated from the following files: