IpSocketBase class
An IPv4 or IPv6 socket with the IP options of that version.
- Use
import ThinkMeta.ConcurrentTasks.Windows.IpSocket;- Namespace
ThinkMeta::ConcurrentTasks::Windows
Syntax
template <IpVersionType _IpVersion, SocketType _BaseSocket> class IpSocketBaseTemplate parameters
_IpVersionIpVersionType- The IP version:
IpVersion::V4orIpVersion::V6. _BaseSocketSocketType- The socket class built on:
Socket(blocking calls) orAsyncIo::AsyncSocket.
Remarks
Plain (Socket) or asynchronous (AsyncIo::AsyncSocket). Owns its socket like Socket.
See also
IpSocket, AsyncIo::AsyncIpSocket
Names
| Name | Description |
|---|---|
IpSocket |
A blocking (plain Socket) IP socket of the given version.
|
IpSocket4 |
Plain IPv4 socket. |
IpSocket6 |
Plain IPv6 socket. |
Constructors
IpSocketBase
Takes over other's socket; other is left without one.
Syntax
IpSocketBase(IpSocketBase&& other) noexcept;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;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
WinsockErrorCode SetOptionAddMembership(
const typename _Traits::MulticastGroupInfo& mgi
) noexcept;Parameters
mgiconst typename _Traits::MulticastGroupInfo&- The multicast group and the local interface (
ip_mreqfor IPv4,ipv6_mreqfor IPv6).
Return value
Type: WinsockErrorCode
WinsockError::Success, or the WSA error of setsockopt.
See also
Joins an IPv4 multicast group on an interface.
Syntax
WinsockErrorCode SetOptionAddMembership(
const in_addr& multicastAddress,
unsigned long index
) noexcept;Parameters
multicastAddressconst in_addr&- The IPv4 multicast group address.
indexunsigned long- The interface index (below 256, see remarks).
Return value
Type: WinsockErrorCode
WinsockError::Success, or the WSA error of setsockopt.
Remarks
The index is passed as interface address 0.0.0.index, so only indices below 256 work.
See also
Joins an IPv6 multicast group on an interface.
Syntax
WinsockErrorCode SetOptionAddMembership(
const in6_addr& multicastAddress,
unsigned long index
) noexcept;Parameters
multicastAddressconst in6_addr&- The IPv6 multicast group address.
indexunsigned long- The interface index;
0selects the default interface.
Return value
Type: WinsockErrorCode
WinsockError::Success, or the WSA error of setsockopt.
See also
SetOptionDropMembership
Leaves a multicast group (IP_DROP_MEMBERSHIP / IPV6_DROP_MEMBERSHIP).
Syntax
WinsockErrorCode SetOptionDropMembership(
const typename _Traits::MulticastGroupInfo& mgi
) noexcept;Parameters
mgiconst typename _Traits::MulticastGroupInfo&- The multicast group and the local interface (
ip_mreqfor IPv4,ipv6_mreqfor IPv6), as joined.
Return value
Type: WinsockErrorCode
WinsockError::Success, or the WSA error of setsockopt.
See also
SetOptionHeaderInclude
Sets whether the application supplies the IP header (IP_HDRINCL / IPV6_HDRINCL).
Syntax
WinsockErrorCode SetOptionHeaderInclude(bool include) noexcept;Parameters
includebooltrueif the data sent starts with the IP header,falseif the stack adds it.
Return value
Type: WinsockErrorCode
WinsockError::Success, or the WSA error of setsockopt.
Remarks
For raw sockets.
GetOptionHeaderInclude
Gets the header-include setting.
Syntax
WinsockErrorCode GetOptionHeaderInclude(bool* include) noexcept;Parameters
includebool*- Required. Receives
trueif the application supplies the IP header.
Return value
Type: WinsockErrorCode
WinsockError::Success, or the WSA error of getsockopt.
SetOptionMulticastInterface
Sets the outgoing multicast interface (IP_MULTICAST_IF / IPV6_MULTICAST_IF).
Syntax
WinsockErrorCode SetOptionMulticastInterface(DWORD index) noexcept;Parameters
indexDWORD- The interface index, in host byte order;
0selects the default interface.
Return value
Type: WinsockErrorCode
WinsockError::Success, or the WSA error of setsockopt.
GetOptionMulticastInterface
Gets the outgoing multicast interface index.
Syntax
WinsockErrorCode GetOptionMulticastInterface(DWORD* index) noexcept;Parameters
indexDWORD*- Required. Receives the interface index, in host byte order.
Return value
Type: WinsockErrorCode
WinsockError::Success, or the WSA error of getsockopt.
SetOptionMulticastLoop
Sets multicast loopback (IP_MULTICAST_LOOP / IPV6_MULTICAST_LOOP).
Syntax
WinsockErrorCode SetOptionMulticastLoop(bool enable) noexcept;Parameters
enablebooltrueif multicast sent is looped back to the local host,falseotherwise.
Return value
Type: WinsockErrorCode
WinsockError::Success, or the WSA error of setsockopt.
GetOptionMulticastLoop
Gets the multicast loopback setting.
Syntax
WinsockErrorCode GetOptionMulticastLoop(bool* enable) noexcept;Parameters
enablebool*- Required. Receives
trueif multicast sent is looped back to the local host.
Return value
Type: WinsockErrorCode
WinsockError::Success, or the WSA error of getsockopt.
SetOptionOriginalArrivalInterface
Enables reporting the original arrival interface (IP_ORIGINAL_ARRIVAL_IF).
Syntax
WinsockErrorCode SetOptionOriginalArrivalInterface(bool enable) noexcept;Parameters
enablebooltrueto report the original arrival interface,falseto stop it.
Return value
Type: WinsockErrorCode
WinsockError::Success, or the WSA error of setsockopt.
Remarks
Reported in received control data. Uses the IPv4 option number at the version's option level, also for IPv6.
GetOptionOriginalArrivalInterface
Gets the original-arrival-interface setting.
Syntax
WinsockErrorCode GetOptionOriginalArrivalInterface(bool* enable) noexcept;Parameters
enablebool*- Required. Receives
trueif the original arrival interface is reported.
Return value
Type: WinsockErrorCode
WinsockError::Success, or the WSA error of getsockopt.
SetOptionPacketInformation
Enables packet information (IP_PKTINFO / IPV6_PKTINFO).
Syntax
WinsockErrorCode SetOptionPacketInformation(bool enable) noexcept;Parameters
enablebooltrueto report packet information,falseto stop it.
Return value
Type: WinsockErrorCode
WinsockError::Success, or the WSA error of setsockopt.
Remarks
Reported in received control data; use with AsyncIo::AsyncSocket::RecvMsg.
GetOptionPacketInformation
Gets the packet-information setting.
Syntax
WinsockErrorCode GetOptionPacketInformation(bool* enable) noexcept;Parameters
enablebool*- Required. Receives
trueif packet information is reported.
Return value
Type: WinsockErrorCode
WinsockError::Success, or the WSA error of getsockopt.
SetOptionRecvInterface
Enables reporting the receiving interface (IP_RECVIF / IPV6_RECVIF).
Syntax
WinsockErrorCode SetOptionRecvInterface(bool enable) noexcept;Parameters
enablebooltrue:WSARecvMsgreturns the interface a datagram arrived on in its control data. Datagram and raw sockets only.
Return value
Type: WinsockErrorCode
WinsockError::Success, or the WSA error of setsockopt.
GetOptionRecvInterface
Gets whether the receiving interface is reported (IP_RECVIF / IPV6_RECVIF).
Syntax
WinsockErrorCode GetOptionRecvInterface(bool* enable) noexcept;Parameters
enablebool*- Required. Receives
trueif the receiving interface is reported.
Return value
Type: WinsockErrorCode
WinsockError::Success, or the WSA error of getsockopt.
SetOptionUnicastInterface
Sets the outgoing unicast interface (IP_UNICAST_IF / IPV6_UNICAST_IF).
Syntax
WinsockErrorCode SetOptionUnicastInterface(DWORD index) noexcept;Parameters
indexDWORD- The interface index, in host byte order;
0selects the default interface.
Return value
Type: WinsockErrorCode
WinsockError::Success, or the WSA error of setsockopt.
GetOptionUnicastInterface
Gets the outgoing unicast interface index.
Syntax
WinsockErrorCode GetOptionUnicastInterface(DWORD* index) noexcept;Parameters
indexDWORD*- Required. Receives the interface index, in host byte order.
Return value
Type: WinsockErrorCode
WinsockError::Success, or the WSA error of getsockopt.
SetOptionAddSourceMembership
Joins a source-specific multicast group (IP_ADD_SOURCE_MEMBERSHIP).
Syntax
WinsockErrorCode 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: WinsockErrorCode
WinsockError::Success, or the WSA error of setsockopt.
See also
SetOptionBlockSource
Blocks a multicast source (IP_BLOCK_SOURCE).
Syntax
WinsockErrorCode 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: WinsockErrorCode
WinsockError::Success, or the WSA error of setsockopt.
See also
SetOptionDontFragment
Sets the don't-fragment flag (IP_DONTFRAGMENT).
Syntax
WinsockErrorCode SetOptionDontFragment(bool dontFragment) noexcept;Parameters
dontFragmentbooltrueto send packets with the don't-fragment flag set.
Return value
Type: WinsockErrorCode
WinsockError::Success, or the WSA error of setsockopt.
GetOptionDontFragment
Gets the don't-fragment flag.
Syntax
WinsockErrorCode GetOptionDontFragment(bool* dontFragment) noexcept;Parameters
dontFragmentbool*- Required. Receives
trueif packets are sent with the don't-fragment flag.
Return value
Type: WinsockErrorCode
WinsockError::Success, or the WSA error of getsockopt.
SetOptionDropSourceMembership
Leaves a source-specific multicast group (IP_DROP_SOURCE_MEMBERSHIP).
Syntax
WinsockErrorCode 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: WinsockErrorCode
WinsockError::Success, or the WSA error of setsockopt.
See also
SetOptionMulticastTtl
Sets the multicast TTL (IP_MULTICAST_TTL).
Syntax
WinsockErrorCode SetOptionMulticastTtl(DWORD ttl) noexcept;Parameters
ttlDWORD- The time to live of outgoing multicast packets (
0to255; default1).
Return value
Type: WinsockErrorCode
WinsockError::Success, or the WSA error of setsockopt.
GetOptionMulticastTtl
Gets the multicast TTL.
Syntax
WinsockErrorCode GetOptionMulticastTtl(DWORD* ttl) noexcept;Parameters
ttlDWORD*- Required. Receives the time to live of outgoing multicast packets.
Return value
Type: WinsockErrorCode
WinsockError::Success, or the WSA error of getsockopt.
SetOptionOptions
Sets the IP options of outgoing packets (IP_OPTIONS).
Syntax
WinsockErrorCode 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
optionsin bytes.
Return value
Type: WinsockErrorCode
WinsockError::Success, or the WSA error of setsockopt.
GetOptionOptions
Gets the IP options (IP_OPTIONS).
Syntax
WinsockErrorCode GetOptionOptions(char* options, int* length) noexcept;Parameters
optionschar*- Required. Receives the IP options.
lengthint*- Required. In: the size of
optionsin bytes; out: the bytes written.
Return value
Type: WinsockErrorCode
WinsockError::Success, or the WSA error of getsockopt.
SetOptionReceiveBroadcast
Sets whether broadcast is received (IP_RECEIVE_BROADCAST).
Syntax
WinsockErrorCode SetOptionReceiveBroadcast(bool enable) noexcept;Parameters
enablebooltrueto receive broadcast data,falseto drop it.
Return value
Type: WinsockErrorCode
WinsockError::Success, or the WSA error of setsockopt.
GetOptionReceiveBroadcast
Gets the receive-broadcast setting.
Syntax
WinsockErrorCode GetOptionReceiveBroadcast(bool* enable) noexcept;Parameters
enablebool*- Required. Receives
trueif broadcast data is received.
Return value
Type: WinsockErrorCode
WinsockError::Success, or the WSA error of getsockopt.
SetOptionTypeOfService
Sets the type of service (IP_TOS).
Syntax
WinsockErrorCode SetOptionTypeOfService(DWORD typeOfService) noexcept;Parameters
typeOfServiceDWORD- The type-of-service byte of outgoing packets.
Return value
Type: WinsockErrorCode
WinsockError::Success, or the WSA error of setsockopt.
GetOptionTypeOfService
Gets the type of service (IP_TOS).
Syntax
WinsockErrorCode GetOptionTypeOfService(DWORD* typeOfService) noexcept;Parameters
typeOfServiceDWORD*- Required. Receives the type-of-service byte.
Return value
Type: WinsockErrorCode
WinsockError::Success, or the WSA error of getsockopt.
SetOptionTtl
Sets the unicast TTL (IP_TTL).
Syntax
WinsockErrorCode SetOptionTtl(DWORD ttl) noexcept;Parameters
ttlDWORD- The time to live of outgoing unicast packets (
1to255).
Return value
Type: WinsockErrorCode
WinsockError::Success, or the WSA error of setsockopt.
GetOptionTtl
Gets the unicast TTL (IP_TTL).
Syntax
WinsockErrorCode GetOptionTtl(DWORD* ttl) noexcept;Parameters
ttlDWORD*- Required. Receives the time to live of outgoing unicast packets.
Return value
Type: WinsockErrorCode
WinsockError::Success, or the WSA error of getsockopt.
SetOptionUnblockSource
Unblocks a multicast source (IP_UNBLOCK_SOURCE).
Syntax
WinsockErrorCode 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: WinsockErrorCode
WinsockError::Success, or the WSA error of setsockopt.
See also
SetOptionWfpRedirectContext
Sets the WFP redirect context (IP_WFP_REDIRECT_CONTEXT).
Syntax
WinsockErrorCode SetOptionWfpRedirectContext(
const WSACMSGHDR* data,
int length
) noexcept;Parameters
dataconst WSACMSGHDR*- Required. The redirect context, as received in control data.
lengthint- The size of
datain bytes.
Return value
Type: WinsockErrorCode
WinsockError::Success, or the WSA error of setsockopt.
GetOptionWfpRedirectContext
Gets the WFP redirect context.
Syntax
WinsockErrorCode GetOptionWfpRedirectContext(
WSACMSGHDR* data,
int* length
) noexcept;Parameters
dataWSACMSGHDR*- Required. Receives the redirect context.
lengthint*- Required. In: the size of
datain bytes; out: the bytes written.
Return value
Type: WinsockErrorCode
WinsockError::Success, or the WSA error of getsockopt.
SetOptionWfpRedirectRecords
Sets the WFP redirect records (IP_WFP_REDIRECT_RECORDS).
Syntax
WinsockErrorCode SetOptionWfpRedirectRecords(
const WSACMSGHDR* data,
int length
) noexcept;Parameters
dataconst WSACMSGHDR*- Required. The redirect records, as received in control data.
lengthint- The size of
datain bytes.
Return value
Type: WinsockErrorCode
WinsockError::Success, or the WSA error of setsockopt.
GetOptionWfpRedirectRecords
Gets the WFP redirect records.
Syntax
WinsockErrorCode GetOptionWfpRedirectRecords(
WSACMSGHDR* data,
int* length
) noexcept;Parameters
dataWSACMSGHDR*- Required. Receives the redirect records.
lengthint*- Required. In: the size of
datain bytes; out: the bytes written.
Return value
Type: WinsockErrorCode
WinsockError::Success, or the WSA 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.
SetOptionHopLimit
Sets IPV6_HOPLIMIT (receive the hop limit in control data).
Syntax
WinsockErrorCode SetOptionHopLimit(bool enable) noexcept;Parameters
enablebooltrueto report the hop limit of received packets,falseto stop it.
Return value
Type: WinsockErrorCode
WinsockError::Success, or the WSA error of setsockopt.
GetOptionHopLimit
Gets the IPV6_HOPLIMIT setting.
Syntax
WinsockErrorCode GetOptionHopLimit(bool* enable) noexcept;Parameters
enablebool*- Required. Receives
trueif the hop limit is reported.
Return value
Type: WinsockErrorCode
WinsockError::Success, or the WSA error of getsockopt.
SetOptionJoinGroup
Joins a multicast group (IPV6_JOIN_GROUP).
Syntax
WinsockErrorCode SetOptionJoinGroup(const ipv6_mreq& mgi) noexcept;Parameters
mgiconst ipv6_mreq&- The multicast group address and the interface index.
Return value
Type: WinsockErrorCode
WinsockError::Success, or the WSA error of setsockopt.
See also
SetOptionLeaveGroup
Leaves a multicast group (IPV6_LEAVE_GROUP).
Syntax
WinsockErrorCode SetOptionLeaveGroup(const ipv6_mreq& mgi) noexcept;Parameters
mgiconst ipv6_mreq&- The multicast group address and the interface index, as joined.
Return value
Type: WinsockErrorCode
WinsockError::Success, or the WSA error of setsockopt.
See also
SetOptionProtectionLevel
Sets the protection level (IPV6_PROTECTION_LEVEL, PROTECTION_LEVEL_*).
Syntax
WinsockErrorCode SetOptionProtectionLevel(INT level) noexcept;Parameters
levelINTPROTECTION_LEVEL_UNRESTRICTED,PROTECTION_LEVEL_EDGERESTRICTEDorPROTECTION_LEVEL_RESTRICTED.
Return value
Type: WinsockErrorCode
WinsockError::Success, or the WSA error of setsockopt.
GetOptionProtectionLevel
Gets the protection level.
Syntax
WinsockErrorCode GetOptionProtectionLevel(INT* level) noexcept;Parameters
levelINT*- Required. Receives the
PROTECTION_LEVEL_*value.
Return value
Type: WinsockErrorCode
WinsockError::Success, or the WSA error of getsockopt.
SetOptionIpv6Only
Sets whether the socket is IPv6-only (IPV6_V6ONLY).
Syntax
WinsockErrorCode SetOptionIpv6Only(bool ipv6Only) noexcept;Parameters
ipv6Onlybooltrue: IPv6 only;false: allows dual-stack IPv4-mapped use.
Return value
Type: WinsockErrorCode
WinsockError::Success, or the WSA error of setsockopt.
Remarks
Set before Socket::Bind.
GetOptionIpv6Only
Gets the IPv6-only setting.
Syntax
WinsockErrorCode GetOptionIpv6Only(bool* ipv6Only) noexcept;Parameters
ipv6Onlybool*- Required. Receives
trueif the socket is IPv6-only,falseif dual-stack.
Return value
Type: WinsockErrorCode
WinsockError::Success, or the WSA error of getsockopt.
Generated from ThinkMeta.ConcurrentTasks.API @ 137ec1d (2026-10-17).