19typedef unsigned int socklen_t;
21# include <sys/socket.h>
62template<
class SERVICE_HANDLER,
class PEER_CONNECTOR>
91 virtual int close (
void);
196#define SH SERVICE_HANDLER
197#define PC PEER_CONNECTOR
203template<
class SH,
class PC>
206 : m_tid (0), m_reactor (0), m_state (idle),
213template<
class SH,
class PC>
221template<
class SH,
class PC>
int
235template<
class SH,
class PC>
int
243template<
class SH,
class PC>
int
260 m_sh = makeServiceHandler (
sh_);
274 if (
async == m_mode) {
284 return activateServiceHandler ();
301template<
class SH,
class PC>
int
315 m_fd =
s.getHandler ();
318 return (
s.connect (
addr_) ? 0 : -1);
321template<
class SH,
class PC>
int
327 return m_sh->open ();
330template<
class SH,
class PC>
void
341 m_reactor->registerIOHandler (
this, m_fd,
WRITE_EVENT);
343 m_tid = m_reactor->registerTimerHandler (
this, m_timeout,
"ASYNC Connect");
347template<
class SH,
class PC>
int
356 m_reactor->registerTimerHandler (
this, m_timeout,
"SYNC Connect");
358 m_reactor->waitForEvents (&m_timeout);
359 m_reactor->removeHandler (
this);
364 if (conned == m_state)
366 DL((
SOCKTRACE,
"Synchronous connect() succeeded.\n"));
376template<
class SH,
class PC>
int
394 if (
async == m_mode) {
395 m_reactor->removeTimerHandler (m_tid);
421#if defined(__CYGWIN32__)
432 if (activateServiceHandler () == 0) {
433 DL((
SOCKTRACE,
"Nonblocking connect() completed\n"));
458 "numbers on client and service hosts.\n"));
462 if (
async == m_mode) {
472template<
class SH,
class PC>
int
481 if (
async == m_mode) {
Address is an abstraction for INET or UNIX-domain address data type.
An abstract interface for handling I/O events, timers, and such.
An abstraction to message logging facility.
#define EL(X)
A macro for writing error message to the Logger.
#define DL(X)
A macro for writing debug message to the Logger.
#define trace_with_mask(s, m)
trace_with_mask() is used to trace function call chain in C++ program.
An implementation of Reactor pattern.
Abstraction of socket data type.
Class TimeVal is a wrapper around UNIX timeval structure.
A wrapper class to provide AutoPtr with reference semantics.
Connector is a template class for initialization of communication services.
void doAsync(void)
Setup for asynchronous mode completion.
virtual int close(void)
Do-nothing close.
virtual int connectServiceHandler(Address &addr, int protocol)
Default strategy is to make synchronous connection with no timeouts.
int m_flags
Socket flags (obsolete)
@ failed
Failed to connect.
@ waiting
Asynchronously waiting on connection completion.
TimeVal m_timeout
Timeout.
virtual int activateServiceHandler()
Activate handler by calling its open() method.
virtual int open(const TimeVal &tv_=TimeVal(5.0), ConnectMode mode_=sync, Reactor *r_=(Reactor *) NULL)
Configure Connector.
virtual int connect(SERVICE_HANDLER *sh_, Address &addr_, int protocol_=AF_INET)
Define strategy for establishing connection.
virtual int handle_write(int fd)
Handle connection completion.
virtual ~Connector()
Destructor. Do-nothing.
virtual SERVICE_HANDLER * makeServiceHandler(SERVICE_HANDLER *sh_)
Defines creation strategy for ServiceHandler.
Connector()
Constructor. Do-nothing.
ConnectMode m_mode
Mode (sync/async)
ProgressState m_state
Connection progress state.
SERVICE_HANDLER * m_sh
Reference to ServiceHandler.
virtual int handle_timeout(TimerId tid)
Handler connection timeout.
int doSync(void)
Synchronous mode completion.
int m_fd
Socket file descriptor.
Reactor * m_reactor
Reference to Reactor (for async)
void set_id(const std::string &id_)
Set EventHandler ID.
bool registerIOHandler(EventHandler *eh_, handler_t fd_, EventType et_=RWE_EVENTS)
Register I/O Event handler with Reactor.
@ nonblocking
Set Socket to a non-blocking mode (O_RDWR|O_NONBLOCK).
@ WRITE_EVENT
Notify when there will be room for at least 1 byte to be written to IO channel without blocking.
void set_errno(int new_errno_)
Set error number in a portable way.
unsigned long TimerId
Timer Id is used in handle_timeout() calls.
@ SOCKTRACE
Extended Socket & friends messages
@ ASSAERR
ASSA and system errors
int get_errno()
Fetch error number in a portable way.
@ sync
Synchronous connection mode.
@ async
Asynchronous connection mode.