libassa
3.5.1
|
Connector is a template class for initialization of communication services. More...
#include <Connector.h>
Public Member Functions | |
Connector () | |
Constructor. Do-nothing. More... | |
virtual | ~Connector () |
Destructor. Do-nothing. More... | |
virtual int | open (const TimeVal &tv_=TimeVal(5.0), ConnectMode mode_=sync, Reactor *r_=(Reactor *) NULL) |
Configure Connector. More... | |
virtual int | close (void) |
Do-nothing close. More... | |
virtual int | connect (SERVICE_HANDLER *sh_, Address &addr_, int protocol_=AF_INET) |
Define strategy for establishing connection. More... | |
virtual int | handle_write (int fd) |
Handle connection completion. More... | |
virtual int | handle_timeout (TimerId tid) |
Handler connection timeout. More... | |
![]() | |
EventHandler () | |
Constructor. More... | |
virtual | ~EventHandler () |
Virtual destructor. More... | |
virtual int | handle_read (int fd) |
Read event callback. More... | |
virtual int | handle_except (int fd) |
Exception handler callback. More... | |
virtual int | handle_signal (int signum_) |
Signal handler callback. More... | |
virtual int | handle_close (int fd) |
EOF on peer socket handler callback. More... | |
virtual void | resetState (void) |
A hook for derived class to reset internal state as needed. More... | |
void | set_id (const std::string &id_) |
Set EventHandler ID. More... | |
std::string | get_id () const |
Retrieve EventHandler ID. More... | |
Protected Types | |
enum | ProgressState { idle , waiting , conned , failed } |
state. More... | |
Protected Member Functions | |
virtual SERVICE_HANDLER * | makeServiceHandler (SERVICE_HANDLER *sh_) |
Defines creation strategy for ServiceHandler. More... | |
virtual int | connectServiceHandler (Address &addr, int protocol) |
Default strategy is to make synchronous connection with no timeouts. More... | |
virtual int | activateServiceHandler () |
Activate handler by calling its open() method. More... | |
Protected Attributes | |
TimeVal | m_timeout |
Timeout. More... | |
TimerId | m_tid |
Timer id. More... | |
Reactor * | m_reactor |
Reference to Reactor (for async) More... | |
ProgressState | m_state |
Connection progress state. More... | |
int | m_flags |
Socket flags (obsolete) More... | |
SERVICE_HANDLER * | m_sh |
Reference to ServiceHandler. More... | |
int | m_fd |
Socket file descriptor. More... | |
ConnectMode | m_mode |
Mode (sync/async) More... | |
![]() | |
std::string | m_id |
Private Member Functions | |
void | doAsync (void) |
Setup for asynchronous mode completion. More... | |
int | doSync (void) |
Synchronous mode completion. More... | |
Connector is a template class for initialization of communication services.
This template class implements the generic strategy for actively
initializing communication services.
SERVICE_HANDLER is the type of service. It shall be a type derived from ServiceHandler interface class.
PEER_CONNECTOR is the type of concrete Socket class - particular transport mechanism used by the Connector to actively establish the connection. It should be derived from Socket interface class.
Definition at line 63 of file Connector.h.
|
protected |
state.
Connection state.
Enumerator | |
---|---|
idle | Initialized.
|
waiting | Asynchronously waiting on connection completion.
|
conned | Connected.
|
failed | Failed to connect.
|
Definition at line 131 of file Connector.h.
ASSA::Connector< SERVICE_HANDLER, PEER_CONNECTOR >::Connector |
Constructor. Do-nothing.
Definition at line 204 of file Connector.h.
References ASSA::EventHandler::set_id(), ASSA::SOCKTRACE, and trace_with_mask.
|
virtual |
Destructor. Do-nothing.
Definition at line 214 of file Connector.h.
References ASSA::SOCKTRACE, and trace_with_mask.
|
protectedvirtual |
Activate handler by calling its open() method.
Definition at line 322 of file Connector.h.
References ASSA::SOCKTRACE, and trace_with_mask.
|
virtual |
Do-nothing close.
Derive classes can change this strategy by overloading this method.
Definition at line 236 of file Connector.h.
References ASSA::SOCKTRACE, and trace_with_mask.
|
virtual |
Define strategy for establishing connection.
Default is to connect synchronously to the remote peer. In sync mode connection either will be established or failed when returned from Connector::connect() call.
In async mode, call to Connector::connect() returns immediately reporting only immediate error. Later on connection is completed asynchronously.
Default timeout on connection waiting is 10 seconds. Timeout can be configured by passing TimeVal parameter to the Connector::open() member function.
If connetion failed, caller should definitely close PEER_CONNECTOR communication point.
sh_ | Pointer to class object derived from ServiceHandler. |
addr_ | Reference to the address to connect to. |
protocol_ | AF_INET for internet socket, AF_UNIX for the UNIX Domain socket (defaults to AF_INET). |
Definition at line 244 of file Connector.h.
References ASSA::ASSAERR, ASSA::async, ASSA::Address::bad(), EL, ASSA::get_errno(), ASSA::set_errno(), ASSA::SOCKTRACE, and trace_with_mask.
Referenced by ASSA::Logger::log_open().
|
protectedvirtual |
Default strategy is to make synchronous connection with no timeouts.
Derived class can change this strategy by overloading this method.
Definition at line 302 of file Connector.h.
References ASSA::ASSAERR, EL, ASSA::Socket::nonblocking, ASSA::SOCKTRACE, and trace_with_mask.
|
private |
Setup for asynchronous mode completion.
Definition at line 331 of file Connector.h.
References ASSA::SOCKTRACE, trace_with_mask, and ASSA::WRITE_EVENT.
|
private |
Synchronous mode completion.
Definition at line 348 of file Connector.h.
References ASSA::ASSAERR, DL, EL, ASSA::Reactor::registerIOHandler(), ASSA::set_errno(), ASSA::SOCKTRACE, trace_with_mask, and ASSA::WRITE_EVENT.
|
virtual |
Handler connection timeout.
Reimplemented from ASSA::EventHandler.
Definition at line 473 of file Connector.h.
References ASSA::async, ASSA::set_errno(), ASSA::SOCKTRACE, trace_with_mask, and ASSA::WRITE_EVENT.
|
virtual |
Handle connection completion.
Always remove IO handler first.
Reimplemented from ASSA::EventHandler.
Definition at line 377 of file Connector.h.
References ASSA::ASSAERR, ASSA::async, DL, EL, ASSA::get_errno(), ASSA::set_errno(), ASSA::SOCKTRACE, trace_with_mask, and ASSA::WRITE_EVENT.
|
protectedvirtual |
Defines creation strategy for ServiceHandler.
Default is to dynamically allocate new SERVICE_HANDLER, if one is not given as an argument.
sh_ | pointer to SERVICE_HANDLER, or NULL, if it is expected to be created here |
Definition at line 288 of file Connector.h.
References ASSA::SOCKTRACE, and trace_with_mask.
|
virtual |
Configure Connector.
Timeout will be used to timeout connection operation. If mode_ is async, then Reactor r_ ought to be specified for handling asynchronous event processing. Derive classes can change this strategy by overloading this method.
tv_ | Time for connection timeout (Default = 5.0 secs.) |
mode_ | Synchronous or Asynchronous mode. |
r_ | Reactor to work with (for async mode). |
Definition at line 222 of file Connector.h.
References ASSA::async, ASSA::SOCKTRACE, and trace_with_mask.
Referenced by ASSA::Logger::log_open().
|
protected |
Socket file descriptor.
Definition at line 179 of file Connector.h.
|
protected |
Socket flags (obsolete)
Definition at line 173 of file Connector.h.
|
protected |
Mode (sync/async)
Definition at line 182 of file Connector.h.
|
protected |
Reference to Reactor (for async)
Definition at line 167 of file Connector.h.
|
protected |
Reference to ServiceHandler.
Definition at line 176 of file Connector.h.
|
protected |
Connection progress state.
Definition at line 170 of file Connector.h.
|
protected |
Timer id.
Definition at line 164 of file Connector.h.
|
protected |
Timeout.
Definition at line 161 of file Connector.h.