Internal base class encapsulating a socket (or file) descriptor and its poller.
More...
#include <socket.hpp>
|
TPollerBase * | Poller () |
| Returns the poller associated with this socket.
|
|
auto | ReadSome (void *buf, size_t size) |
| Asynchronously reads data from the socket into the provided buffer.
|
|
auto | ReadSomeYield (void *buf, size_t size) |
| Forces a read operation on the next event loop iteration.
|
|
auto | WriteSome (const void *buf, size_t size) |
| Asynchronously writes data from the provided buffer to the socket.
|
|
auto | WriteSomeYield (const void *buf, size_t size) |
| Forces a write operation on the next event loop iteration.
|
|
auto | Monitor () |
| Monitors the socket for remote hang-up (closure).
|
|
void | Close () |
| Closes the socket.
|
|
Internal base class encapsulating a socket (or file) descriptor and its poller.
This class stores a file descriptor and a pointer to a poller (TPollerBase) to support asynchronous I/O operations. It provides functionality to create a new socket descriptor (via Create()) and to set it up (via Setup()). Additionally, it holds the descriptor and allows cleanup via Close().
- Note
- This class is intended solely for internal use within the library. End-users should not interact directly with this class; instead, use the higher-level wrapper classes: TSocket, TFileHandle, TPollerDrivenSocket, or TPollerDrivenFileHandle.
◆ TSocketBase() [1/2]
Constructs a TSocketBase with a new socket descriptor.
- Parameters
-
poller | Reference to the poller responsible for asynchronous operations. |
domain | The address family (e.g., AF_INET, AF_INET6). |
type | The socket type (e.g., SOCK_STREAM, SOCK_DGRAM). |
◆ TSocketBase() [2/2]
Constructs a TSocketBase from an existing socket descriptor.
- Parameters
-
fd | An already created socket descriptor. |
poller | Reference to the poller managing asynchronous I/O. |
◆ Close()
Closes the socket.
Closes the socket using the low-level operation provided by TSockOps, removes it from the poller, and marks the descriptor as invalid.
◆ Create()
Creates a new socket descriptor.
- Parameters
-
domain | The protocol family of the socket. |
type | The type of socket. |
- Returns
- The socket descriptor on success, or -1 on failure.
◆ Monitor()
Monitors the socket for remote hang-up (closure).
This awaitable suspends the coroutine until a remote hang-up is detected.
- Returns
- An awaitable object that yields a boolean value (true) once the remote hang-up is detected.
◆ Poller()
Returns the poller associated with this socket.
- Returns
- A pointer to the TPollerBase responsible for managing asynchronous events.
◆ ReadSome()
Asynchronously reads data from the socket into the provided buffer.
When awaited, this method suspends the current coroutine until the read operation completes and then returns the number of bytes read.
- Parameters
-
buf | Pointer to the destination buffer. |
size | The number of bytes to read. |
- Returns
- An awaitable object that yields the number of bytes read.
◆ ReadSomeYield()
Forces a read operation on the next event loop iteration.
Similar to ReadSome(), but this variant ensures that the read is deferred to the next iteration of the event loop.
- Parameters
-
buf | Pointer to the buffer where data will be stored. |
size | Number of bytes to read. |
- Returns
- An awaitable object yielding the number of bytes read.
◆ Setup()
Performs additional setup on the socket descriptor.
This method may set socket options and configure the descriptor as needed.
- Parameters
-
s | The socket descriptor to set up. |
- Returns
- A status code indicating success or failure.
◆ WriteSome()
Asynchronously writes data from the provided buffer to the socket.
This method suspends the current coroutine until the data is written, and then returns the number of bytes successfully written.
- Parameters
-
buf | Pointer to the data to be written. |
size | The number of bytes to write. |
- Returns
- An awaitable object that yields the number of bytes written.
◆ WriteSomeYield()
Forces a write operation on the next event loop iteration.
This variant behaves similarly to WriteSome() but defers execution until the next loop iteration.
- Parameters
-
buf | Pointer to the data to be written. |
size | Number of bytes to write. |
- Returns
- An awaitable object that yields the number of bytes written.
The documentation for this class was generated from the following file: