Preliminary. ThinkMeta ConcurrentTasks and this documentation are preliminary; everything is subject to change.

API reference / Net

IpSocketBase class

An IPv4 or IPv6 socket with the IP options of that version.

On this page
Use
import ThinkMeta.ConcurrentTasks.Net.IpSocket;
Namespace
ThinkMeta::ConcurrentTasks::Net
Platforms
Windows, Linux

Syntax

template <IpVersionType _IpVersion, SocketType _BaseSocket> class IpSocketBase

Template parameters

_IpVersionIpVersionType
The IP version: IpVersion::V4 or IpVersion::V6.
_BaseSocketSocketType
The socket class built on: Platform::Socket (blocking calls) or AsyncIo::AsyncSocket.

Remarks

Plain (Platform::Socket) or asynchronous (AsyncIo::AsyncSocket). Owns its socket like Socket.

See also

IpSocket, AsyncIo::AsyncIpSocket

Names

NameDescription
IpSocket A blocking (plain Platform::Socket) IP socket of the given version.
IpSocket4 A blocking IPv4 socket.
IpSocket6 A blocking IPv6 socket.

Constructors

IpSocketBase

Creates an object without a socket.

Syntax

IpSocketBase() noexcept = default;

Takes over other's socket; other is left without one.

Syntax

IpSocketBase(IpSocketBase&& other) noexcept = default;

Parameters

otherIpSocketBase&&
The object whose socket is taken over; it holds no socket afterwards.

Methods

operator=

Takes over other's socket; a socket this object already holds is closed first.

Syntax

IpSocketBase& operator=(IpSocketBase&& other) noexcept = default;

Parameters

otherIpSocketBase&&
The object whose socket is taken over; it holds no socket afterwards.

Return value

Type: IpSocketBase&

This object.

SetOptionAddMembership

Joins a multicast group (IP_ADD_MEMBERSHIP / IPV6_ADD_MEMBERSHIP).

Syntax

SocketErrorCode SetOptionAddMembership(
    const typename _Traits::MulticastGroupInfo& mgi
) noexcept;

Parameters

mgiconst typename _Traits::MulticastGroupInfo&
The multicast group and the local interface (ip_mreq for IPv4, ipv6_mreq for IPv6).

Return value

Type: SocketErrorCode

Platform::SocketError::Success, or the error of setsockopt.

See also

SetOptionDropMembership

Windows only

Joins an IPv4 multicast group on an interface. Windows.

Syntax

SocketErrorCode SetOptionAddMembership(
    const in_addr& multicastAddress,
    std::uint32_t index
) noexcept;

Parameters

multicastAddressconst in_addr&
The IPv4 multicast group address.
indexstd::uint32_t
The interface index (below 2^24, see remarks).

Return value

Type: SocketErrorCode

Platform::SocketError::Success, or the error of setsockopt.

Remarks

The index is passed as interface address 0.x.y.z, which Windows reads as an interface index.

See also

SetOptionDropMembership

Windows only

Joins an IPv6 multicast group on an interface. Windows.

Syntax

SocketErrorCode SetOptionAddMembership(
    const in6_addr& multicastAddress,
    std::uint32_t index
) noexcept;

Parameters

multicastAddressconst in6_addr&
The IPv6 multicast group address.
indexstd::uint32_t
The interface index; 0 selects the default interface.

Return value

Type: SocketErrorCode

Platform::SocketError::Success, or the error of setsockopt.

See also

SetOptionDropMembership

SetOptionDropMembership

Leaves a multicast group (IP_DROP_MEMBERSHIP / IPV6_DROP_MEMBERSHIP).

Syntax

SocketErrorCode SetOptionDropMembership(
    const typename _Traits::MulticastGroupInfo& mgi
) noexcept;

Parameters

mgiconst typename _Traits::MulticastGroupInfo&
The multicast group and the local interface (ip_mreq for IPv4, ipv6_mreq for IPv6), as joined.

Return value

Type: SocketErrorCode

Platform::SocketError::Success, or the error of setsockopt.

See also

SetOptionAddMembership

Windows only

Leaves an IPv4 multicast group joined by interface index. Windows.

Syntax

SocketErrorCode SetOptionDropMembership(
    const in_addr& multicastAddress,
    std::uint32_t index
) noexcept;

Parameters

multicastAddressconst in_addr&
The IPv4 multicast group address, as joined.
indexstd::uint32_t
The interface index, as joined.

Return value

Type: SocketErrorCode

Platform::SocketError::Success, or the error of setsockopt.

See also

SetOptionAddMembership

Windows only

Leaves an IPv6 multicast group joined by interface index. Windows.

Syntax

SocketErrorCode SetOptionDropMembership(
    const in6_addr& multicastAddress,
    std::uint32_t index
) noexcept;

Parameters

multicastAddressconst in6_addr&
The IPv6 multicast group address, as joined.
indexstd::uint32_t
The interface index, as joined.

Return value

Type: SocketErrorCode

Platform::SocketError::Success, or the error of setsockopt.

See also

SetOptionAddMembership

SetOptionHeaderInclude

Sets whether the application supplies the IP header (IP_HDRINCL / IPV6_HDRINCL).

Syntax

SocketErrorCode SetOptionHeaderInclude(bool include) noexcept;

Parameters

includebool
true if the data sent starts with the IP header, false if the stack adds it.

Return value

Type: SocketErrorCode

Platform::SocketError::Success, or the error of setsockopt.

Remarks

For raw sockets.

GetOptionHeaderInclude

Gets the header-include setting.

Syntax

SocketErrorCode GetOptionHeaderInclude(bool* include) noexcept;

Parameters

includebool*
Required. Receives true if the application supplies the IP header.

Return value

Type: SocketErrorCode

Platform::SocketError::Success, or the error of getsockopt.

SetOptionMulticastLoop

Sets multicast loopback (IP_MULTICAST_LOOP / IPV6_MULTICAST_LOOP).

Syntax

SocketErrorCode SetOptionMulticastLoop(bool enable) noexcept;

Parameters

enablebool
true if multicast sent is looped back to the local host, false otherwise.

Return value

Type: SocketErrorCode

Platform::SocketError::Success, or the error of setsockopt.

GetOptionMulticastLoop

Gets the multicast loopback setting.

Syntax

SocketErrorCode GetOptionMulticastLoop(bool* enable) noexcept;

Parameters

enablebool*
Required. Receives true if multicast sent is looped back to the local host.

Return value

Type: SocketErrorCode

Platform::SocketError::Success, or the error of getsockopt.

SetOptionPacketInformation

Enables packet information (IP_PKTINFO / IPV6_PKTINFO, IPV6_RECVPKTINFO on Linux).

Syntax

SocketErrorCode SetOptionPacketInformation(bool enable) noexcept;

Parameters

enablebool
true to report packet information, false to stop it.

Return value

Type: SocketErrorCode

Platform::SocketError::Success, or the error of setsockopt.

Remarks

Reported in received control data; use with AsyncIo::AsyncSocket::RecvMsg.

GetOptionPacketInformation

Gets the packet-information setting.

Syntax

SocketErrorCode GetOptionPacketInformation(bool* enable) noexcept;

Parameters

enablebool*
Required. Receives true if packet information is reported.

Return value

Type: SocketErrorCode

Platform::SocketError::Success, or the error of getsockopt.

SetOptionHopLimitWindows only

Sets whether the hop limit of received packets is reported (IP_HOPLIMIT/IPV6_HOPLIMIT). Windows.

Syntax

SocketErrorCode SetOptionHopLimit(bool enable) noexcept;

Parameters

enablebool
true to report the hop limit (TTL) in the control data, false to stop it.

Return value

Type: SocketErrorCode

Platform::SocketError::Success, or the error of setsockopt.

GetOptionHopLimitWindows only

Gets whether the hop limit of received packets is reported. Windows.

Syntax

SocketErrorCode GetOptionHopLimit(bool* enable) noexcept;

Parameters

enablebool*
Required. Receives true if the hop limit is reported.

Return value

Type: SocketErrorCode

Platform::SocketError::Success, or the error of getsockopt.

SetOptionMulticastInterfaceWindows only

Sets the outgoing multicast interface (IP_MULTICAST_IF / IPV6_MULTICAST_IF). Windows.

Syntax

SocketErrorCode SetOptionMulticastInterface(std::uint32_t index) noexcept;

Parameters

indexstd::uint32_t
The interface index, in host byte order; 0 selects the default interface.

Return value

Type: SocketErrorCode

Platform::SocketError::Success, or the error of setsockopt.

GetOptionMulticastInterfaceWindows only

Gets the outgoing multicast interface index. Windows.

Syntax

SocketErrorCode GetOptionMulticastInterface(std::uint32_t* index) noexcept;

Parameters

indexstd::uint32_t*
Required. Receives the interface index, in host byte order.

Return value

Type: SocketErrorCode

Platform::SocketError::Success, or the error of getsockopt.

SetOptionOriginalArrivalInterfaceWindows only

Enables reporting the original arrival interface (IP_ORIGINAL_ARRIVAL_IF). Windows.

Syntax

SocketErrorCode SetOptionOriginalArrivalInterface(bool enable) noexcept;

Parameters

enablebool
true to report the original arrival interface, false to stop it.

Return value

Type: SocketErrorCode

Platform::SocketError::Success, or the error of setsockopt.

Remarks

Reported in received control data. Uses the IPv4 option number at the version's option level, also for IPv6.

GetOptionOriginalArrivalInterfaceWindows only

Gets the original-arrival-interface setting. Windows.

Syntax

SocketErrorCode GetOptionOriginalArrivalInterface(bool* enable) noexcept;

Parameters

enablebool*
Required. Receives true if the original arrival interface is reported.

Return value

Type: SocketErrorCode

Platform::SocketError::Success, or the error of getsockopt.

SetOptionRecvInterfaceWindows only

Enables reporting the receiving interface (IP_RECVIF / IPV6_RECVIF). Windows.

Syntax

SocketErrorCode SetOptionRecvInterface(bool enable) noexcept;

Parameters

enablebool
true: WSARecvMsg returns the interface a datagram arrived on in its control data. Datagram and raw sockets only.

Return value

Type: SocketErrorCode

Platform::SocketError::Success, or the error of setsockopt.

GetOptionRecvInterfaceWindows only

Gets whether the receiving interface is reported (IP_RECVIF / IPV6_RECVIF). Windows.

Syntax

SocketErrorCode GetOptionRecvInterface(bool* enable) noexcept;

Parameters

enablebool*
Required. Receives true if the receiving interface is reported.

Return value

Type: SocketErrorCode

Platform::SocketError::Success, or the error of getsockopt.

SetOptionUnicastInterfaceWindows only

Sets the outgoing unicast interface (IP_UNICAST_IF / IPV6_UNICAST_IF). Windows.

Syntax

SocketErrorCode SetOptionUnicastInterface(std::uint32_t index) noexcept;

Parameters

indexstd::uint32_t
The interface index, in host byte order; 0 selects the default interface.

Return value

Type: SocketErrorCode

Platform::SocketError::Success, or the error of setsockopt.

GetOptionUnicastInterfaceWindows only

Gets the outgoing unicast interface index. Windows.

Syntax

SocketErrorCode GetOptionUnicastInterface(std::uint32_t* index) noexcept;

Parameters

indexstd::uint32_t*
Required. Receives the interface index, in host byte order.

Return value

Type: SocketErrorCode

Platform::SocketError::Success, or the error of getsockopt.

SetOptionAddSourceMembership

Joins a source-specific multicast group (IP_ADD_SOURCE_MEMBERSHIP).

Syntax

SocketErrorCode SetOptionAddSourceMembership(const ip_mreq_source& mgi) noexcept;

Parameters

mgiconst ip_mreq_source&
The multicast group, the source address to receive from and the local interface.

Return value

Type: SocketErrorCode

Platform::SocketError::Success, or the error of setsockopt.

See also

SetOptionDropSourceMembership

SetOptionDropSourceMembership

Leaves a source-specific multicast group (IP_DROP_SOURCE_MEMBERSHIP).

Syntax

SocketErrorCode SetOptionDropSourceMembership(const ip_mreq_source& mgi) noexcept;

Parameters

mgiconst ip_mreq_source&
The multicast group, the source address and the local interface, as joined.

Return value

Type: SocketErrorCode

Platform::SocketError::Success, or the error of setsockopt.

See also

SetOptionAddSourceMembership

SetOptionBlockSource

Blocks a multicast source (IP_BLOCK_SOURCE).

Syntax

SocketErrorCode SetOptionBlockSource(const ip_mreq_source& mgi) noexcept;

Parameters

mgiconst ip_mreq_source&
The joined multicast group, the source address to block and the local interface.

Return value

Type: SocketErrorCode

Platform::SocketError::Success, or the error of setsockopt.

See also

SetOptionUnblockSource

SetOptionUnblockSource

Unblocks a multicast source (IP_UNBLOCK_SOURCE).

Syntax

SocketErrorCode SetOptionUnblockSource(const ip_mreq_source& mgi) noexcept;

Parameters

mgiconst ip_mreq_source&
The multicast group, the blocked source address and the local interface.

Return value

Type: SocketErrorCode

Platform::SocketError::Success, or the error of setsockopt.

See also

SetOptionBlockSource

SetOptionMulticastTtl

Sets the multicast TTL (IP_MULTICAST_TTL).

Syntax

SocketErrorCode SetOptionMulticastTtl(std::uint32_t ttl) noexcept;

Parameters

ttlstd::uint32_t
The time to live of outgoing multicast packets (0 to 255; default 1).

Return value

Type: SocketErrorCode

Platform::SocketError::Success, or the error of setsockopt.

GetOptionMulticastTtl

Gets the multicast TTL.

Syntax

SocketErrorCode GetOptionMulticastTtl(std::uint32_t* ttl) noexcept;

Parameters

ttlstd::uint32_t*
Required. Receives the time to live of outgoing multicast packets.

Return value

Type: SocketErrorCode

Platform::SocketError::Success, or the error of getsockopt.

SetOptionTypeOfService

Sets the type of service (IP_TOS).

Syntax

SocketErrorCode SetOptionTypeOfService(std::uint32_t typeOfService) noexcept;

Parameters

typeOfServicestd::uint32_t
The type-of-service byte of outgoing packets.

Return value

Type: SocketErrorCode

Platform::SocketError::Success, or the error of setsockopt.

GetOptionTypeOfService

Gets the type of service (IP_TOS).

Syntax

SocketErrorCode GetOptionTypeOfService(std::uint32_t* typeOfService) noexcept;

Parameters

typeOfServicestd::uint32_t*
Required. Receives the type-of-service byte.

Return value

Type: SocketErrorCode

Platform::SocketError::Success, or the error of getsockopt.

SetOptionTtl

Sets the unicast TTL (IP_TTL).

Syntax

SocketErrorCode SetOptionTtl(std::uint32_t ttl) noexcept;

Parameters

ttlstd::uint32_t
The time to live of outgoing unicast packets (1 to 255).

Return value

Type: SocketErrorCode

Platform::SocketError::Success, or the error of setsockopt.

GetOptionTtl

Gets the unicast TTL (IP_TTL).

Syntax

SocketErrorCode GetOptionTtl(std::uint32_t* ttl) noexcept;

Parameters

ttlstd::uint32_t*
Required. Receives the time to live of outgoing unicast packets.

Return value

Type: SocketErrorCode

Platform::SocketError::Success, or the error of getsockopt.

SetOptionDontFragmentWindows only

Sets the don't-fragment flag (IP_DONTFRAGMENT). Windows.

Syntax

SocketErrorCode SetOptionDontFragment(bool dontFragment) noexcept;

Parameters

dontFragmentbool
true to send packets with the don't-fragment flag set.

Return value

Type: SocketErrorCode

Platform::SocketError::Success, or the error of setsockopt.

GetOptionDontFragmentWindows only

Gets the don't-fragment flag. Windows.

Syntax

SocketErrorCode GetOptionDontFragment(bool* dontFragment) noexcept;

Parameters

dontFragmentbool*
Required. Receives true if packets are sent with the don't-fragment flag.

Return value

Type: SocketErrorCode

Platform::SocketError::Success, or the error of getsockopt.

SetOptionOptionsWindows only

Sets the IP options of outgoing packets (IP_OPTIONS). Windows.

Syntax

SocketErrorCode SetOptionOptions(const char* options, int length) noexcept;

Parameters

optionsconst char*
Required. The IP options as they appear in the header (at most 40 bytes).
lengthint
The size of options in bytes.

Return value

Type: SocketErrorCode

Platform::SocketError::Success, or the error of setsockopt.

GetOptionOptionsWindows only

Gets the IP options (IP_OPTIONS). Windows.

Syntax

SocketErrorCode GetOptionOptions(char* options, int* length) noexcept;

Parameters

optionschar*
Required. Receives the IP options.
lengthint*
Required. In: the size of options in bytes; out: the bytes written.

Return value

Type: SocketErrorCode

Platform::SocketError::Success, or the error of getsockopt.

SetOptionReceiveBroadcastWindows only

Sets whether broadcast is received (IP_RECEIVE_BROADCAST). Windows.

Syntax

SocketErrorCode SetOptionReceiveBroadcast(bool enable) noexcept;

Parameters

enablebool
true to receive broadcast data, false to drop it.

Return value

Type: SocketErrorCode

Platform::SocketError::Success, or the error of setsockopt.

GetOptionReceiveBroadcastWindows only

Gets the receive-broadcast setting. Windows.

Syntax

SocketErrorCode GetOptionReceiveBroadcast(bool* enable) noexcept;

Parameters

enablebool*
Required. Receives true if broadcast data is received.

Return value

Type: SocketErrorCode

Platform::SocketError::Success, or the error of getsockopt.

SetOptionWfpRedirectContextWindows only

Sets the WFP redirect context (IP_WFP_REDIRECT_CONTEXT). Windows.

Syntax

SocketErrorCode SetOptionWfpRedirectContext(
    const WSACMSGHDR* data,
    int length
) noexcept;

Parameters

dataconst WSACMSGHDR*
Required. The redirect context, as received in control data.
lengthint
The size of data in bytes.

Return value

Type: SocketErrorCode

Platform::SocketError::Success, or the error of setsockopt.

GetOptionWfpRedirectContextWindows only

Gets the WFP redirect context. Windows.

Syntax

SocketErrorCode GetOptionWfpRedirectContext(WSACMSGHDR* data, int* length) noexcept;

Parameters

dataWSACMSGHDR*
Required. Receives the redirect context.
lengthint*
Required. In: the size of data in bytes; out: the bytes written.

Return value

Type: SocketErrorCode

Platform::SocketError::Success, or the error of getsockopt.

SetOptionWfpRedirectRecordsWindows only

Sets the WFP redirect records (IP_WFP_REDIRECT_RECORDS). Windows.

Syntax

SocketErrorCode SetOptionWfpRedirectRecords(
    const WSACMSGHDR* data,
    int length
) noexcept;

Parameters

dataconst WSACMSGHDR*
Required. The redirect records, as received in control data.
lengthint
The size of data in bytes.

Return value

Type: SocketErrorCode

Platform::SocketError::Success, or the error of setsockopt.

GetOptionWfpRedirectRecordsWindows only

Gets the WFP redirect records. Windows.

Syntax

SocketErrorCode GetOptionWfpRedirectRecords(WSACMSGHDR* data, int* length) noexcept;

Parameters

dataWSACMSGHDR*
Required. Receives the redirect records.
lengthint*
Required. In: the size of data in bytes; out: the bytes written.

Return value

Type: SocketErrorCode

Platform::SocketError::Success, or the error of getsockopt.

FillAddress

Sets family, address and port of a socket address.

Syntax

static void FillAddress(
    sockaddr_in& sockAddr,
    const in_addr& addr,
    std::uint16_t port
) noexcept;

Parameters

sockAddrsockaddr_in&
The socket address to fill; zero-initialize it first.
addrconst in_addr&
The IPv4 address, e.g. IpTraits<IpVersion::V4>::AnyAddress (INADDR_ANY) for the wildcard address.
portstd::uint16_t
In host order; converted with htons.

Remarks

Other fields are not touched: zero-initialize sockAddr first.

Sets family, address and port of a socket address.

Syntax

static void FillAddress(
    sockaddr_in6& sockAddr,
    const in6_addr& addr,
    std::uint16_t port
) noexcept;

Parameters

sockAddrsockaddr_in6&
The socket address to fill; zero-initialize it first.
addrconst in6_addr&
The IPv6 address, e.g. IpTraits<IpVersion::V6>::AnyAddress (in6addr_any) for the wildcard address.
portstd::uint16_t
In host order; converted with htons.

Remarks

Other fields (flow info, scope id) are not touched: zero-initialize sockAddr first.

SetOptionUnicastHops

Sets the unicast hop limit (IPV6_UNICAST_HOPS).

Syntax

SocketErrorCode SetOptionUnicastHops(std::uint32_t hops) noexcept;

Parameters

hopsstd::uint32_t
The hop limit of outgoing unicast packets (0 to 255).

Return value

Type: SocketErrorCode

Platform::SocketError::Success, or the error of setsockopt.

Remarks

The IPv6 counterpart of the IPv4 time to live.

GetOptionUnicastHops

Gets the unicast hop limit (IPV6_UNICAST_HOPS).

Syntax

SocketErrorCode GetOptionUnicastHops(std::uint32_t* hops) noexcept;

Parameters

hopsstd::uint32_t*
Required. Receives the hop limit of outgoing unicast packets.

Return value

Type: SocketErrorCode

Platform::SocketError::Success, or the error of getsockopt.

SetOptionMulticastHops

Sets the multicast hop limit (IPV6_MULTICAST_HOPS).

Syntax

SocketErrorCode SetOptionMulticastHops(std::uint32_t hops) noexcept;

Parameters

hopsstd::uint32_t
The hop limit of outgoing multicast packets (0 to 255; default 1).

Return value

Type: SocketErrorCode

Platform::SocketError::Success, or the error of setsockopt.

Remarks

The IPv6 counterpart of the IPv4 multicast time to live.

GetOptionMulticastHops

Gets the multicast hop limit (IPV6_MULTICAST_HOPS).

Syntax

SocketErrorCode GetOptionMulticastHops(std::uint32_t* hops) noexcept;

Parameters

hopsstd::uint32_t*
Required. Receives the hop limit of outgoing multicast packets.

Return value

Type: SocketErrorCode

Platform::SocketError::Success, or the error of getsockopt.

SetOptionIpv6Only

Sets whether the socket is IPv6-only (IPV6_V6ONLY).

Syntax

SocketErrorCode SetOptionIpv6Only(bool ipv6Only) noexcept;

Parameters

ipv6Onlybool
true: IPv6 only; false: allows dual-stack IPv4-mapped use.

Return value

Type: SocketErrorCode

Platform::SocketError::Success, or the error of setsockopt.

Remarks

Set before Platform::Socket::Bind.

GetOptionIpv6Only

Gets the IPv6-only setting.

Syntax

SocketErrorCode GetOptionIpv6Only(bool* ipv6Only) noexcept;

Parameters

ipv6Onlybool*
Required. Receives true if the socket is IPv6-only, false if dual-stack.

Return value

Type: SocketErrorCode

Platform::SocketError::Success, or the error of getsockopt.

SetOptionProtectionLevelWindows only

Sets the protection level (IPV6_PROTECTION_LEVEL, PROTECTION_LEVEL_*). Windows.

Syntax

SocketErrorCode SetOptionProtectionLevel(int level) noexcept;

Parameters

levelint
PROTECTION_LEVEL_UNRESTRICTED, PROTECTION_LEVEL_EDGERESTRICTED or PROTECTION_LEVEL_RESTRICTED.

Return value

Type: SocketErrorCode

Platform::SocketError::Success, or the error of setsockopt.

GetOptionProtectionLevelWindows only

Gets the protection level. Windows.

Syntax

SocketErrorCode GetOptionProtectionLevel(int* level) noexcept;

Parameters

levelint*
Required. Receives the PROTECTION_LEVEL_* value.

Return value

Type: SocketErrorCode

Platform::SocketError::Success, or the error of getsockopt.

Generated from ThinkMeta.ConcurrentTasks.API @ da816bc (2026-11-06).