#include <userver/utest/port_reservation.hpp>
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. | |
Definition at line 51 of file port_reservation.hpp.
| using utest::PortReservation::Options = PortReservationOptions |
Definition at line 50 of file port_reservation.hpp.
Definition at line 52 of file port_reservation.hpp.
|
explicit |
Binds the socket without enabling port sharing. For a fixed port, this can block the calling thread until the port becomes available.
| std::system_error | If binding fails or the fixed port remains busy until the timeout. |
| std::invalid_argument | If the fixed port is zero. |
|
nodiscard |
Transfers ownership of the bound descriptor to the caller and invalidates this reservation. Requires a valid reservation.