sciop_connector.cpp
来自「这是广泛使用的通信开源项目,对于大容量,高并发的通讯要求完全能够胜任,他广泛可用」· C++ 代码 · 共 526 行 · 第 1/2 页
CPP
526 行
svc_handler->is_closed ();
// In case of failures and close() has not be called.
if (result == -1 &&
!closed)
{
// First, cancel from connector.
this->base_connector_.cancel (svc_handler);
// Double check to make sure the handler has not been closed
// yet. This double check is required to ensure that the
// connection handler was not closed yet by some other
// thread since it was still registered with the connector.
// Once connector.cancel() has been processed, we are
// assured that the connector will no longer open/close this
// handler.
closed =
svc_handler->is_closed ();
// If closed, there is nothing to do here. If not closed,
// it was either opened or is still pending.
if (!closed)
{
// Check if the handler has been opened.
int open =
svc_handler->is_open ();
// Some other thread was able to open the handler even
// though wait failed for this thread.
if (open)
// Overwrite <result>.
result = 0;
else
{
// Assert that it is still connecting.
ACE_ASSERT (svc_handler->is_connecting ());
// Force close the handler now.
svc_handler->close ();
}
}
}
}
// Irrespective of success or failure, remove the extra #REFCOUNT#.
svc_handler->remove_reference ();
// In case of errors.
if (result == -1)
{
// Give users a clue to the problem.
if (TAO_debug_level)
{
ACE_DEBUG ((LM_ERROR,
"TAO (%P|%t) - SCIOP_Connector::make_connection, "
"connection to <%s:%d> failed (%p)\n",
sciop_endpoint->host (), sciop_endpoint->port (),
"errno"));
}
return 0;
}
// At this point, the connection has be successfully connected.
// #REFCOUNT# is one.
if (TAO_debug_level > 2)
ACE_DEBUG ((LM_DEBUG,
"TAO (%P|%t) - SCIOP_Connector::make_connection, "
"new connection to <%s:%d> on Transport[%d]\n",
sciop_endpoint->host (), sciop_endpoint->port (),
svc_handler->peer ().get_handle ()));
TAO_Transport *transport =
svc_handler->transport ();
// Add the handler to Cache
int retval =
this->orb_core ()->lane_resources ().transport_cache ().cache_transport (&desc,
transport);
// Failure in adding to cache.
if (retval != 0)
{
// Close the handler.
svc_handler->close ();
if (TAO_debug_level > 0)
{
ACE_ERROR ((LM_ERROR,
"TAO (%P|%t) - SCIOP_Connector::make_connection, "
"could not add the new connection to cache\n"));
}
return 0;
}
// Registration failures.
if (retval != 0)
{
// Purge from the connection cache.
transport->purge_entry ();
// Close the handler.
svc_handler->close ();
if (TAO_debug_level > 0)
{
ACE_ERROR ((LM_ERROR,
"TAO (%P|%t) - SCIOP_Connector::make_connection, "
"could not register the new connection in the reactor\n"));
}
return 0;
}
return transport;
}
TAO_Profile *
TAO_SCIOP_Connector::create_profile (TAO_InputCDR& cdr)
{
TAO_Profile *pfile;
ACE_NEW_RETURN (pfile,
TAO_SCIOP_Profile (this->orb_core ()),
0);
int r = pfile->decode (cdr);
if (r == -1)
{
pfile->_decr_refcnt ();
pfile = 0;
}
return pfile;
}
TAO_Profile *
TAO_SCIOP_Connector::make_profile (ACE_ENV_SINGLE_ARG_DECL)
{
// The endpoint should be of the form:
// N.n@host:port/object_key
// or:
// host:port/object_key
TAO_Profile *profile = 0;
ACE_NEW_THROW_EX (profile,
TAO_SCIOP_Profile (this->orb_core ()),
CORBA::NO_MEMORY (
CORBA::SystemException::_tao_minor_code (
TAO_DEFAULT_MINOR_CODE,
ENOMEM),
CORBA::COMPLETED_NO));
ACE_CHECK_RETURN (0);
return profile;
}
int
TAO_SCIOP_Connector::check_prefix (const char *endpoint)
{
// Check for a valid string
if (!endpoint || !*endpoint)
return -1; // Failure
const char *protocol[] = { "sciop", "scioploc" };
size_t slot = ACE_OS::strchr (endpoint, ':') - endpoint;
size_t len0 = ACE_OS::strlen (protocol[0]);
size_t len1 = ACE_OS::strlen (protocol[1]);
// Check for the proper prefix in the IOR. If the proper prefix
// isn't in the IOR then it is not an IOR we can use.
if (slot == len0
&& ACE_OS::strncasecmp (endpoint, protocol[0], len0) == 0)
return 0;
else if (slot == len1
&& ACE_OS::strncasecmp (endpoint, protocol[1], len1) == 0)
return 0;
return -1;
// Failure: not an SCIOP IOR
// DO NOT throw an exception here.
}
char
TAO_SCIOP_Connector::object_key_delimiter (void) const
{
return TAO_SCIOP_Profile::object_key_delimiter_;
}
int
TAO_SCIOP_Connector::init_tcp_properties (void)
{
// Connector protocol properties are obtained from ORB-level
// RTCORBA::ClientProtocolProperties policy override.
// If the override doesn't exist or doesn't contain the
// properties, we use ORB default.
//
// Currently, we do not use Object-level and Current-level policy
// overrides for protocol configuration because connection
// lookup and caching are not done based on protocol
// properties.
ACE_DECLARE_NEW_CORBA_ENV;
// Initialize the settings to the ORB defaults. If RT CORBA is enabled,
// it may override these.
int send_buffer_size = this->orb_core ()->orb_params ()->sock_sndbuf_size ();
int recv_buffer_size = this->orb_core ()->orb_params ()->sock_rcvbuf_size ();
int no_delay = this->orb_core ()->orb_params ()->nodelay ();
int enable_network_priority = 0;
TAO_Protocols_Hooks *tph = this->orb_core ()->get_protocols_hooks (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK_RETURN (-1);
if (tph != 0)
{
const char protocol [] = "sciop";
const char *protocol_type = protocol;
int hook_result =
tph->call_client_protocols_hook (send_buffer_size,
recv_buffer_size,
no_delay,
enable_network_priority,
protocol_type);
if(hook_result == -1)
return -1;
}
// Extract and locally store properties of interest.
this->tcp_properties_.send_buffer_size =
send_buffer_size;
this->tcp_properties_.recv_buffer_size =
recv_buffer_size;
this->tcp_properties_.no_delay =
no_delay;
this->tcp_properties_.enable_network_priority =
enable_network_priority;
return 0;
}
TAO_SCIOP_Endpoint *
TAO_SCIOP_Connector::remote_endpoint (TAO_Endpoint *endpoint)
{
if (endpoint->tag () != TAO_TAG_SCIOP_PROFILE)
return 0;
TAO_SCIOP_Endpoint *sciop_endpoint =
ACE_dynamic_cast (TAO_SCIOP_Endpoint *,
endpoint );
if (sciop_endpoint == 0)
return 0;
return sciop_endpoint;
}
#endif /* TAO_HAS_SCIOP == 1 */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?