AsyncTcpSocket class
A TCP socket for overlapped I/O from tasks.
- Use
import ThinkMeta.ConcurrentTasks.AsyncIo.AsyncTcpSocket;- Namespace
ThinkMeta::ConcurrentTasks::AsyncIo- Inherits
TcpSocketBase,AsyncSocket
Syntax
template <IpVersionType _IpVersion>
class AsyncTcpSocket : public TcpSocketBase<_IpVersion, AsyncSocket>Template parameters
_IpVersionIpVersionType- The IP version:
Windows::IpVersion::V4orWindows::IpVersion::V6.
Remarks
AsyncSocket plus the TCP/IP options of Windows::TcpSocketBase/ Windows::IpSocketBase, for Windows::IpVersion::V4 or V6. Create() (no arguments, see Windows::TcpSocket::Create) creates an overlapped TCP socket of the right address family and associates it with the core's completion port; needs Windows::Socket::Startup and EnableAsyncIo. The object owns the SOCKET and closes it on destruction. All the remarks of AsyncSocket apply (task-only waiting forms, timeouts, buffer lifetime).
See also
Names
| Name | Description |
|---|---|
AsyncTcpSocket4 |
Asynchronous IPv4 TCP socket. |
AsyncTcpSocket6 |
Asynchronous IPv6 TCP socket. |
Constructors
AsyncTcpSocket
Takes over other's socket; other is left without one.
Syntax
AsyncTcpSocket(AsyncTcpSocket&& other) noexcept;Parameters
otherAsyncTcpSocket&&- 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
AsyncTcpSocket& operator=(AsyncTcpSocket&& other) noexcept;Parameters
otherAsyncTcpSocket&&- The object whose socket is taken over; it holds no socket afterwards.
Return value
Type: AsyncTcpSocket&
This object.
Accept
Accepts one connection on this listening socket.
Syntax
WinsockErrorCode Accept(
AsyncTcpSocket& acceptSocket,
typename _Traits::SockAddr* address = nullptr,
Duration timeout = Duration::Infinite()
) noexcept;Parameters
acceptSocketAsyncTcpSocket&- Takes the connection. Must not hold a socket yet; Accept creates it. On failure it is closed again.
addresstypename _Traits::SockAddr*- Optional; receives the peer's address.Default:
nullptr timeoutDuration- Limit for the wait; see
AsyncSocketfor the timeout rules.Default:Duration::Infinite()
Return value
Type: WinsockErrorCode
WinsockError::Success, WinsockError::TimedOut, or the WSA error of the create/AcceptEx/setsockopt step.
Remarks
Task only; suspends the calling task. This socket must be created, bound and listening (Windows::Socket::Listen). Uses AcceptEx without initial data, so it completes as soon as a connection arrives, then applies SO_UPDATE_ACCEPT_CONTEXT so that getpeername, shutdown etc. work on acceptSocket.
See also
Connect
Connects to an address.
Syntax
WinsockErrorCode Connect(
const typename _Traits::SockAddr& address,
Duration timeout = Duration::Infinite()
) noexcept;Parameters
addressconst typename _Traits::SockAddr&- The remote address and port (
sockaddr_inorsockaddr_in6). timeoutDuration- Limit for the wait; see
AsyncSocketfor the timeout rules.Default:Duration::Infinite()
Return value
Type: WinsockErrorCode
WinsockError::Success, WinsockError::TimedOut, or the WSA error of ConnectEx/setsockopt.
Remarks
Task only; suspends the calling task until connected. Uses ConnectEx. The socket must be created and bound (Windows::Socket::Bind, e.g. to the any address, port 0); ConnectEx fails with WSAEINVAL otherwise. Applies SO_UPDATE_CONNECT_CONTEXT after the connection.
See also
ConnectAsync
Starts a connect without initial data.
Syntax
WinsockErrorCode ConnectAsync(
const typename _Traits::SockAddr& address,
AsyncSocketIoRequest& asyncIoRequest
) noexcept;Parameters
addressconst typename _Traits::SockAddr&- The remote address and port (
sockaddr_inorsockaddr_in6). asyncIoRequestAsyncSocketIoRequest&- The caller-owned request that is completed with the operation's result. It must not be in use by another operation and must stay valid and must not move until it has completed.
Return value
Type: WinsockErrorCode
WinsockError::Success, WinsockError::Pending or the WSA error (see AsyncSocket).
Remarks
Never suspends; uses ConnectEx. The socket must be created and bound. After successful completion the caller calls Windows::Socket::SetOptionUpdateConnectContext.
See also
Generated from ThinkMeta.ConcurrentTasks.API @ 137ec1d (2026-10-17).