shmiop_acceptor.cpp
来自「这是广泛使用的通信开源项目,对于大容量,高并发的通讯要求完全能够胜任,他广泛可用」· C++ 代码 · 共 521 行 · 第 1/2 页
CPP
521 行
// This may look like C, but it's really -*- C++ -*-
// SHMIOP_Acceptor.cpp,v 1.21 2003/11/03 03:05:25 dhinton Exp
#include "SHMIOP_Acceptor.h"
#if defined (TAO_HAS_SHMIOP) && (TAO_HAS_SHMIOP != 0)
#include "SHMIOP_Profile.h"
#include "tao/MProfile.h"
#include "tao/ORB_Core.h"
#include "tao/Server_Strategy_Factory.h"
#include "tao/debug.h"
#include "tao/Codeset_Manager.h"
#if !defined(__ACE_INLINE__)
#include "SHMIOP_Acceptor.i"
#endif /* __ACE_INLINE__ */
#include "ace/os_include/os_netdb.h"
ACE_RCSID (Strategies,
SHMIOP_Acceptor,
"SHMIOP_Acceptor.cpp,v 1.21 2003/11/03 03:05:25 dhinton Exp")
#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)
template class ACE_Acceptor<TAO_SHMIOP_Connection_Handler, ACE_MEM_ACCEPTOR>;
template class ACE_Strategy_Acceptor<TAO_SHMIOP_Connection_Handler, ACE_MEM_ACCEPTOR>;
template class ACE_Accept_Strategy<TAO_SHMIOP_Connection_Handler, ACE_MEM_ACCEPTOR>;
template class ACE_Creation_Strategy<TAO_SHMIOP_Connection_Handler>;
template class ACE_Concurrency_Strategy<TAO_SHMIOP_Connection_Handler>;
template class ACE_Scheduling_Strategy<TAO_SHMIOP_Connection_Handler>;
template class TAO_Creation_Strategy<TAO_SHMIOP_Connection_Handler>;
template class TAO_Concurrency_Strategy<TAO_SHMIOP_Connection_Handler>;
template class TAO_Accept_Strategy<TAO_SHMIOP_Connection_Handler, ACE_MEM_ACCEPTOR>;
#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)
#pragma instantiate ACE_Acceptor<TAO_SHMIOP_Connection_Handler, ACE_MEM_ACCEPTOR>
#pragma instantiate ACE_Strategy_Acceptor<TAO_SHMIOP_Connection_Handler, ACE_MEM_ACCEPTOR>
#pragma instantiate ACE_Accept_Strategy<TAO_SHMIOP_Connection_Handler, ACE_MEM_ACCEPTOR>
#pragma instantiate ACE_Creation_Strategy<TAO_SHMIOP_Connection_Handler>
#pragma instantiate ACE_Concurrency_Strategy<TAO_SHMIOP_Connection_Handler>
#pragma instantiate ACE_Scheduling_Strategy<TAO_SHMIOP_Connection_Handler>
#pragma instantiate TAO_Creation_Strategy<TAO_SHMIOP_Connection_Handler>
#pragma instantiate TAO_Concurrency_Strategy<TAO_SHMIOP_Connection_Handler>
#pragma instantiate TAO_Accept_Strategy<TAO_SHMIOP_Connection_Handler, ACE_MEM_ACCEPTOR>
#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */
TAO_SHMIOP_Acceptor::TAO_SHMIOP_Acceptor (CORBA::Boolean flag)
: TAO_Acceptor (TAO_TAG_SHMEM_PROFILE),
version_ (TAO_DEF_GIOP_MAJOR, TAO_DEF_GIOP_MINOR),
orb_core_ (0),
base_acceptor_ (),
creation_strategy_ (0),
concurrency_strategy_ (0),
accept_strategy_ (0),
mmap_file_prefix_ (0),
mmap_size_ (1024 * 1024),
lite_flag_ (flag)
{
}
TAO_SHMIOP_Acceptor::~TAO_SHMIOP_Acceptor (void)
{
// Make sure we are closed before we start destroying the
// strategies.
this->close ();
delete this->creation_strategy_;
delete this->concurrency_strategy_;
delete this->accept_strategy_;
}
// TODO =
// 2) For V1.[1,2] there are tagged components
// 3) Create multiple profiles for wild carded endpoints (may be multiple
// interfaces over which we can receive requests. Thus a profile
// must be made for each one.
int
TAO_SHMIOP_Acceptor::create_profile (const TAO::ObjectKey &object_key,
TAO_MProfile &mprofile,
CORBA::Short priority)
{
// Check if multiple endpoints should be put in one profile or
// if they should be spread across multiple profiles.
if (priority == TAO_INVALID_PRIORITY)
return this->create_new_profile (object_key,
mprofile,
priority);
else
return this->create_shared_profile (object_key,
mprofile,
priority);
}
int
TAO_SHMIOP_Acceptor::create_new_profile (const TAO::ObjectKey &object_key,
TAO_MProfile &mprofile,
CORBA::Short priority)
{
// @@ we only make one for now
int count = mprofile.profile_count ();
if ((mprofile.size () - count) < 1
&& mprofile.grow (count + 1) == -1)
return -1;
TAO_SHMIOP_Profile *pfile = 0;
ACE_NEW_RETURN (pfile,
TAO_SHMIOP_Profile (this->host_.c_str (),
this->address_.get_port_number (),
object_key,
this->address_.get_remote_addr (),
this->version_,
this->orb_core_),
-1);
pfile->endpoint ()->priority (priority);
if (mprofile.give_profile (pfile) == -1)
{
pfile->_decr_refcnt ();
pfile = 0;
return -1;
}
// Do not add any tagged components to the profile if configured
// by the user not to do so, or if an SHMIOP 1.0 endpoint is being
// created (IIOP 1.0 did not support tagged components, so we follow
// the same convention for SHMIOP).
if (this->orb_core_->orb_params ()->std_profile_components () == 0
|| (this->version_.major == 1 && this->version_.minor == 0))
return 0;
pfile->tagged_components ().set_orb_type (TAO_ORB_TYPE);
this->orb_core_->codeset_manager()->
set_codeset(pfile->tagged_components());
return 0;
}
int
TAO_SHMIOP_Acceptor::create_shared_profile (const TAO::ObjectKey &object_key,
TAO_MProfile &mprofile,
CORBA::Short priority)
{
TAO_Profile *pfile = 0;
TAO_SHMIOP_Profile *shmiop_profile = 0;
// First see if <mprofile> already contains a SHMIOP profile.
for (TAO_PHandle i = 0; i != mprofile.profile_count (); ++i)
{
pfile = mprofile.get_profile (i);
if (pfile->tag () == TAO_TAG_SHMEM_PROFILE)
{
shmiop_profile = ACE_dynamic_cast (TAO_SHMIOP_Profile *,
pfile);
break;
}
}
if (shmiop_profile == 0)
{
// If <mprofile> doesn't contain SHMIOP_Profile, we need to create
// one.
return create_new_profile (object_key,
mprofile,
priority);
}
else
{
// A SHMIOP_Profile already exists - just add our endpoint to it.
TAO_SHMIOP_Endpoint *endpoint = 0;
ACE_NEW_RETURN (endpoint,
TAO_SHMIOP_Endpoint (this->host_.c_str (),
this->address_.get_port_number (),
this->address_.get_remote_addr ()),
-1);
endpoint->priority (priority);
shmiop_profile->add_endpoint (endpoint);
return 0;
}
}
int
TAO_SHMIOP_Acceptor::is_collocated (const TAO_Endpoint *endpoint)
{
const TAO_SHMIOP_Endpoint *endp =
ACE_dynamic_cast(const TAO_SHMIOP_Endpoint *, endpoint);
// Make sure the dynamically cast pointer is valid.
if (endp == 0)
return 0;
// @@ TODO The following code looks funky, why only the host
// name is compared? What if there are multiple SHMIOP
// servers in the same address? Why do SHMIOP_Endpoints keep
// a INET_Addr but not a MEM_Addr? And why is there no lazy
// evaluation of IP-addresses for SHMIOP endpoints? Is it
// because it is always 'localhost'? We need answers to
// these questions to solve:
//
// http://deuce.doc.wustl.edu/bugzilla/show_bug.cgi?id=1220
//
// The following code is suspec
// compare the port and sin_addr (numeric host address)
return this->address_.same_host (endp->object_addr ());
}
int
TAO_SHMIOP_Acceptor::close (void)
{
return this->base_acceptor_.close ();
}
int
TAO_SHMIOP_Acceptor::open (TAO_ORB_Core *orb_core,
ACE_Reactor *reactor,
int major,
int minor,
const char *port,
const char *options)
{
if (major >=0 && minor >= 0)
this->version_.set_version (ACE_static_cast (CORBA::Octet,
major),
ACE_static_cast (CORBA::Octet,
minor));
// Parse options
if (this->parse_options (options) == -1)
return -1;
if (isdigit (*port) == 0)
return -1; // Port number must consist of digits
if (port)
this->address_.set (ACE_TEXT_CHAR_TO_TCHAR(port));
return this->open_i (orb_core,
reactor);
}
int
TAO_SHMIOP_Acceptor::open_default (TAO_ORB_Core *orb_core,
ACE_Reactor *reactor,
int major,
int minor,
const char *options)
{
if (major >=0 && minor >= 0)
this->version_.set_version (ACE_static_cast (CORBA::Octet,
major),
ACE_static_cast (CORBA::Octet,
minor));
// Parse options
if (this->parse_options (options) == -1)
return -1;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?