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

aiogate Class Reference

abstraction for callback More...

#include <aiogate.h>

Inheritance diagram for aiogate:

terimber_aiogate terimber_aiosock_callback terimber_thread_employer terimber_log_helper terimber_log

List of all members.

Public Member Functions

 aiogate (size_t addional_working_threads, size_t mem_usage)
 consrtuctor
virtual ~aiogate ()
 destructor
virtual void v_on_error (size_t handle, int err, aiosock_type mask, void *userdata)
 port will call function after error occured
virtual void v_on_connect (size_t handle, const sockaddr_in &peeraddr, void *userdata)
 port will call function after successfully connecting to socket
virtual void v_on_send (size_t handle, void *buf, size_t requested, size_t processed, const sockaddr_in &toaddr, void *userdata)
 port will call function after successfully sending buffer to socket
virtual void v_on_receive (size_t handle, void *buf, size_t requested, size_t processed, const sockaddr_in &toaddr, void *userdata)
 port will call function after successfully receiving buffer from socket
virtual void v_on_accept (size_t handle, size_t handle_accepted, terimber_aiosock_callback *&callback, const sockaddr_in &peeraddr, void *userdata)
 port will call function after successfully accepting the new incoming connection user can change the callback, by default it's an object which created a listener
virtual size_t listen (const char *address, unsigned short port, size_t max_connection, unsigned short buffered_acceptors, terimber_aiogate_pin_factory *factory, void *arg)
 starts listening TCP port on specified address
virtual void deaf (size_t ident)
 stops listener with specified ident
virtual size_t connect (const char *remote, unsigned short rport, const char *local, unsigned short lport, size_t timeout, terimber_aiogate_pin_factory *factory, void *arg)
 initiates connection
virtual size_t bind (const char *address, unsigned short port, terimber_aiogate_pin_factory *factory, void *arg)
 bind to the specified socket address
virtual bool send (size_t ident, const void *buf, size_t len, const sockaddr_in *toaddr)
 sends buf bytes asynchronously
virtual bool send_bulk (size_t ident, const terimber_aiogate_buffer *bulk, size_t count, const sockaddr_in *toaddr)
 sends bulk of buffers asynchronously
virtual bool recv (size_t ident, bool expect_delivery, const sockaddr_in *toaddr)
 initiates receive process, either use big buffer or just a small one in order to save the memory usage for a unknown waiting time
virtual bool close (size_t ident)
 close connection pin
virtual bool set_send_timeout (size_t ident, size_t timeout)
 set send timeout
virtual bool set_recv_timeout (size_t ident, size_t timeout)
 sets recv timeout
virtual void doxray ()
 makes the snapshot of internal state
bool on ()
 activates aiogate
void off ()
 deactivates aiogate

Protected Member Functions

virtual bool v_has_job (size_t ident, void *user_data)
 checks if any activity is required
virtual void v_do_job (size_t ident, void *user_data)
 do real pin activity

Private Types

typedef map< size_t,
listener_info
listener_map_t
 maps listener ident to listener information
typedef map< size_t, pin_infopin_map_t
 maps pin ident to pin information
typedef node_allocator
< fixed_size_buffer
chunk_allocator_t
 node allocator for linked list buffers
typedef list< pin_info_extraclose_list_t
 lists pins prepeared for destruction

Private Member Functions

void lock_pin (mutex_keeper &mtx, pin_info &info, ub4_t mask)
 locks pin while callback invoking
bool unlock_pin (mutex_keeper &mtx, size_t ident, ub4_t mask, bool unmask_in_progress)
 unlocks pin
void initiate_close (size_t ident, size_t mask, bool invoke_callback)
 initiates pin closure
void final_close (pin_info_extra &info)
 actual pin closure in a separate thread

Private Attributes

bool _on
 on/off flag
mutex _pin_mtx
 pin mutex
listener_map_t _listener_map
 listener map
pin_map_t _pin_map
 pin map
aiosock _pin_port
 aiosock port
chunk_allocator_t _pin_allocator
 memory chunks allocator
close_list_t _pin_list
 list of pins prepared for final closure
thread _pin_thread
 housekeeping thread

Classes

class  listener_info
 keeps listener information More...
class  pin_info
 pin info with information about pin status More...
class  pin_info_extra
 pin information required for proper pin destruction More...
class  pin_info_minimum
 min pin information More...
class  udp_header
 keeps information for udp package More...


Detailed Description

abstraction for callback

class aiogate< callbacks for thread that closes pins

Definition at line 66 of file aiogate.h.


Member Typedef Documentation

maps listener ident to listener information

Definition at line 204 of file aiogate.h.

aiogate::pin_map_t [private]

maps pin ident to pin information

Definition at line 207 of file aiogate.h.

node allocator for linked list buffers

Definition at line 210 of file aiogate.h.

lists pins prepeared for destruction

Definition at line 213 of file aiogate.h.


Constructor & Destructor Documentation

BEGIN_TERIMBER_NAMESPACE aiogate::aiogate ( size_t  addional_working_threads,
size_t  mem_usage 
)

consrtuctor

Parameters:
addional_working_threads  additional working thread for processing user callbacks
mem_usage  max memory usage in bytes

Definition at line 62 of file aiogate.cpp.

aiogate::~aiogate (  )  [virtual]

destructor

Definition at line 70 of file aiogate.cpp.

References off().


Member Function Documentation

void aiogate::v_on_error ( size_t  handle,
int  err,
aiosock_type  mask,
void *  userdata 
) [virtual]

port will call function after error occured

Parameters:
handle  socket ident
err  error code
mask  type of action when error occurred
userdata  user defined data

Implements terimber_aiosock_callback.

Definition at line 79 of file aiogate.cpp.

References _pin_map, _pin_mtx, aiogate_accept_mask, aiogate_connect_mask, aiogate_recv_mask, aiogate_send_mask, AIOSOCK_ACCEPT, AIOSOCK_CONNECT, AIOSOCK_RECV, AIOSOCK_SEND, en_log_info, en_log_warning, base_map< K, T, Pr, M >::end(), base_map< K, T, Pr, M >::find(), terimber_log::format_logging(), initiate_close(), and mutex_keeper::unlock().

void aiogate::v_on_connect ( size_t  handle,
const sockaddr_in &  peeraddr,
void *  userdata 
) [virtual]

port will call function after successfully connecting to socket

Parameters:
handle  socket ident
peeraddr  peer address
userdata  user defined data

Implements terimber_aiosock_callback.

Definition at line 204 of file aiogate.cpp.

References _pin_map, _pin_mtx, _pin_port, aiogate_connect_mask, en_log_error, en_log_info, en_log_warning, base_map< K, T, Pr, M >::end(), base_map< K, T, Pr, M >::find(), terimber_log::format_logging(), aiosock::getpeeraddr(), aiosock::getsockaddr(), initiate_close(), lock_pin(), terimber_aiogate_pin::on_connect(), mutex_keeper::unlock(), and unlock_pin().

void aiogate::v_on_send ( size_t  handle,
void *  buf,
size_t  requested,
size_t  processed,
const sockaddr_in &  toaddr,
void *  userdata 
) [virtual]

void aiogate::v_on_receive ( size_t  handle,
void *  buf,
size_t  requested,
size_t  processed,
const sockaddr_in &  toaddr,
void *  userdata 
) [virtual]

port will call function after successfully receiving buffer from socket

Parameters:
handle  socket ident
buf  buffer to receive bytes
requested  bytes requested for receive
processed  bytes actually received
toaddr  peer address
userdata  user defined data

Implements terimber_aiosock_callback.

Definition at line 400 of file aiogate.cpp.

References aiogate::pin_info::_leader, aiogate::pin_info_minimum::_pin, _pin_map, _pin_mtx, fixed_size_buffer::_ptr, aiogate::pin_info_minimum::_rbuf, aiogate_recv_mask, en_log_error, en_log_info, en_log_warning, base_map< K, T, Pr, M >::end(), base_map< K, T, Pr, M >::find(), terimber_log::format_logging(), initiate_close(), lock_pin(), terimber_aiogate_pin::on_recv(), recv(), mutex_keeper::unlock(), and unlock_pin().

void aiogate::v_on_accept ( size_t  handle,
size_t  handle_accepted,
terimber_aiosock_callback *&  callback,
const sockaddr_in &  peeraddr,
void *  userdata 
) [virtual]

port will call function after successfully accepting the new incoming connection user can change the callback, by default it's an object which created a listener

Parameters:
handle  listener socket ident
handle_accepted  accepted new incoming socket connection ident
callback  callback for processing further asynchronous actions
peeraddr  peer address
userdata  user defined data

Implements terimber_aiosock_callback.

Definition at line 462 of file aiogate.cpp.

References aiogate::pin_info_minimum::_factory, _listener_map, aiogate::pin_info_minimum::_pin, _pin_map, _pin_mtx, _pin_port, aiogate::pin_info::_tcp_udp, aiogate_accept_mask, aiosock::close(), en_log_error, en_log_info, base_map< K, T, Pr, M >::end(), map< K, T, Pr, M >::erase(), base_map< K, T, Pr, M >::find(), pair< T1, T2 >::first, terimber_log::format_logging(), aiosock::getpeeraddr(), aiosock::getsockaddr(), map< K, T, Pr, M >::insert(), lock_pin(), terimber_aiogate_pin::on_accept(), and unlock_pin().

size_t aiogate::listen ( const char *  address,
unsigned short  port,
size_t  max_connection,
unsigned short  buffered_acceptors,
terimber_aiogate_pin_factory factory,
void *  arg 
) [virtual]

starts listening TCP port on specified address

Parameters:
address  server ip or name, can be null - localhost will be used
port  listening port
max_connection  max waited connections
buffered_acceptors  how many acceptor will be waiting for incoming pins
factory  factory, which knows how to create pin
arg  user defined argument - will be used for terimber_aiogate_pin_factory::create method as an input argument

Implements terimber_aiogate.

Definition at line 596 of file aiogate.cpp.

References _listener_map, _pin_mtx, _pin_port, aiogate_accept_mask, aiosock::close(), aiosock::create(), en_log_error, en_log_info, base_map< K, T, Pr, M >::end(), map< K, T, Pr, M >::erase(), terimber_log::format_logging(), map< K, T, Pr, M >::insert(), and aiosock::listen().

void aiogate::deaf ( size_t  ident  )  [virtual]

stops listener with specified ident

Parameters:
ident  listener socket ident

Implements terimber_aiogate.

Definition at line 651 of file aiogate.cpp.

References _listener_map, _pin_mtx, _pin_port, aiosock::close(), en_log_info, base_map< K, T, Pr, M >::end(), map< K, T, Pr, M >::erase(), base_map< K, T, Pr, M >::find(), and terimber_log::format_logging().

size_t aiogate::connect ( const char *  remote,
unsigned short  rport,
const char *  local,
unsigned short  lport,
size_t  timeout,
terimber_aiogate_pin_factory factory,
void *  arg 
) [virtual]

initiates connection

Returns:
ident if asynchronous connection process has been initiated when asynchronous connection completed (failed or succeeded) connect --> factory->create() --> (pin->on_connect() OR pin->on_close())
Parameters:
remote  remote host ip or name
rport  remote port
local  local host ip or name - optional can be null
lport  local port - optional can be zero
timeout  timeout in milliseconds
factory  factory, which knows how to create pin
arg  user defined argument - will be used for terimber_aiogate_pin_factory::create method as an input argument

Implements terimber_aiogate.

Definition at line 675 of file aiogate.cpp.

References aiogate::pin_info_minimum::_factory, aiogate::pin_info_minimum::_pin, _pin_map, _pin_mtx, _pin_port, aiogate::pin_info::_tcp_udp, aiogate_connect_mask, aiosock::bind(), aiosock::close(), aiosock::connect(), terimber_aiogate_pin_factory::create(), aiosock::create(), terimber_aiogate_pin_factory::destroy(), en_log_error, en_log_info, base_map< K, T, Pr, M >::end(), map< K, T, Pr, M >::erase(), terimber_log::format_logging(), and map< K, T, Pr, M >::insert().

size_t aiogate::bind ( const char *  address,
unsigned short  port,
terimber_aiogate_pin_factory factory,
void *  arg 
) [virtual]

bool aiogate::send ( size_t  ident,
const void *  buf,
size_t  len,
const sockaddr_in *  toaddr 
) [virtual]

sends buf bytes asynchronously

Parameters:
ident  unique pin identificator
buf  buffer to send
len  length of buffer
toaddr  peer address, optional - only for UDP

Implements terimber_aiogate.

Definition at line 861 of file aiogate.cpp.

References terimber_aiogate_buffer::buf, terimber_aiogate_buffer::len, and send_bulk().

bool aiogate::send_bulk ( size_t  ident,
const terimber_aiogate_buffer bulk,
size_t  count,
const sockaddr_in *  toaddr 
) [virtual]

sends bulk of buffers asynchronously

Parameters:
ident  unique pin identificator
bulk  buffers to send
count  length of bulk
toaddr  peer address, optional - only for UDP

Implements terimber_aiogate.

Definition at line 878 of file aiogate.cpp.

References aiogate::udp_header::_addr, aiogate::udp_header::_payload, _pin_allocator, _pin_map, _pin_mtx, _pin_port, base_map< K, T, Pr, M >::const_iterator::_ptr, aiogate_send_mask, node_allocator< T >::allocate(), terimber_aiogate_buffer::buf, BUFFER_CHUNK, en_log_error, en_log_paranoid, base_map< K, T, Pr, M >::end(), base_map< K, T, Pr, M >::find(), terimber_log::format_logging(), terimber_aiogate_buffer::len, and aiosock::send().

Referenced by send().

bool aiogate::recv ( size_t  ident,
bool  expect_delivery,
const sockaddr_in *  toaddr 
) [virtual]

initiates receive process, either use big buffer or just a small one in order to save the memory usage for a unknown waiting time

Parameters:
ident  unique identificator
expect_delivery  memory usage advisor
toaddr  peer address optional - only for UDP

Implements terimber_aiogate.

Definition at line 1031 of file aiogate.cpp.

References _pin_allocator, _pin_map, _pin_mtx, _pin_port, base_map< K, T, Pr, M >::const_iterator::_ptr, aiogate_recv_mask, node_allocator< T >::allocate(), BUFFER_CHUNK, rep_allocator::deallocate(), en_log_error, en_log_paranoid, base_map< K, T, Pr, M >::end(), base_map< K, T, Pr, M >::find(), terimber_log::format_logging(), and aiosock::receive().

Referenced by v_on_receive().

bool aiogate::close ( size_t  ident  )  [virtual]

close connection pin

Parameters:
ident  unique pin identificator

Implements terimber_aiogate.

Definition at line 1130 of file aiogate.cpp.

References _pin_map, _pin_mtx, en_log_error, en_log_info, base_map< K, T, Pr, M >::end(), base_map< K, T, Pr, M >::find(), terimber_log::format_logging(), initiate_close(), and mutex_keeper::unlock().

bool aiogate::set_send_timeout ( size_t  ident,
size_t  timeout 
) [virtual]

set send timeout

Parameters:
ident  unique pin identificator
timeout  timeout in milliseconds

Implements terimber_aiogate.

Definition at line 1092 of file aiogate.cpp.

References _pin_map, _pin_mtx, en_log_info, base_map< K, T, Pr, M >::end(), base_map< K, T, Pr, M >::find(), and terimber_log::format_logging().

bool aiogate::set_recv_timeout ( size_t  ident,
size_t  timeout 
) [virtual]

sets recv timeout

Parameters:
ident  unique pin identificator
timeout  timeout in milliseconds

Implements terimber_aiogate.

Definition at line 1111 of file aiogate.cpp.

References _pin_map, _pin_mtx, en_log_error, base_map< K, T, Pr, M >::end(), base_map< K, T, Pr, M >::find(), and terimber_log::format_logging().

bool aiogate::v_has_job ( size_t  ident,
void *  user_data 
) [protected, virtual]

checks if any activity is required

Parameters:
ident  thread ident
user_data  user defined data

Implements terimber_thread_employer.

Definition at line 1152 of file aiogate.cpp.

References _pin_list, _pin_mtx, and base_list< T >::empty().

void aiogate::v_do_job ( size_t  ident,
void *  user_data 
) [protected, virtual]

do real pin activity

Parameters:
ident  thread ident
user_data  user defined data

Implements terimber_thread_employer.

Definition at line 1161 of file aiogate.cpp.

References _pin_list, _pin_mtx, base_list< T >::empty(), final_close(), base_list< T >::front(), list< T >::pop_front(), and mutex_keeper::unlock().

void aiogate::lock_pin ( mutex_keeper mtx,
pin_info info,
ub4_t  mask 
) [private]

locks pin while callback invoking

Parameters:
mtx  mutex
info  pin info reference
mask  action mask

Definition at line 541 of file aiogate.cpp.

References aiogate::pin_info::_callback_invoking_mask, and mutex_keeper::unlock().

Referenced by bind(), v_on_accept(), v_on_connect(), v_on_receive(), and v_on_send().

bool aiogate::unlock_pin ( mutex_keeper mtx,
size_t  ident,
ub4_t  mask,
bool  unmask_in_progress 
) [private]

unlocks pin

Parameters:
ident  mutex
mask  pin ident
unmask_in_progress  action mask flag tells should function unmask ot not

Definition at line 552 of file aiogate.cpp.

References _pin_map, en_log_error, base_map< K, T, Pr, M >::end(), base_map< K, T, Pr, M >::find(), terimber_log::format_logging(), initiate_close(), mutex_keeper::lock(), and mutex_keeper::unlock().

Referenced by bind(), v_on_accept(), v_on_connect(), v_on_receive(), and v_on_send().

void aiogate::initiate_close ( size_t  ident,
size_t  mask,
bool  invoke_callback 
) [private]

initiates pin closure

Parameters:
ident  pin ident
mask  reason why pin is about to close
invoke_callback  flag should user callback be invoked upon pin closure

Definition at line 1178 of file aiogate.cpp.

References _pin_list, _pin_map, _pin_mtx, _pin_thread, base_map< K, T, Pr, M >::end(), map< K, T, Pr, M >::erase(), base_map< K, T, Pr, M >::find(), list< T >::push_back(), mutex_keeper::unlock(), and thread::wakeup().

Referenced by close(), unlock_pin(), v_on_connect(), v_on_error(), v_on_receive(), and v_on_send().


Member Data Documentation

bool aiogate::_on [private]

on/off flag

Definition at line 417 of file aiogate.h.

Referenced by off(), and on().

listener map

Definition at line 419 of file aiogate.h.

Referenced by deaf(), doxray(), listen(), and v_on_accept().

memory chunks allocator

Definition at line 422 of file aiogate.h.

Referenced by doxray(), final_close(), off(), recv(), send_bulk(), and v_on_send().

list of pins prepared for final closure

Definition at line 423 of file aiogate.h.

Referenced by doxray(), initiate_close(), off(), v_do_job(), and v_has_job().

housekeeping thread

Definition at line 424 of file aiogate.h.

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


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


© Copyright Terimber 2003-.