boost::corosio::socket_option::v6_only
Restrict an IPv6 socket to IPv6 only (IPV6_V6ONLY).
Synopsis
Declared in <boost/corosio/socket_option.hpp>
class v6_only
: public boolean_option
Description
When enabled, the socket only accepts IPv6 connections. When disabled, the socket accepts both IPv4 and IPv6 connections (dual‐stack mode).
Example
void
accept_ipv6_peers_only(corosio::tcp_acceptor& acc)
{
if (auto ec = acc.open(corosio::family::v6))
return; // report the error
// Set between open() and bind(): once bound, the option no longer moves.
// Disabled, an IPv6 acceptor also accepts IPv4 peers and reports them as
// v4-mapped addresses. tcp_acceptor::open() leaves the acceptor dual-stack
// (v6_only false) on every backend; tcp_socket and udp_socket are the
// opposite, their open() making an IPv6 socket v6-only. Set the option
// explicitly whenever either behavior matters, rather than relying on a
// default that differs by object. set_option reports failure by throwing,
// not by returning a code.
acc.set_option(corosio::socket_option::v6_only(true));
if (auto ec =
acc.bind(corosio::endpoint(corosio::ipv6_address::any(), 8080)))
return; // report the error
if (auto ec = acc.listen())
return; // report the error
}
Member Functions
Name |
Description |
Assignment operators |
|
Return the negated option value. |
|
Return the option value. |
|
Return the option value. |
Using Declarations
Name |
Description |
Inherit assignment from the base. |
|
Inherit the base constructors. |
Created with MrDocs