Home / Open source / Terimber 2.0
aiogate Class Referenceabstraction for callback
More...
#include <aiogate.h>
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_info > | pin_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_extra > | close_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.
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] |
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] |
port will call function after successfully sending buffer to socket
- Parameters:
-
handle |
socket handle |
buf |
buffer to send bytes |
requested |
bytes requested for sending |
processed |
bytes actually sent |
toaddr |
peer address |
userdata |
user defined data |
Implements terimber_aiosock_callback.
Definition at line 256 of file aiogate.cpp.
References aiogate::udp_header::_addr, fixed_size_buffer::_begin, fixed_size_buffer::_end, aiogate::pin_info::_in_progress_mask, fixed_size_buffer::_next, aiogate::udp_header::_payload, aiogate::pin_info_minimum::_pin, _pin_allocator, _pin_map, _pin_mtx, _pin_port, base_map< K, T, Pr, M >::const_iterator::_ptr, fixed_size_buffer::_ptr, aiogate::pin_info::_send_timeout, aiogate::pin_info_minimum::_shead, aiogate::pin_info::_stail, aiogate::pin_info::_tcp_udp, aiogate_send_mask, rep_allocator::deallocate(), 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_send(), aiosock::send(), mutex_keeper::unlock(), and unlock_pin().
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().
bind to the specified socket address
- Parameters:
-
address |
local host ip or name |
port |
local port |
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 763 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_bind_mask, aiosock::bind(), aiosock::close(), 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(), aiosock::getsockaddr(), map< K, T, Pr, M >::insert(), lock_pin(), terimber_aiogate_pin::on_bind(), and unlock_pin().
bool aiogate::send |
( |
size_t |
ident, |
|
|
const void * |
buf, |
|
|
size_t |
len, |
|
|
const sockaddr_in * |
toaddr | |
|
) |
| | [virtual] |
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().
void aiogate::doxray |
( |
|
) |
[virtual] |
makes the snapshot of internal state
Implements terimber_aiogate.
Definition at line 1243 of file aiogate.cpp.
References _listener_map, _pin_allocator, _pin_list, _pin_map, _pin_mtx, _pin_port, byte_allocator::capacity(), byte_allocator::count(), aiosock::doxray(), en_log_xray, terimber_log::format_logging(), list< T >::size(), base_map< K, T, Pr, M >::size(), and mutex_keeper::unlock().
deactivates aiogate
Definition at line 157 of file aiogate.cpp.
References aiogate::pin_info_minimum::_factory, _on, aiogate::pin_info_minimum::_pin, _pin_allocator, _pin_list, _pin_map, _pin_mtx, _pin_port, _pin_thread, base_map< K, T, Pr, M >::begin(), thread::cancel_job(), rep_allocator::clear_all(), terimber_aiogate_pin_factory::destroy(), base_list< T >::empty(), en_log_error, en_log_info, base_map< K, T, Pr, M >::end(), map< K, T, Pr, M >::erase(), terimber_log::format_logging(), base_list< T >::front(), terimber_log_helper::log_on(), aiosock::off(), list< T >::pop_front(), and thread::stop().
Referenced by ~aiogate().
bool aiogate::v_has_job |
( |
size_t |
ident, |
|
|
void * |
user_data | |
|
) |
| | [protected, virtual] |
void aiogate::v_do_job |
( |
size_t |
ident, |
|
|
void * |
user_data | |
|
) |
| | [protected, virtual] |
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().
actual pin closure in a separate thread
- Parameters:
-
Definition at line 1201 of file aiogate.cpp.
References aiogate::pin_info_minimum::_factory, aiogate::pin_info_extra::_ident, aiogate::pin_info_extra::_invoke_callback, aiogate::pin_info_extra::_mask, fixed_size_buffer::_next, aiogate::pin_info_minimum::_pin, _pin_allocator, _pin_mtx, _pin_port, aiogate::pin_info_minimum::_rbuf, aiogate::pin_info_minimum::_shead, aiosock::close(), rep_allocator::deallocate(), terimber_aiogate_pin_factory::destroy(), en_log_error, terimber_log::format_logging(), terimber_aiogate_pin::on_close(), and mutex_keeper::unlock().
Referenced by v_do_job().
Member Data Documentation
pin mutex
Definition at line 418 of file aiogate.h.
Referenced by bind(), close(), connect(), deaf(), doxray(), final_close(), initiate_close(), listen(), off(), recv(), send_bulk(), set_recv_timeout(), set_send_timeout(), v_do_job(), v_has_job(), v_on_accept(), v_on_connect(), v_on_error(), v_on_receive(), and v_on_send().
pin map
Definition at line 420 of file aiogate.h.
Referenced by bind(), close(), connect(), doxray(), initiate_close(), off(), recv(), send_bulk(), set_recv_timeout(), set_send_timeout(), unlock_pin(), v_on_accept(), v_on_connect(), v_on_error(), v_on_receive(), and v_on_send().
aiosock port
Definition at line 421 of file aiogate.h.
Referenced by bind(), connect(), deaf(), doxray(), final_close(), listen(), off(), on(), recv(), send_bulk(), v_on_accept(), v_on_connect(), and v_on_send().
The documentation for this class was generated from the following files:
|
|