boost::corosio::native_tcp_socket
Connects, reads, and writes over TCP, calling the backend directly.
Synopsis
template<auto Backend>
class native_tcp_socket
: public tcp_socket
Description
This class template inherits from tcp_socket. It shadows the async operations (read_some, write_some, connect) with versions that call the backend implementation directly. The compiler can then inline through the entire call chain.
Non‐async operations (open, close, cancel, socket options) remain unchanged and dispatch through the compiled library.
A native_tcp_socket IS‐A tcp_socket and can be passed to any function expecting tcp_socket& or io_stream&. In that case, virtual dispatch is used transparently.
Thread Safety
Same as tcp_socket.
Example
capy::task<>
connect_and_read()
{
corosio::native_io_context<corosio::epoll> ctx;
corosio::native_tcp_socket<corosio::epoll> s(ctx);
auto [ec] = co_await s.connect(
corosio::endpoint(corosio::ipv4_address::loopback(), 8080));
if (ec)
co_return;
char buf[1024];
auto [ec2, n] =
co_await s.read_some(capy::mutable_buffer(buf, sizeof(buf)));
if (ec2)
co_return;
}
Types
Name |
Description |
Represent the awaitable returned by |
|
Owns a platform‐specific I/O implementation and destroys it when the handle goes out of scope. |
|
Define backend hooks for TCP socket operations. |
|
Constructs, closes, and destroys platform implementations on behalf of an I/O object. Platform backends implement this interface. |
|
Represent the awaitable returned by |
Type Aliases
Name |
Description |
The endpoint type used by this socket. |
|
The shutdown direction type used by this socket. |
Member Functions
Name |
Description |
|
Constructors |
Assignment operators |
|
Assign an existing native socket to this object. |
|
Bind the socket to a local endpoint. |
|
Cancel any pending asynchronous operations. |
|
Close the socket. |
|
Asynchronously connect to a remote endpoint. |
|
Return the execution context. |
|
Get a socket option. |
|
Check if the socket is open. |
|
Get the local endpoint of the socket. |
|
Get the native socket handle. |
|
Open the socket. |
|
Asynchronously read data from the socket. |
|
Release ownership of the native socket handle. |
|
Get the remote endpoint of the socket. |
|
Set a socket option. |
|
Disable sends or receives on the socket. |
|
Asynchronously wait for the socket to be ready. |
|
Asynchronously write data to the socket. |
Protected Types
Name |
Description |
Awaitable for async read operations. |
|
Awaitable for async write operations. |
Protected Member Functions
Name |
Description |
Assignment operators |
|
|
Dispatch read through implementation vtable. |
|
Dispatch write through implementation vtable. |
Protected Static Member Functions
Name |
Description |
Create a handle bound to a service found in the context. |
Template Parameters
Name |
Description |
Backend |
A backend tag value (e.g., |
See Also
tcp_socket, epoll_t, iocp_t
Created with MrDocs