userver: utest::PortReservation Class Reference
Loading...
Searching...
No Matches
utest::PortReservation Class Referencefinal

#include <userver/utest/port_reservation.hpp>

Detailed Description

Owns a socket bound to a port on an IPv4 or IPv6 loopback address. Keep the reservation alive until the consumer has duplicated the descriptor.

Definition at line 48 of file port_reservation.hpp.

Public Types

using Options = PortReservationOptions
using IpVersion = Options::IpVersion
using Protocol = Options::Protocol

Public Member Functions

 PortReservation (Options options={})
 PortReservation (const PortReservation &)=delete
 PortReservation (PortReservation &&) noexcept=default
PortReservation & operator= (const PortReservation &)=delete
PortReservation & operator= (PortReservation &&) noexcept=default
bool IsValid () const noexcept
 Returns whether the reservation still owns its socket.
int GetNativeFd () const
 Returns a borrowed descriptor. Requires a valid reservation. The caller must not close it.
int ReleaseNativeFd () &&
std::uint16_t GetPort () const
 Returns the assigned port. Requires a reservation that still owns its socket.

Member Typedef Documentation

◆ IpVersion

◆ Options

using utest::PortReservation::Options = PortReservationOptions

Definition at line 50 of file port_reservation.hpp.

◆ Protocol

Constructor & Destructor Documentation

◆ PortReservation()

utest::PortReservation::PortReservation ( Options options = {})
explicit

Binds the socket without enabling port sharing. For a fixed port, this can block the calling thread until the port becomes available.

Exceptions
std::system_errorIf binding fails or the fixed port remains busy until the timeout.
std::invalid_argumentIf the fixed port is zero.

Member Function Documentation

◆ ReleaseNativeFd()

int utest::PortReservation::ReleaseNativeFd ( ) &&
nodiscard

Transfers ownership of the bound descriptor to the caller and invalidates this reservation. Requires a valid reservation.


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