19 typedef unsigned int socklen_t;
21 # include <sys/socket.h> 62 template<
class SERVICE_HANDLER,
class PEER_CONNECTOR>
91 virtual int close (
void);
117 virtual int connect (SERVICE_HANDLER* sh_,
119 int protocol_ = AF_INET);
196 #define SH SERVICE_HANDLER 197 #define PC PEER_CONNECTOR 203 template<
class SH,
class PC>
213 template<
class SH,
class PC>
221 template<
class SH,
class PC>
int 235 template<
class SH,
class PC>
int 243 template<
class SH,
class PC>
int 261 PEER_CONNECTOR& s = *
m_sh;
272 if (e == EINPROGRESS || e == EWOULDBLOCK)
287 template<
class SH,
class PC> SERVICE_HANDLER*
293 SERVICE_HANDLER* new_sh = sh_;
296 new_sh =
new SERVICE_HANDLER;
301 template<
class SH,
class PC>
int 307 PEER_CONNECTOR& s = *
m_sh;
309 if ( !s.open (protocol_family_) ) {
315 m_fd = s.getHandler ();
318 return (s.connect (addr_) ? 0 : -1);
321 template<
class SH,
class PC>
int 327 return m_sh->open ();
330 template<
class SH,
class PC>
void 347 template<
class SH,
class PC>
int 366 DL((
SOCKTRACE,
"Synchronous connect() succeeded.\n"));
376 template<
class SH,
class PC>
int 414 error = ret = errno = 0;
415 socklen_t n =
sizeof (error);
421 #if defined(__CYGWIN32__) 422 ret = getsockopt (
m_fd, SOL_SOCKET, SO_ERROR, (
void*)&error, (
int*)&n);
423 #elif defined (WIN32) 424 ret = getsockopt (
m_fd, SOL_SOCKET, SO_ERROR, (
char*)&error, (
int*)&n);
426 ret = getsockopt (
m_fd, SOL_SOCKET, SO_ERROR, (
void*)&error, &n);
433 DL((
SOCKTRACE,
"Nonblocking connect() completed\n"));
458 "numbers on client and service hosts.\n"));
472 template<
class SH,
class PC>
int
Connector is a template class for initialization of communication services.
void set_id(const std::string &id_)
Set EventHandler ID.
virtual int close(void)
Do-nothing close.
bool registerIOHandler(EventHandler *eh_, handler_t fd_, EventType et_=RWE_EVENTS)
Register I/O Event handler with Reactor.
ProgressState m_state
Connection progress state.
TimeVal m_timeout
Timeout.
virtual int connect(SERVICE_HANDLER *sh_, Address &addr_, int protocol_=AF_INET)
Define strategy for establishing connection.
Connector()
Constructor. Do-nothing.
int doSync(void)
Synchronous mode completion.
virtual int handle_write(int fd)
Handle connection completion.
SERVICE_HANDLER * m_sh
Reference to ServiceHandler.
Asynchronously waiting on connection completion.
Class TimeVal is a wrapper around UNIX timeval structure.
bool bad() const
Indicates whether there was error during address construction process i.e.
bool removeHandler(EventHandler *eh_, EventType et_=ALL_EVENTS)
Remove Event handler from reactor for either all I/O events or timeout event or both.
bool removeTimerHandler(TimerId id_)
Remove Timer event from the queue.
Asynchronous connection mode.
virtual SERVICE_HANDLER * makeServiceHandler(SERVICE_HANDLER *sh_)
Defines creation strategy for ServiceHandler.
#define DL(X)
A macro for writing debug message to the Logger.
void set_errno(int new_errno_)
Set error number in a portable way.
#define trace_with_mask(s, m)
trace_with_mask() is used to trace function call chain in C++ program.
Synchronous connection mode.
int m_flags
Socket flags (obsolete)
#define EL(X)
A macro for writing error message to the Logger.
Reactor * m_reactor
Reference to Reactor (for async)
Set Socket to a non-blocking mode (O_RDWR|O_NONBLOCK).
virtual ~Connector()
Destructor. Do-nothing.
Notify when there will be room for at least 1 byte to be written to IO channel without blocking...
An abstract interface for handling I/O events, timers, and such.
int get_errno()
Fetch error number in a portable way.
Address is an abstraction for INET or UNIX-domain address data type.
An abstraction to message logging facility.
An implementation of Reactor pattern.
void waitForEvents(void)
Main waiting loop that blocks indefinitely processing events.
virtual int connectServiceHandler(Address &addr, int protocol)
Default strategy is to make synchronous connection with no timeouts.
virtual int activateServiceHandler()
Activate handler by calling its open() method.
unsigned long TimerId
Timer Id is used in handle_timeout() calls.
TimerId registerTimerHandler(EventHandler *eh_, const TimeVal &tv_, const std::string &name_="<unknown>")
Register Timer Event handler with Reactor.
int m_fd
Socket file descriptor.
ConnectMode m_mode
Mode (sync/async)
void doAsync(void)
Setup for asynchronous mode completion.
Abstraction of socket data type.
virtual int handle_timeout(TimerId tid)
Handler connection timeout.
virtual int open(const TimeVal &tv_=TimeVal(5.0), ConnectMode mode_=sync, Reactor *r_=(Reactor *) NULL)
Configure Connector.
Extended Socket & friends messages.