libfilezilla
Public Types | Public Member Functions | Static Public Attributes | Friends | List of all members
aio_buffer_pool Class Referencefinal

A buffer pool for use with async readers/writers. More...

#include <aio.hpp>

Inheritance diagram for aio_buffer_pool:
Inheritance graph
[legend]
Collaboration diagram for aio_buffer_pool:
Collaboration graph
[legend]

Public Types

typedef void * shm_handle
 

Public Member Functions

 aio_buffer_pool (logger_interface &logger, size_t buffer_count=1, size_t buffer_size=0, bool use_shm=false, std::string_view application_group_id={})
 
 operator bool () const
 
buffer_lease get_buffer (aio_waiter &h)
 
buffer_lease get_buffer (event_handler &h)
 
logger_interfacelogger () const
 
std::tuple< shm_handle, uint8_t const *, size_t > shared_memory_info () const
 
size_t buffer_count () const
 
- Public Member Functions inherited from aio_waitable
void remove_waiter (aio_waiter &h)
 
void remove_waiter (event_handler &h)
 

Static Public Attributes

static shm_handle const shm_handle_default
 

Friends

class buffer_lease
 

Additional Inherited Members

- Protected Member Functions inherited from aio_waitable
void remove_waiters ()
 Call in destructor of most-derived class.
 
void add_waiter (aio_waiter &h)
 
void add_waiter (event_handler &h)
 
void signal_availibility ()
 

Detailed Description

A buffer pool for use with async readers/writers.

Can use shared memory, see shared_memory_info()

Examples
aio.cpp, and https.cpp.

Member Function Documentation

◆ get_buffer()

buffer_lease get_buffer ( aio_waiter h)

/brief Returns either a buffer lease, or records the passed waiter/handler as waiting.

If waiting, do not call get_buffer again until after waiter/handler got signalled.

If a buffer becomes available and there are multiple waiters, the order in waiters are signaled is undefined.

◆ shared_memory_info()

std::tuple<shm_handle, uint8_t const*, size_t> shared_memory_info ( ) const

Returns a tuple with information on the mapping

  • A file descriptor or handle backing the memory
  • The base address of the mapping
  • Total size of the memory mapping

To pass buffer leases to a child process:

  • Pass the fd/handle and total size to the child
  • Create mapping in the child, obtaining its own base address
  • If parent gets a buffer lease, parent calculates offset to the base address, passes offset and buffer size to child
  • Child computes actuall address from offset and its own base address
  • Parent keeps lease until the child signals that it's done with that buffer
Warning
The child has write access to the mapping, do not pass the fd/handle to untrusted children

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