COROIO: NNet::TPollerDrivenSocket< T > Class Template Reference
COROIO
 
Loading...
Searching...
No Matches
NNet::TPollerDrivenSocket< T > Class Template Reference

Socket type driven by the poller's implementation. More...

#include <socket.hpp>

Inheritance diagram for NNet::TPollerDrivenSocket< T >:
NNet::TSocket NNet::TSocketBase< TSockOps >

Public Types

using TPoller = T
 
- Public Types inherited from NNet::TSocket
using TPoller = TPollerBase
 

Public Member Functions

 TPollerDrivenSocket (T &poller, int domain, int type=SOCK_STREAM)
 Constructs a TPollerDrivenSocket from a poller, domain, and socket type.
 
 TPollerDrivenSocket (const TAddress &addr, int fd, T &poller)
 Constructs a TPollerDrivenSocket from an existing file descriptor.
 
 TPollerDrivenSocket (int fd, T &poller)
 
auto Accept ()
 Asynchronously accepts an incoming connection.
 
auto Connect (const TAddress &addr, TTime deadline=TTime::max())
 Asynchronously connects to the specified address with an optional deadline.
 
auto ReadSome (void *buf, size_t size)
 Asynchronously reads data from the socket.
 
auto WriteSome (const void *buf, size_t size)
 Asynchronously writes data to the socket.
 
auto WriteSomeYield (const void *buf, size_t size)
 The WriteSomeYield and ReadSomeYield variants behave similarly to WriteSome/ReadSome.
 
auto ReadSomeYield (void *buf, size_t size)
 The WriteSomeYield and ReadSomeYield variants behave similarly to WriteSome/ReadSome.
 
- Public Member Functions inherited from NNet::TSocket
 TSocket (TPollerBase &poller, int domain, int type=SOCK_STREAM)
 Constructs a TSocket using the given poller, address family, and socket type.
 
 TSocket (const TAddress &addr, int fd, TPollerBase &poller)
 Constructs a TSocket for an already-connected socket.
 
 TSocket (TSocket &&other)
 
TSocketoperator= (TSocket &&other)
 
auto Connect (const TAddress &addr, TTime deadline=TTime::max())
 Asynchronously connects to the specified address.
 
auto Accept ()
 Asynchronously accepts an incoming connection.
 
void Bind (const TAddress &addr)
 Binds the socket to the specified local address.
 
void Listen (int backlog=128)
 Puts the socket in a listening state with an optional backlog (default is 128).
 
const std::optional< TAddress > & RemoteAddr () const
 Returns the remote address of the connected peer.
 
const std::optional< TAddress > & LocalAddr () const
 Returns the local address to which the socket is bound.
 
int Fd () const
 Returns the underlying socket descriptor.
 
- Public Member Functions inherited from NNet::TSocketBase< TSockOps >
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.
 

Additional Inherited Members

- Protected Member Functions inherited from NNet::TSocketBase< TSockOps >
 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 inherited from NNet::TSocket
std::optional< TAddressLocalAddr_
 
std::optional< TAddressRemoteAddr_
 

Detailed Description

template<typename T>
class NNet::TPollerDrivenSocket< T >

Socket type driven by the poller's implementation.

This class is used when socket operations (read, write, connect, etc.) are defined by the poller—in other words, when these operations depend on the underlying poller (e.g. for high-performance I/O using uring or IOCP).

Ordinary users should not worry about selecting the appropriate socket type. Instead, they should use the type defined by the poller, i.e. typename TPoller::TSocket. Depending on the poller, this may resolve to either TSocket or TPollerDrivenSocket.

Template Parameters
TThe poller type used by this socket. The poller must provide methods for asynchronous operations (such as Connect, Accept, Recv, and Send) and timer management.

Constructor & Destructor Documentation

◆ TPollerDrivenSocket() [1/2]

template<typename T>
NNet::TPollerDrivenSocket< T >::TPollerDrivenSocket ( T & poller,
int domain,
int type = SOCK_STREAM )
inline

Constructs a TPollerDrivenSocket from a poller, domain, and socket type.

The socket is registered with the poller upon construction.

Parameters
pollerReference to the poller handling asynchronous events.
domainThe address family (e.g., AF_INET, AF_INET6).
typeThe socket type (defaults to SOCK_STREAM).

◆ TPollerDrivenSocket() [2/2]

template<typename T>
NNet::TPollerDrivenSocket< T >::TPollerDrivenSocket ( const TAddress & addr,
int fd,
T & poller )
inline

Constructs a TPollerDrivenSocket from an existing file descriptor.

Parameters
fdThe socket descriptor.
pollerReference to the poller.

Member Function Documentation

◆ Accept()

template<typename T>
auto NNet::TPollerDrivenSocket< T >::Accept ( )
inline

Asynchronously accepts an incoming connection.

Returns an awaitable object that, upon completion, yields a new TPollerDrivenSocket for the accepted connection.

Returns
An awaitable yielding the accepted TPollerDrivenSocket.

◆ Connect()

template<typename T>
auto NNet::TPollerDrivenSocket< T >::Connect ( const TAddress & addr,
TTime deadline = TTime::max() )
inline

Asynchronously connects to the specified address with an optional deadline.

Initiates a connection and returns an awaitable that completes when the connection is established. If a deadline is specified and exceeded, a timeout error is thrown.

Parameters
addrThe remote address to connect to.
deadlineThe timeout deadline (defaults to TTime::max()).
Returns
An awaitable object for the connection operation.
Exceptions
std::runtime_errorif the socket is already connected.

◆ ReadSome()

template<typename T>
auto NNet::TPollerDrivenSocket< T >::ReadSome ( void * buf,
size_t size )
inline

Asynchronously reads data from the socket.

Returns an awaitable that suspends until data is available, then returns the number of bytes read.

Parameters
bufPointer to the buffer where data will be stored.
sizeNumber of bytes to read.
Returns
An awaitable yielding the number of bytes read.

◆ WriteSome()

template<typename T>
auto NNet::TPollerDrivenSocket< T >::WriteSome ( const void * buf,
size_t size )
inline

Asynchronously writes data to the socket.

Returns an awaitable that suspends until data is written, then returns the number of bytes written.

Parameters
bufPointer to the data to write.
sizeNumber of bytes to write.
Returns
An awaitable yielding the number of bytes written.

The documentation for this class was generated from the following file: