|
idfxx 1.0.0
Modern C++23 components for ESP-IDF
|
A TCP netconn channel. More...
Public Member Functions | |
| stream_channel () | |
| Creates a TCP netconn with default address family (IPv4). | |
| stream_channel (address_family fam) | |
| Creates a TCP netconn for the given address family. | |
| void | connect (const endpoint &peer) |
| Connects to the given remote endpoint. | |
| result< void > | try_connect (const endpoint &peer) |
| Connects to the given remote endpoint. | |
| void | close () |
| Closes the netconn. | |
| result< void > | try_close () |
| Closes the netconn. | |
| void | shutdown () |
| Shuts down both directions on the netconn. | |
| result< void > | try_shutdown () |
| Shuts down both directions on the netconn. | |
| void | shutdown (direction dir) |
| Shuts down one direction on the netconn (half-close). | |
| result< void > | try_shutdown (direction dir) |
| Shuts down one direction on the netconn (half-close). | |
| size_t | send (std::span< const std::byte > data, idfxx::flags< write_flag > flags={}) |
| Sends a buffer on the TCP netconn. | |
| result< size_t > | try_send (std::span< const std::byte > data, idfxx::flags< write_flag > flags={}) |
| Sends a buffer on the TCP netconn. | |
| size_t | send (std::string_view data, idfxx::flags< write_flag > flags={}) |
| Sends a string view on the TCP netconn. | |
| result< size_t > | try_send (std::string_view data, idfxx::flags< write_flag > flags={}) |
| Sends a string view on the TCP netconn. | |
| buffer | recv () |
| Receives the next buffer from the connection. | |
| result< buffer > | try_recv () |
| Receives the next buffer from the connection. | |
| std::span< std::byte > | recv (std::span< std::byte > buf) |
| Receives data into a caller-provided buffer. | |
| result< std::span< std::byte > > | try_recv (std::span< std::byte > buf) |
| Receives data into a caller-provided buffer. | |
| endpoint | peer_endpoint () const |
| Returns the remote endpoint the channel is connected to. | |
| result< endpoint > | try_peer_endpoint () const |
| Returns the remote endpoint the channel is connected to. | |
Static Public Member Functions | |
| static result< stream_channel > | make () |
| Creates a TCP netconn with default address family (IPv4). | |
| static result< stream_channel > | make (address_family fam) |
| Creates a TCP netconn for the given address family. | |
Friends | |
| class | listener |
A TCP netconn channel.
Use idfxx::net::netconn::listener to accept inbound connections; this class is for outbound client connections and for the per-connection channel returned by the listener.
Ownership is exclusive: the channel is non-copyable and move-only. A moved-from channel may only be destroyed, move-assigned, or queried via is_open() (→ false) and idf_handle() (→ nullptr); calling any other method on it is undefined behavior. The destructor releases the channel if open.
Definition at line 80 of file stream_channel.hpp.
| idfxx::net::netconn::stream_channel::stream_channel | ( | ) |
Creates a TCP netconn with default address family (IPv4).
CONFIG_COMPILER_CXX_EXCEPTIONS is enabled. | std::system_error | on failure. |
|
explicit |
Creates a TCP netconn for the given address family.
| fam | Address family. |
CONFIG_COMPILER_CXX_EXCEPTIONS is enabled. | std::system_error | on failure. |
|
inline |
Closes the netconn.
CONFIG_COMPILER_CXX_EXCEPTIONS is enabled. | std::system_error | on failure. |
Definition at line 150 of file stream_channel.hpp.
References idfxx::unwrap().
Connects to the given remote endpoint.
| peer | Remote endpoint to connect to. |
CONFIG_COMPILER_CXX_EXCEPTIONS is enabled. | std::system_error | on failure. |
Definition at line 132 of file stream_channel.hpp.
References idfxx::unwrap().
|
static |
Creates a TCP netconn with default address family (IPv4).
|
static |
Creates a TCP netconn for the given address family.
| fam | Address family. |
|
inline |
Returns the remote endpoint the channel is connected to.
CONFIG_COMPILER_CXX_EXCEPTIONS is enabled. | std::system_error | on failure (e.g. the channel is not connected). |
Definition at line 368 of file stream_channel.hpp.
References idfxx::unwrap().
|
inline |
Receives the next buffer from the connection.
On graceful peer close the returned buffer is non-owning (is_open() == false); this is the loop termination signal and is not an error.
CONFIG_COMPILER_CXX_EXCEPTIONS is enabled. | std::system_error | on failure. |
Definition at line 320 of file stream_channel.hpp.
References idfxx::unwrap().
|
inline |
Receives data into a caller-provided buffer.
On graceful peer close the returned span is empty; this is the loop termination signal and is not an error.
| buf | Destination buffer. |
CONFIG_COMPILER_CXX_EXCEPTIONS is enabled. | std::system_error | on failure. |
buf covering the bytes actually received, or an empty span on graceful close. Definition at line 345 of file stream_channel.hpp.
References idfxx::unwrap().
|
inline |
Sends a buffer on the TCP netconn.
By default the data is copied into the stack's buffers, so data may be reused or destroyed as soon as this call returns. Pass write_flag::no_copy to reference the caller's buffer instead.
In the default blocking mode the full buffer is sent or an error is thrown. The returned byte count is informational and only diverges from data.size() when write_flag::dont_block is set; for that partial-write accounting use try_send.
write_flag::no_copy set, data must remain valid and unmodified until the data has been transmitted and acknowledged by the peer — not merely until this call returns. Use only for storage that outlives the connection (e.g. static or flash-resident data).| data | Data to send. |
| flags | Flags controlling copy behaviour and PSH suppression. |
CONFIG_COMPILER_CXX_EXCEPTIONS is enabled. | std::system_error | on failure. |
Definition at line 236 of file stream_channel.hpp.
|
inline |
Sends a string view on the TCP netconn.
By default the data is copied into the stack's buffers, so data may be reused or destroyed as soon as this call returns. Pass write_flag::no_copy to reference the caller's buffer instead.
In the default blocking mode the full buffer is sent or an error is thrown. The returned byte count is informational and only diverges from data.size() when write_flag::dont_block is set; for that partial-write accounting use try_send.
write_flag::no_copy set, data must remain valid and unmodified until the data has been transmitted and acknowledged by the peer — not merely until this call returns.| data | Data to send. |
| flags | Flags controlling copy behaviour and PSH suppression. |
CONFIG_COMPILER_CXX_EXCEPTIONS is enabled. | std::system_error | on failure. |
Definition at line 285 of file stream_channel.hpp.
|
inline |
Shuts down both directions on the netconn.
CONFIG_COMPILER_CXX_EXCEPTIONS is enabled. | std::system_error | on failure. |
Definition at line 167 of file stream_channel.hpp.
References idfxx::unwrap().
Shuts down one direction on the netconn (half-close).
The two directions are independent: after shutdown(direction::send) the peer sees end-of-stream but recv keeps returning data the peer sends until it closes; after shutdown(direction::receive) further reads return the empty-buffer close signal while sends still succeed.
| dir | Direction to shut down. |
CONFIG_COMPILER_CXX_EXCEPTIONS is enabled. | std::system_error | on failure. |
Definition at line 191 of file stream_channel.hpp.
References idfxx::unwrap().
Closes the netconn.
Connects to the given remote endpoint.
| peer | Remote endpoint to connect to. |
Returns the remote endpoint the channel is connected to.
Definition at line 376 of file stream_channel.hpp.
Receives the next buffer from the connection.
| result< std::span< std::byte > > idfxx::net::netconn::stream_channel::try_recv | ( | std::span< std::byte > | buf | ) |
Receives data into a caller-provided buffer.
| buf | Destination buffer. |
buf covering the bytes actually received (empty on graceful close), or an error. | result< size_t > idfxx::net::netconn::stream_channel::try_send | ( | std::span< const std::byte > | data, |
| idfxx::flags< write_flag > | flags = {} |
||
| ) |
Sends a buffer on the TCP netconn.
By default the data is copied into the stack's buffers, so data may be reused or destroyed as soon as this call returns. Pass write_flag::no_copy to reference the caller's buffer instead.
write_flag::no_copy set, data must remain valid and unmodified until the data has been transmitted and acknowledged by the peer — not merely until this call returns. Use only for storage that outlives the connection (e.g. static or flash-resident data).| data | Data to send. |
| flags | Flags controlling copy behaviour and PSH suppression. |
| result< size_t > idfxx::net::netconn::stream_channel::try_send | ( | std::string_view | data, |
| idfxx::flags< write_flag > | flags = {} |
||
| ) |
Sends a string view on the TCP netconn.
By default the data is copied into the stack's buffers, so data may be reused or destroyed as soon as this call returns. Pass write_flag::no_copy to reference the caller's buffer instead.
write_flag::no_copy set, data must remain valid and unmodified until the data has been transmitted and acknowledged by the peer — not merely until this call returns.| data | Data to send. |
| flags | Flags controlling copy behaviour and PSH suppression. |
Shuts down both directions on the netconn.
Shuts down one direction on the netconn (half-close).
The two directions are independent: after shutdown(direction::send) the peer sees end-of-stream but recv keeps returning data the peer sends until it closes; after shutdown(direction::receive) further reads return the empty-buffer close signal while sends still succeed.
| dir | Direction to shut down. |
Definition at line 379 of file stream_channel.hpp.