template<typename
TSocket>
class NNet::TByteWriter< TSocket >
A utility for writing data to a socket-like object.
This class provides methods to write a specified number of bytes or to write a TLine
object. If the underlying socket indicates it cannot make progress, the write operation is retried; if the socket is closed (write returns 0), an exception is thrown.
- Template Parameters
-
TSocket | The socket type used for writing bytes. It must provide a method TValueTask<ssize_t> WriteSome(const void* data, size_t size) which returns:
- 0 if the connection is closed,
- a positive number for the count of bytes successfully written,
- a negative number to indicate a recoverable write error (in which case a retry may be attempted).
|
Example Usage
TValueTask<void> ExampleFunction(
TSocket& socket) {
const char* message = "Hello, World!";
co_await writer.Write(message, std::strlen(message));
TLine line{
"PartA",
"PartB"};
co_await writer.Write(line);
co_return;
}
High-level asynchronous socket for network communication.
Definition socket.hpp:364
TByteWriter(TSocket &socket)
Constructs a writer for the given socket.
Definition sockutils.hpp:195
Definition sockutils.hpp:9