COROIO: NNet::TSocketBase< void > Class Reference
COROIO
 
Loading...
Searching...
No Matches
NNet::TSocketBase< void > Class Reference

Internal base class encapsulating a socket (or file) descriptor and its poller. More...

#include <socket.hpp>

Public Member Functions

TPollerBasePoller ()
 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.
 

Protected Member Functions

 TSocketBase (TPollerBase &poller, int domain, int type)
 
 TSocketBase (int fd, TPollerBase &poller)
 
int Create (int domain, int type)
 Creates a new socket descriptor.
 
int Setup (int s)
 Performs additional setup on the socket descriptor.
 
 TSocketBase (TPollerBase &poller, int domain, int type)
 Constructs a TSocketBase with a new socket descriptor.
 
 TSocketBase (int fd, TPollerBase &poller)
 Constructs a TSocketBase from an existing socket descriptor.
 
 TSocketBase (const TSocketBase &other)=delete
 
TSocketBaseoperator= (TSocketBase &other) const=delete
 

Protected Attributes

TPollerBasePoller_ = nullptr
 
int Fd_ = -1
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ TSocketBase() [1/2]

NNet::TSocketBase< void >::TSocketBase ( TPollerBase & poller,
int domain,
int type )
inlineprotected

Constructs a TSocketBase with a new socket descriptor.

Parameters
pollerReference to the poller responsible for asynchronous operations.
domainThe address family (e.g., AF_INET, AF_INET6).
typeThe socket type (e.g., SOCK_STREAM, SOCK_DGRAM).

◆ TSocketBase() [2/2]

NNet::TSocketBase< void >::TSocketBase ( int fd,
TPollerBase & poller )
inlineprotected

Constructs a TSocketBase from an existing socket descriptor.

Parameters
fdAn already created socket descriptor.
pollerReference to the poller managing asynchronous I/O.

Member Function Documentation

◆ Close()

void NNet::TSocketBase< void >::Close ( )
inline

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()

int NNet::TSocketBase< void >::Create ( int domain,
int type )
protected

Creates a new socket descriptor.

Parameters
domainThe protocol family of the socket.
typeThe type of socket.
Returns
The socket descriptor on success, or -1 on failure.

◆ Monitor()

auto NNet::TSocketBase< void >::Monitor ( )
inline

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()

TPollerBase * NNet::TSocketBase< void >::Poller ( )
inline

Returns the poller associated with this socket.

Returns
A pointer to the TPollerBase responsible for managing asynchronous events.

◆ ReadSome()

auto NNet::TSocketBase< void >::ReadSome ( void * buf,
size_t size )
inline

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
bufPointer to the destination buffer.
sizeThe number of bytes to read.
Returns
An awaitable object that yields the number of bytes read.

◆ ReadSomeYield()

auto NNet::TSocketBase< void >::ReadSomeYield ( void * buf,
size_t size )
inline

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
bufPointer to the buffer where data will be stored.
sizeNumber of bytes to read.
Returns
An awaitable object yielding the number of bytes read.

◆ Setup()

int NNet::TSocketBase< void >::Setup ( int s)
protected

Performs additional setup on the socket descriptor.

This method may set socket options and configure the descriptor as needed.

Parameters
sThe socket descriptor to set up.
Returns
A status code indicating success or failure.

◆ WriteSome()

auto NNet::TSocketBase< void >::WriteSome ( const void * buf,
size_t size )
inline

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
bufPointer to the data to be written.
sizeThe number of bytes to write.
Returns
An awaitable object that yields the number of bytes written.

◆ WriteSomeYield()

auto NNet::TSocketBase< void >::WriteSomeYield ( const void * buf,
size_t size )
inline

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
bufPointer to the data to be written.
sizeNumber 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: