69 lines
2.2 KiB
C++
69 lines
2.2 KiB
C++
///----------------------------------------------------------------------------
|
|
//
|
|
// Copyright (C) Intel Corporation, 2006 - 2007.
|
|
//
|
|
// File: connector.cpp
|
|
//
|
|
// Contents: Connector that handles connection to peers
|
|
//
|
|
// Notes:
|
|
//----------------------------------------------------------------------------
|
|
|
|
#include "connector.h"
|
|
#include <ace/os_include/os_netdb.h>
|
|
#include "global.h"
|
|
#include "SOCKSv5.h"
|
|
|
|
Connection_Handler_Connector::Connection_Handler_Connector (void)
|
|
{
|
|
}
|
|
|
|
//-------------------------------------------------------
|
|
// Initiate (or reinitiate) a connection on the
|
|
// Connection_Handler.
|
|
//-------------------------------------------------------
|
|
int
|
|
Connection_Handler_Connector::initiate_connection (Tcp_Svc_Handler *connection_handler,
|
|
ACE_Synch_Options &synch_options)
|
|
{
|
|
ACE_TCHAR addr_buf[MAX_HOST_NAME_LEN];
|
|
|
|
// Mark ourselves as idle so that the various iterators will ignore
|
|
// us until we are reconnected.
|
|
connection_handler->state (Tcp_Svc_Handler::IDLE);
|
|
|
|
// We check the remote addr second so that it remains in the
|
|
// addr_buf.
|
|
if (connection_handler->local_addr ().addr_to_string (addr_buf, sizeof addr_buf) == -1
|
|
|| connection_handler->remote_addr ().addr_to_string (addr_buf, sizeof addr_buf) == -1)
|
|
ACE_ERROR_RETURN ((MY_ERROR ACE_TEXT ("can't obtain peer's address\n")), -1);
|
|
|
|
// Try to connect to the Peer.
|
|
if (this->connect (connection_handler,
|
|
connection_handler->remote_addr (),
|
|
synch_options) == -1)
|
|
{
|
|
if (errno != EWOULDBLOCK)
|
|
{
|
|
ACE_DEBUG ((MY_DEBUG ACE_TEXT("connect on address %s FAILED\n"), addr_buf));
|
|
|
|
ACE_DEBUG((MY_INFO ACE_TEXT("increasing counter=%x before reducing it later.\n"),MAX_TCP_COUNTER));
|
|
TCP_COUNTER.IncrementCheckMax();
|
|
return -1;
|
|
}
|
|
else
|
|
{
|
|
ACE_DEBUG ((MY_DEBUG
|
|
ACE_TEXT (" in the process of connecting to %s\n"), addr_buf));
|
|
}
|
|
}
|
|
else
|
|
{
|
|
ACE_DEBUG ((MY_DEBUG
|
|
ACE_TEXT ("connected to %s on %d\n"),
|
|
addr_buf, connection_handler->get_handle ()));
|
|
}
|
|
return 0;
|
|
}
|
|
|