Home / Open source / Terimber 2.0
aiofile Class Referenceexpands windows IO Completion Port idea to Linux
More...
#include <aiofile.h>
List of all members.
|
Public Member Functions |
| aiofile (size_t capacity, size_t deactivate_time_msec) |
| constructor
|
| ~aiofile () |
| destructor
|
bool | on () |
| activates
|
void | off () |
| deactivates
|
virtual size_t | open (const char *file_name, bool read_write, terimber_aiofile_callback *callback) |
| open file
|
virtual void | close (size_t handle) |
| close file
|
virtual int | write (size_t handle, size_t offset, const void *buf, size_t len, size_t timeout, void *userdata) |
| sends buffer to specified file asynchronously
|
virtual int | read (size_t handle, size_t offset, void *buf, size_t len, size_t timeout, void *userdata) |
| receives buffer of bytes from specified file asynchronously
|
virtual void | doxray () |
| makes the snapshot of internal state
|
Public Attributes |
mutex | _mtx |
| multithreaded access to file map
|
aiofile_file_map_t | _file_map |
| file map
|
aiofile_reverse_map_t | _reverse_map |
| reverse file map
|
aiofile_delay_key_t | _delay_key_map |
| map of the keys which can not be returned back to generator right now
|
unique_key_generator | _file_generator |
| generates file idents
|
aiofile_pblock_allocator_t | _incoming_list_allocator |
| external allocator for list of pointers to blocks
|
aiofile_block_allocator_t | _block_allocator |
| block allocator
|
aiofile_pblock_list_t | _initial_list |
| keeps initial processing reuqests
|
aiofile_pblock_list_t | _outgoing_list |
| keeps processed asynchronous requests
|
aiofile_pblock_list_t | _abounded_list |
| keeps abounded asynchronous requests for Complition Port only
|
Protected Member Functions |
virtual bool | v_has_job (size_t ident, void *data) |
| detects if there is any job to do
|
virtual void | v_do_job (size_t ident, void *data) |
| executes actual job in separate thread
|
Private Types |
typedef node_allocator
< base_list< aiofile_block * >
::_node > | aiofile_pblock_allocator_t |
| node allocator for list of blocks
|
typedef _list< aiofile_block
*, aiofile_pblock_allocator_t > | aiofile_pblock_alloc_list_t |
| list of block pointers with external allocator
|
typedef list< aiofile_block * > | aiofile_pblock_list_t |
| list of block pointers with internal allocator
|
typedef node_allocator
< aiofile_block > | aiofile_block_allocator_t |
| node allocator - block factory
|
typedef map< size_t,
listener_info > | aiofile_listener_map_t |
| maps listener ident to listener information
|
typedef map< size_t, aiofile_file > | aiofile_file_map_t |
| maps file ident yo file info
|
typedef map< size_t,
aiofile_file >::iterator | aiofile_file_map_iterator_t |
| aiofile_socket_map iterator
|
typedef map< aio_file_handle,
aiofile_file_map_iterator_t > | aiofile_reverse_map_t |
| reverses map file handle to file map interator
|
typedef map< aio_file_handle,
aiofile_file_map_iterator_t >
::iterator | aiofile_reverse_map_iterator_t |
| aiofile_reverse_map iterator
|
typedef map< size_t, size_t > | aiofile_delay_key_t |
| maps file ident to delay counter
|
Private Member Functions |
void | _clear_block_lists () |
| clears all block lists outgoing, abounded, initial
|
aiofile_block * | _get_block () |
| gets new blocks
|
void | _put_block (aiofile_block *block) |
| returns used block back
|
bool | resolve_socket_address (const char *address, unsigned short port, sockaddr_in &addr) |
| resolves address into IP
|
aio_file_handle | find_socket_handle (size_t ident) |
| thread-safe function to find file handle by file ident
|
void | process_timeouted_blocks () |
| processes timeouted blocks
|
void | complete_block (size_t sock_key, aiofile_block *ov, int err, size_t processed) |
| completes asynchronous action
|
int | _activate_block (size_t ident, aiofile_block *block) |
| inserts block into incoming queue for processing in a separate thread
|
size_t | _assign_file (aio_file_handle handle, terimber_aiofile_callback *callback) |
| associates file handle with completion port
|
void | _cancel_file (aio_file_handle handle) |
| cancels asynchronous operations
|
void | _close_file (aio_file_handle handle) |
| closes file
|
int | _process_block (aiofile_block *block) |
| starts actual IO processing
|
int | _process_write (aio_file_handle handle, aiofile_block *block) |
| writes the function for IO blocks processing
|
int | _process_read (aio_file_handle handle, aiofile_block *block) |
| reads the function for IO blocks processing
|
void | wait_for_io_completion () |
| waits for completion actions in separate thread Terimber Completion Port
|
Private Attributes |
HANDLE | _aiofile_io_handle |
| this Terimber port handle
|
threadpool | _thread_pool |
| thread pool
|
size_t | _capacity |
| max thread pool capacity
|
thread | _in_thread |
| housekeeping thread - process initatial and timeouted blocks
|
bool | _on |
| activation flag
|
bool | _flag_io_port |
| signals that the Terimber Completion Port is running
|
event | _start_io_port |
| signals that the thread is waiting for completion actions - Terimber Completion Port
|
event | _stop_io_port |
| signals that the thread stopped for completion actions - Terimber Completion Port
|
Static Private Attributes |
static bool | _port_init |
| initialize once
|
Classes |
class | aiofile_file |
| keeps file information including initiated asynchronous actions blocks More...
|
class | listener_info |
| listener information More...
|
Detailed Description
expands windows IO Completion Port idea to Linux
Definition at line 87 of file aiofile.h.
Member Typedef Documentation
list of block pointers with external allocator
Definition at line 95 of file aiofile.h.
list of block pointers with internal allocator
Definition at line 98 of file aiofile.h.
node allocator - block factory
Definition at line 101 of file aiofile.h.
maps listener ident to listener information
Definition at line 125 of file aiofile.h.
maps file ident yo file info
Definition at line 157 of file aiofile.h.
aiofile_socket_map iterator
Definition at line 160 of file aiofile.h.
aiofile_reverse_map iterator
Definition at line 166 of file aiofile.h.
maps file ident to delay counter
Definition at line 169 of file aiofile.h.
Constructor & Destructor Documentation
aiofile::aiofile |
( |
size_t |
capacity, |
|
|
size_t |
deactivate_time_msec | |
|
) |
| | |
constructor
- Parameters:
-
capacity |
additional threads for processing asynchronous completion callbacks |
deactivate_time_msec |
timeout in milliseconds to despose unused threads |
Definition at line 145 of file aiofile.cpp.
Member Function Documentation
void aiofile::_clear_block_lists |
( |
|
) |
[inline, private] |
void aiofile::_put_block |
( |
aiofile_block * |
block |
) |
[inline, private] |
activates
Definition at line 165 of file aiofile.cpp.
References _aiofile_io_handle, _flag_io_port, _in_thread, _on, _start_io_port, _thread_pool, aiofile_completion_io_port_ident, aiofile_completion_io_port_thread_alert, aiofile_io_initiation_ident, aiofile_io_initiation_thread_alert, aiofile_working_ident, aiofile_working_thread_alert, thread::assign_job(), threadpool::borrow_thread(), en_log_error, en_log_info, terimber_log::format_logging(), terimber_log_helper::log_on(), threadpool::on(), thread::start(), and event::wait().
deactivates
Definition at line 227 of file aiofile.cpp.
References _aiofile_io_handle, _block_allocator, _cancel_file(), _clear_block_lists(), _close_file(), _delay_key_map, _file_generator, _file_map, _in_thread, _incoming_list_allocator, _mtx, _on, _reverse_map, _stop_io_port, _thread_pool, base_map< K, T, Pr, M >::begin(), thread::cancel_job(), map< K, T, Pr, M >::clear(), unique_key_generator::clear(), rep_allocator::clear_extra(), en_log_error, en_log_info, base_map< K, T, Pr, M >::end(), terimber_log::format_logging(), terimber_log_helper::log_on(), threadpool::off(), threadpool::revoke_client(), thread::stop(), and event::wait().
Referenced by ~aiofile().
void aiofile::close |
( |
size_t |
handle |
) |
[virtual] |
close file
- Parameters:
-
Implements terimber_aiofile.
Definition at line 685 of file aiofile.cpp.
References _abounded_list, _aiofile_io_handle, _cancel_file(), _close_file(), _delay_key_map, _file_generator, aiofile_block::_file_ident, _file_map, _incoming_list_allocator, _initial_list, _mtx, _outgoing_list, _put_block(), _reverse_map, base_list< T >::begin(), en_log_error, en_log_info, base_list< T >::end(), base_map< K, T, Pr, M >::end(), list< T >::erase(), map< K, T, Pr, M >::erase(), base_map< K, T, Pr, M >::find(), terimber_log::format_logging(), map< K, T, Pr, M >::insert(), base_map< size_t, size_t, less< size_t >, false >::iterator, list< T >::push_back(), and unique_key_generator::save().
Referenced by _close_file().
int aiofile::write |
( |
size_t |
handle, |
|
|
size_t |
offset, |
|
|
const void * |
buf, |
|
|
size_t |
len, |
|
|
size_t |
timeout, |
|
|
void * |
userdata | |
|
) |
| | [virtual] |
int aiofile::read |
( |
size_t |
handle, |
|
|
size_t |
offset, |
|
|
void * |
buf, |
|
|
size_t |
len, |
|
|
size_t |
timeout, |
|
|
void * |
userdata | |
|
) |
| | [virtual] |
void aiofile::doxray |
( |
|
) |
[virtual] |
makes the snapshot of internal state
Implements terimber_aiofile.
Definition at line 834 of file aiofile.cpp.
References _abounded_list, _delay_key_map, _file_map, _initial_list, _mtx, _outgoing_list, _thread_pool, threadpool::doxray(), en_log_xray, terimber_log::format_logging(), list< T >::size(), base_map< K, T, Pr, M >::size(), and mutex_keeper::unlock().
bool aiofile::v_has_job |
( |
size_t |
ident, |
|
|
void * |
data | |
|
) |
| | [protected, virtual] |
detects if there is any job to do
- Parameters:
-
ident |
thread ident |
data |
user defined data |
Implements terimber_thread_employer.
Definition at line 305 of file aiofile.cpp.
References _aiofile_io_handle, aiofile_block::_expired, _file_map, _flag_io_port, _initial_list, _mtx, _outgoing_list, aiofile_completion_io_port_ident, aiofile_io_initiation_ident, aiofile_working_ident, base_map< K, T, Pr, M >::begin(), base_list< T >::empty(), and base_map< K, T, Pr, M >::end().
void aiofile::v_do_job |
( |
size_t |
ident, |
|
|
void * |
data | |
|
) |
| | [protected, virtual] |
executes actual job in separate thread
- Parameters:
-
ident |
thread ident |
data |
user defined data |
Implements terimber_thread_employer.
Definition at line 474 of file aiofile.cpp.
References aiofile_block::_buf, _capacity, _delay_key_map, aiofile_block::_err, _file_generator, aiofile_block::_file_ident, _file_map, _initial_list, aiofile_block::_len, _mtx, _outgoing_list, _process_block(), aiofile_block::_processed, _put_block(), _thread_pool, aiofile_block::_type, aiofile_block::_userdata, aiofile_completion_io_port_ident, aiofile_io_initiation_ident, AIOFILE_READ, aiofile_working_ident, aiofile_working_thread_alert, AIOFILE_WRITE, threadpool::borrow_from_range(), threadpool::borrow_thread(), base_list< T >::empty(), en_log_error, base_map< K, T, Pr, M >::end(), map< K, T, Pr, M >::erase(), base_map< K, T, Pr, M >::find(), terimber_log::format_logging(), base_list< T >::front(), base_map< size_t, size_t, less< size_t >, false >::iterator, mutex_keeper::lock(), list< T >::pop_front(), list< T >::push_back(), unique_key_generator::save(), mutex_keeper::unlock(), terimber_aiofile_callback::v_on_error(), terimber_aiofile_callback::v_on_read(), terimber_aiofile_callback::v_on_write(), and wait_for_io_completion().
bool aiofile::resolve_socket_address |
( |
const char * |
address, |
|
|
unsigned short |
port, |
|
|
sockaddr_in & |
addr | |
|
) |
| | [private] |
resolves address into IP
- Parameters:
-
address |
file address as string |
port |
file port |
addr |
file address as struct |
thread-safe function to find file handle by file ident
- Parameters:
-
void aiofile::process_timeouted_blocks |
( |
|
) |
[private] |
processes timeouted blocks
Definition at line 1109 of file aiofile.cpp.
References _abounded_list, _delay_key_map, aiofile_block::_expired, _file_generator, aiofile_block::_file_ident, _file_map, _incoming_list_allocator, _mtx, _put_block(), aiofile_block::_type, aiofile_block::_userdata, AIOFILE_READ, base_map< K, T, Pr, M >::begin(), en_log_error, base_map< K, T, Pr, M >::end(), map< K, T, Pr, M >::erase(), base_map< K, T, Pr, M >::find(), terimber_log::format_logging(), base_map< size_t, size_t, less< size_t >, false >::iterator, mutex_keeper::lock(), OS_TYPE, OS_WIN32, list< T >::push_back(), unique_key_generator::save(), mutex_keeper::unlock(), and terimber_aiofile_callback::v_on_error().
void aiofile::complete_block |
( |
size_t |
sock_key, |
|
|
aiofile_block * |
ov, |
|
|
int |
err, |
|
|
size_t |
processed | |
|
) |
| | [private] |
completes asynchronous action
- Parameters:
-
sock_key |
file ident |
ov |
asynchronous block pointer |
err |
error code, if any |
processed |
bytes processed |
Definition at line 408 of file aiofile.cpp.
References _abounded_list, _capacity, aiofile_block::_err, _file_map, _incoming_list_allocator, _mtx, _outgoing_list, aiofile_block::_processed, _put_block(), _thread_pool, aiofile_working_ident, aiofile_working_thread_alert, base_list< T >::begin(), threadpool::borrow_from_range(), threadpool::borrow_thread(), en_log_error, en_log_info, base_list< T >::end(), base_map< K, T, Pr, M >::end(), list< T >::erase(), base_map< K, T, Pr, M >::find(), terimber_log::format_logging(), list< T >::push_back(), and mutex_keeper::unlock().
Referenced by wait_for_io_completion().
int aiofile::_activate_block |
( |
size_t |
ident, |
|
|
aiofile_block * |
block | |
|
) |
| | [private] |
inserts block into incoming queue for processing in a separate thread
- Parameters:
-
ident |
file ident |
block |
asynchronous block pointer |
Definition at line 1047 of file aiofile.cpp.
References aiofile_block::_file_ident, _file_map, _in_thread, _initial_list, _put_block(), en_log_error, base_map< K, T, Pr, M >::end(), base_map< K, T, Pr, M >::find(), terimber_log::format_logging(), list< T >::push_back(), and thread::wakeup().
Referenced by read(), and write().
associates file handle with completion port
- Parameters:
-
handle |
file handle |
callback |
callback |
Definition at line 861 of file aiofile.cpp.
References _aiofile_io_handle, _close_file(), _file_generator, _file_map, aiofile::aiofile_file::_handle, _reverse_map, en_log_error, en_log_info, base_map< K, T, Pr, M >::end(), map< K, T, Pr, M >::erase(), terimber_log::format_logging(), unique_key_generator::generate(), map< K, T, Pr, M >::insert(), and unique_key_generator::save().
Referenced by open().
starts actual IO processing
- Parameters:
-
Definition at line 957 of file aiofile.cpp.
References _aiofile_io_handle, _capacity, aiofile_block::_err, aiofile_block::_file_ident, _file_map, _incoming_list_allocator, _outgoing_list, _process_read(), _process_write(), aiofile_block::_processed, _thread_pool, aiofile_block::_type, AIOFILE_READ, aiofile_working_ident, aiofile_working_thread_alert, AIOFILE_WRITE, threadpool::borrow_from_range(), threadpool::borrow_thread(), en_log_error, en_log_info, base_map< K, T, Pr, M >::end(), base_map< K, T, Pr, M >::find(), terimber_log::format_logging(), OS_TYPE, OS_WIN32, and list< T >::push_back().
Referenced by v_do_job().
void aiofile::wait_for_io_completion |
( |
|
) |
[private] |
Member Data Documentation
The documentation for this class was generated from the following files:
|
|