userver: engine::io::Sockaddr Class Reference
Loading...
Searching...
No Matches
engine::io::Sockaddr Class Referencefinal

#include <userver/engine/io/sockaddr.hpp>

Detailed Description

Native socket address wrapper.

Definition at line 40 of file sockaddr.hpp.

Public Member Functions

 Sockaddr () noexcept
 Constructs an unspecified native socket address.
 
 Sockaddr (const void *data)
 Wraps a native socket address structure.
 
template<typename T >
T * As ()
 Domain-specific native socket address structure pointer.
 
template<typename T >
const T * As () const
 Domain-specific native socket address structure pointer.
 
struct sockaddr * Data ()
 Native socket address structure pointer.
 
const struct sockaddr * Data () const
 Native socket address structure pointer.
 
socklen_t Size () const
 Maximum supported native socket address structure size.
 
socklen_t Capacity () const
 Maximum supported native socket address structure size.
 
sa_family_t Family () const
 Protocol family.
 
AddrDomain Domain () const
 Communication domain.
 
bool HasPort () const
 Whether the stored socket address family expects a port.
 
std::uint16_t Port () const
 Returns the stored port number if available, otherwise throws.
 
void SetPort (std::uint16_t port)
 Sets a port for address families that allow for one, otherwise throws.
 
std::string PrimaryAddressString () const
 Human-readable address representation.
 

Static Public Member Functions

static Sockaddr MakeUnixSocketAddress (std::string_view path)
 Creates address of a Unix socket located at the specified path.
 
static Sockaddr MakeLoopbackAddress () noexcept
 Creates the IPv6 loopback address [::1]:0 that also handles IPv4 connections.
 
static Sockaddr MakeIPv4LoopbackAddress () noexcept
 Creates the IPv4 only loopback address 127.0.0.1:0.
 
static constexpr socklen_t Addrlen (AddrDomain domain)
 Domain-specific native socket address structure size.
 

Constructor & Destructor Documentation

◆ Sockaddr() [1/2]

engine::io::Sockaddr::Sockaddr ( )
inlinenoexcept

Constructs an unspecified native socket address.

Definition at line 44 of file sockaddr.hpp.

◆ Sockaddr() [2/2]

engine::io::Sockaddr::Sockaddr ( const void * data)
inlineexplicit

Wraps a native socket address structure.

Warning
sa_family must contain a correct address family.

Definition at line 49 of file sockaddr.hpp.

Member Function Documentation

◆ Addrlen()

static constexpr socklen_t engine::io::Sockaddr::Addrlen ( AddrDomain domain)
inlinestaticconstexpr

Domain-specific native socket address structure size.

Definition at line 119 of file sockaddr.hpp.

◆ As() [1/2]

template<typename T >
T * engine::io::Sockaddr::As ( )
inline

Domain-specific native socket address structure pointer.

Warning
No type checking is performed, user must ensure that only the correct domain is accessed.

Definition at line 73 of file sockaddr.hpp.

◆ As() [2/2]

template<typename T >
const T * engine::io::Sockaddr::As ( ) const
inline

Domain-specific native socket address structure pointer.

Warning
No type checking is performed, user must ensure that only the correct domain is accessed.

Definition at line 82 of file sockaddr.hpp.

◆ Capacity()

socklen_t engine::io::Sockaddr::Capacity ( ) const
inline

Maximum supported native socket address structure size.

Definition at line 97 of file sockaddr.hpp.

◆ Data() [1/2]

struct sockaddr * engine::io::Sockaddr::Data ( )
inline

Native socket address structure pointer.

Definition at line 88 of file sockaddr.hpp.

◆ Data() [2/2]

const struct sockaddr * engine::io::Sockaddr::Data ( ) const
inline

Native socket address structure pointer.

Definition at line 91 of file sockaddr.hpp.

◆ Domain()

AddrDomain engine::io::Sockaddr::Domain ( ) const
inline

Communication domain.

Definition at line 103 of file sockaddr.hpp.

◆ Family()

sa_family_t engine::io::Sockaddr::Family ( ) const
inline

Protocol family.

Definition at line 100 of file sockaddr.hpp.

◆ MakeIPv4LoopbackAddress()

static Sockaddr engine::io::Sockaddr::MakeIPv4LoopbackAddress ( )
staticnoexcept

Creates the IPv4 only loopback address 127.0.0.1:0.

Prefer a more generic MakeLoopbackAddress() function if not sure.

◆ MakeLoopbackAddress()

static Sockaddr engine::io::Sockaddr::MakeLoopbackAddress ( )
staticnoexcept

Creates the IPv6 loopback address [::1]:0 that also handles IPv4 connections.

A program needs to support only this API type to support IPv4 and IPv6.

◆ PrimaryAddressString()

std::string engine::io::Sockaddr::PrimaryAddressString ( ) const

Human-readable address representation.

Note
Does not include port number.

◆ Size()

socklen_t engine::io::Sockaddr::Size ( ) const
inline

Maximum supported native socket address structure size.

Definition at line 94 of file sockaddr.hpp.


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