boost::corosio::socket_option::leave_group

Leave a multicast group (IP_DROP_MEMBERSHIP / IPV6_LEAVE_GROUP).

Synopsis

class leave_group;

Description

The group's family — not the socket's — selects the wire struct and protocol level, mirroring join_group.

Example

void
stop_receiving_an_ipv4_multicast_group(corosio::udp_socket& sock)
{
    // Precondition: sock is open on family::v4 and joined this group.
    //
    // Membership otherwise lasts until the socket closes. The group and the
    // interface have to match the join_group that established it --
    // attempting to leave a (group, interface) pair the kernel has no
    // membership for fails with EADDRNOTAVAIL, which set_option reports
    // through its return value.
    auto [aec, group] = corosio::make_ipv4_address("239.255.0.1");
    if (aec)
        return; // report the error
    if (auto ec = sock.set_option(corosio::socket_option::leave_group(group)))
        return; // report the error
}

Member Functions

Name

Description

leave_group [constructor]

Constructors

Created with MrDocs