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>
206 : m_tid (0), m_reactor (0), m_state (idle),
207 m_flags (0), m_sh ((SERVICE_HANDLER*)NULL), m_fd (-1), m_mode (
sync)
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
260 m_sh = makeServiceHandler (sh_);
261 PEER_CONNECTOR& s = *m_sh;
269 if (connectServiceHandler (addr_, protocol_family_) == -1)
272 if (e == EINPROGRESS || e == EWOULDBLOCK)
274 if (
async == m_mode) {
284 return activateServiceHandler ();
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
341 m_reactor->registerIOHandler (
this, m_fd,
WRITE_EVENT);
343 m_tid = m_reactor->registerTimerHandler (
this, m_timeout,
"ASYNC Connect");
347 template<
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"));
376 template<
class SH,
class PC>
int
394 if (
async == m_mode) {
395 m_reactor->removeTimerHandler (m_tid);
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);
432 if (activateServiceHandler () == 0) {
433 DL((
SOCKTRACE,
"Nonblocking connect() completed\n"));
458 "numbers on client and service hosts.\n"));
462 if (
async == m_mode) {
472 template<
class SH,
class PC>
int
481 if (
async == m_mode) {