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

Asynchronous file handle driven by the poller's implementation. More...

#include <socket.hpp>

Inheritance diagram for NNet::TPollerDrivenFileHandle< T >:
NNet::TFileHandle NNet::TSocketBase< TFileOps >

Public Types

using TPoller = T
 

Public Member Functions

 TPollerDrivenFileHandle (int fd, T &poller)
 Constructs a TPollerDrivenFileHandle from an existing file descriptor.
 
auto ReadSome (void *buf, size_t size)
 Asynchronously reads data from the file into the provided buffer.
 
auto WriteSome (const void *buf, size_t size)
 Asynchronously writes data from the provided buffer to the file.
 
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::TFileHandle
 TFileHandle (int fd, TPollerBase &poller)
 Constructs a TFileHandle from an existing file descriptor.
 
 TFileHandle (TFileHandle &&other)
 
TFileHandleoperator= (TFileHandle &&other)
 
- Public Member Functions inherited from NNet::TSocketBase< TFileOps >
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< TFileOps >
 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
 

Detailed Description

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

Asynchronous file handle driven by the poller's implementation.

This class implements file I/O operations (e.g. read, write) using methods provided by the poller. In such scenarios, the poller controls the behavior of these operations (for example, when using io_uring on Linux or IOCP on Windows).

Ordinary users should not choose a file handle type directly. Instead, they should use the type defined by the poller (i.e. typename TPoller::TFileHandle), which will resolve to either TFileHandle or TPollerDrivenFileHandle depending on the poller in use.

Template Parameters
TThe poller type that defines the asynchronous file operations.

Constructor & Destructor Documentation

◆ TPollerDrivenFileHandle()

template<typename T>
NNet::TPollerDrivenFileHandle< T >::TPollerDrivenFileHandle ( int fd,
T & poller )
inline

Constructs a TPollerDrivenFileHandle from an existing file descriptor.

The file descriptor is owned by the TPollerDrivenFileHandle and will be closed in the destructor.

Parameters
fdThe file descriptor to manage.
pollerReference to the poller for asynchronous I/O.

Member Function Documentation

◆ ReadSome()

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

Asynchronously reads data from the file into the provided buffer.

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

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

◆ WriteSome()

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

Asynchronously writes data from the provided buffer to the file.

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

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

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