Thread portable class


Gate portable class


Timer class


Pool class


Terimber 2.0


About C++


Downloads Products & Services Support Clients Open Source About



Home / Open source / Terimber 2.0

aiofile Class Reference

expands windows IO Completion Port idea to Linux More...

#include <aiofile.h>

Inheritance diagram for aiofile:

terimber_thread_employer terimber_aiofile terimber_log_helper terimber_log

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_fileaiofile_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

node allocator for list of blocks

Definition at line 92 of file aiofile.h.

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.

reverses map file handle to file map interator

Definition at line 163 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.

aiofile::~aiofile (  ) 

destructor

Definition at line 158 of file aiofile.cpp.

References off().


Member Function Documentation

void aiofile::_clear_block_lists (  )  [inline, private]

clears all block lists outgoing, abounded, initial

Definition at line 173 of file aiofile.h.

References _abounded_list, _initial_list, _outgoing_list, _put_block(), base_list< T >::begin(), list< T >::clear(), base_list< T >::empty(), and base_list< T >::end().

Referenced by off().

aiofile_block* aiofile::_get_block (  )  [inline, private]

gets new blocks

Definition at line 213 of file aiofile.h.

References _block_allocator, and node_allocator< T >::allocate().

Referenced by read(), and write().

void aiofile::_put_block ( aiofile_block block  )  [inline, private]

returns used block back

Definition at line 227 of file aiofile.h.

References _block_allocator, and rep_allocator::deallocate().

Referenced by _activate_block(), _clear_block_lists(), close(), complete_block(), process_timeouted_blocks(), and v_do_job().

size_t aiofile::open ( const char *  file_name,
bool  read_write,
terimber_aiofile_callback callback 
) [virtual]

open file

Parameters:
file_name  file name
read_write  open for read or write only
callback  user callback class

Implements terimber_aiofile.

Definition at line 647 of file aiofile.cpp.

References _aiofile_io_handle, _assign_file(), _mtx, en_log_error, and terimber_log::format_logging().

int aiofile::write ( size_t  handle,
size_t  offset,
const void *  buf,
size_t  len,
size_t  timeout,
void *  userdata 
) [virtual]

sends buffer to specified file asynchronously

Parameters:
handle  valid file ident
offset  file offset
buf  buffer
len  length of buffer
timeout  timeout in milliseconds
userdata  user defined data

Implements terimber_aiofile.

Definition at line 781 of file aiofile.cpp.

References _activate_block(), aiofile_block::_buf, _get_block(), aiofile_block::_len, _mtx, aiofile_block::_type, aiofile_block::_userdata, AIOFILE_WRITE, and aiofile_block::set_timeout().

int aiofile::read ( size_t  handle,
size_t  offset,
void *  buf,
size_t  len,
size_t  timeout,
void *  userdata 
) [virtual]

receives buffer of bytes from specified file asynchronously

Parameters:
handle  valid file ident
offset  file offset
buf  buffer
len  length of buffer
timeout  timeout in milliseconds
userdata  user defined data

Implements terimber_aiofile.

Definition at line 808 of file aiofile.cpp.

References _activate_block(), aiofile_block::_buf, _get_block(), aiofile_block::_len, _mtx, aiofile_block::_type, aiofile_block::_userdata, AIOFILE_READ, and aiofile_block::set_timeout().

void aiofile::doxray (  )  [virtual]

bool aiofile::v_has_job ( size_t  ident,
void *  data 
) [protected, virtual]

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

aio_file_handle aiofile::find_socket_handle ( size_t  ident  )  [private]

thread-safe function to find file handle by file ident

Parameters:
ident  file ident

void aiofile::complete_block ( size_t  sock_key,
aiofile_block ov,
int  err,
size_t  processed 
) [private]

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

size_t aiofile::_assign_file ( aio_file_handle  handle,
terimber_aiofile_callback callback 
) [private]

void aiofile::_cancel_file ( aio_file_handle  handle  )  [private]

cancels asynchronous operations

Parameters:
handle  file handle

Definition at line 931 of file aiofile.cpp.

References en_log_info, and terimber_log::format_logging().

Referenced by close(), and off().

void aiofile::_close_file ( aio_file_handle  handle  )  [private]

closes file

Parameters:
handle  file handle

Definition at line 919 of file aiofile.cpp.

References close(), en_log_info, and terimber_log::format_logging().

Referenced by _assign_file(), close(), and off().

int aiofile::_process_write ( aio_file_handle  handle,
aiofile_block block 
) [private]

writes the function for IO blocks processing

Parameters:
handle  file handle
block  block pointer

Definition at line 1077 of file aiofile.cpp.

References aiofile_block::_buf, aiofile_block::_err, aiofile_block::_len, and aiofile_block::_processed.

Referenced by _process_block().

int aiofile::_process_read ( aio_file_handle  handle,
aiofile_block block 
) [private]

reads the function for IO blocks processing

Parameters:
handle  file handle
block  block pointer

Definition at line 1093 of file aiofile.cpp.

References aiofile_block::_buf, aiofile_block::_err, aiofile_block::_len, and aiofile_block::_processed.

Referenced by _process_block().

void aiofile::wait_for_io_completion (  )  [private]

waits for completion actions in separate thread Terimber Completion Port

Definition at line 361 of file aiofile.cpp.

References _aiofile_io_handle, _flag_io_port, _start_io_port, _stop_io_port, complete_block(), os_minus_one, and event::signal().

Referenced by v_do_job().


Member Data Documentation

multithreaded access to file map

Definition at line 381 of file aiofile.h.

Referenced by close(), complete_block(), doxray(), off(), open(), process_timeouted_blocks(), read(), v_do_job(), v_has_job(), and write().

reverse file map

Definition at line 383 of file aiofile.h.

Referenced by _assign_file(), close(), and off().

map of the keys which can not be returned back to generator right now

Definition at line 384 of file aiofile.h.

Referenced by close(), doxray(), off(), process_timeouted_blocks(), and v_do_job().

generates file idents

Definition at line 385 of file aiofile.h.

Referenced by _assign_file(), close(), off(), process_timeouted_blocks(), and v_do_job().

external allocator for list of pointers to blocks

Definition at line 386 of file aiofile.h.

Referenced by _process_block(), close(), complete_block(), off(), and process_timeouted_blocks().

block allocator

Definition at line 387 of file aiofile.h.

Referenced by _get_block(), _put_block(), and off().

keeps initial processing reuqests

Definition at line 388 of file aiofile.h.

Referenced by _activate_block(), _clear_block_lists(), close(), doxray(), v_do_job(), and v_has_job().

keeps processed asynchronous requests

Definition at line 389 of file aiofile.h.

Referenced by _clear_block_lists(), _process_block(), close(), complete_block(), doxray(), v_do_job(), and v_has_job().

keeps abounded asynchronous requests for Complition Port only

Definition at line 392 of file aiofile.h.

Referenced by _clear_block_lists(), close(), complete_block(), doxray(), and process_timeouted_blocks().

HANDLE aiofile::_aiofile_io_handle [private]

this Terimber port handle

Definition at line 396 of file aiofile.h.

Referenced by _assign_file(), _process_block(), close(), off(), on(), open(), v_has_job(), and wait_for_io_completion().

thread pool

Definition at line 397 of file aiofile.h.

Referenced by _process_block(), complete_block(), doxray(), off(), on(), and v_do_job().

size_t aiofile::_capacity [private]

max thread pool capacity

Definition at line 398 of file aiofile.h.

Referenced by _process_block(), complete_block(), and v_do_job().

housekeeping thread - process initatial and timeouted blocks

Definition at line 399 of file aiofile.h.

Referenced by _activate_block(), off(), and on().

bool aiofile::_port_init [static, private]

initialize once

Definition at line 400 of file aiofile.h.

bool aiofile::_on [private]

activation flag

Definition at line 401 of file aiofile.h.

Referenced by off(), and on().

bool aiofile::_flag_io_port [private]

signals that the Terimber Completion Port is running

Definition at line 402 of file aiofile.h.

Referenced by on(), v_has_job(), and wait_for_io_completion().

signals that the thread is waiting for completion actions - Terimber Completion Port

Definition at line 403 of file aiofile.h.

Referenced by on(), and wait_for_io_completion().

signals that the thread stopped for completion actions - Terimber Completion Port

Definition at line 404 of file aiofile.h.

Referenced by off(), and wait_for_io_completion().


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


© Copyright Terimber 2003-.