uiop_acceptor.cpp

来自「这是广泛使用的通信开源项目,对于大容量,高并发的通讯要求完全能够胜任,他广泛可用」· C++ 代码 · 共 583 行 · 第 1/2 页

CPP
583
字号
// UIOP_Acceptor.cpp,v 1.19 2003/03/12 16:13:26 parsons Exp

// ============================================================================
//
// = LIBRARY
//     TAO
//
// = FILENAME
//      UIOP_Acceptor.cpp
//
// = DESCRIPTION
//
// = AUTHOR
//     Fred Kuhns <fredk@cs.wustl.edu> and
//     Ossama Othman <othman@cs.wustl.edu>
//
// ============================================================================

#include "UIOP_Acceptor.h"

#if TAO_HAS_UIOP == 1

#include "UIOP_Profile.h"
#include "tao/MProfile.h"
#include "tao/ORB_Core.h"
#include "tao/Server_Strategy_Factory.h"
#include "tao/debug.h"
#include "tao/Protocols_Hooks.h"
#include "tao/Codeset_Manager.h"

ACE_RCSID (Strategies, 
           UIOP_Acceptor, 
           "UIOP_Acceptor.cpp,v 1.19 2003/03/12 16:13:26 parsons Exp")

#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)

template class ACE_Acceptor<TAO_UIOP_Connection_Handler, ACE_LSOCK_ACCEPTOR>;
template class ACE_Strategy_Acceptor<TAO_UIOP_Connection_Handler, ACE_LSOCK_ACCEPTOR>;
template class ACE_Accept_Strategy<TAO_UIOP_Connection_Handler, ACE_LSOCK_ACCEPTOR>;
template class ACE_Creation_Strategy<TAO_UIOP_Connection_Handler>;
template class ACE_Concurrency_Strategy<TAO_UIOP_Connection_Handler>;
template class ACE_Scheduling_Strategy<TAO_UIOP_Connection_Handler>;
template class TAO_Creation_Strategy<TAO_UIOP_Connection_Handler>;
template class TAO_Concurrency_Strategy<TAO_UIOP_Connection_Handler>;
template class TAO_Accept_Strategy<TAO_UIOP_Connection_Handler, ACE_LSOCK_ACCEPTOR>;

#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)

#pragma instantiate ACE_Acceptor<TAO_UIOP_Connection_Handler, ACE_LSOCK_ACCEPTOR>
#pragma instantiate ACE_Strategy_Acceptor<TAO_UIOP_Connection_Handler, ACE_LSOCK_ACCEPTOR>
#pragma instantiate ACE_Accept_Strategy<TAO_UIOP_Connection_Handler, ACE_LSOCK_ACCEPTOR>
#pragma instantiate ACE_Creation_Strategy<TAO_UIOP_Connection_Handler>
#pragma instantiate ACE_Concurrency_Strategy<TAO_UIOP_Connection_Handler>
#pragma instantiate ACE_Scheduling_Strategy<TAO_UIOP_Connection_Handler>
#pragma instantiate TAO_Creation_Strategy<TAO_UIOP_Connection_Handler>
#pragma instantiate TAO_Concurrency_Strategy<TAO_UIOP_Connection_Handler>
#pragma instantiate TAO_Accept_Strategy<TAO_UIOP_Connection_Handler, ACE_LSOCK_ACCEPTOR>

#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */


TAO_UIOP_Acceptor::TAO_UIOP_Acceptor (CORBA::Boolean flag)
  : TAO_Acceptor (TAO_TAG_UIOP_PROFILE),
    base_acceptor_ (),
    creation_strategy_ (0),
    concurrency_strategy_ (0),
    accept_strategy_ (0),
    version_ (TAO_DEF_GIOP_MAJOR, TAO_DEF_GIOP_MINOR),
    orb_core_ (0),
    unlink_on_close_ (1),
    lite_flag_ (flag)
{
}

TAO_UIOP_Acceptor::~TAO_UIOP_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_;
}

int
TAO_UIOP_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_UIOP_Acceptor::create_new_profile (const TAO::ObjectKey &object_key,
                                       TAO_MProfile &mprofile,
                                       CORBA::Short priority)
{
  ACE_UNIX_Addr addr;

  if (this->base_acceptor_.acceptor ().get_local_addr (addr) == -1)
    return 0;

  int count = mprofile.profile_count ();
  if ((mprofile.size () - count) < 1
      && mprofile.grow (count + 1) == -1)
    return -1;

  TAO_UIOP_Profile *pfile = 0;
  ACE_NEW_RETURN (pfile,
                  TAO_UIOP_Profile (addr,
                                    object_key,
                                    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 UIOP 1.0 endpoint is being
  // created (IIOP 1.0 did not support tagged components, so we follow
  // the same convention for UIOP).
  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_UIOP_Acceptor::create_shared_profile (const TAO::ObjectKey &object_key,
                                          TAO_MProfile &mprofile,
                                          CORBA::Short priority)
{
  TAO_Profile *pfile = 0;
  TAO_UIOP_Profile *uiop_profile = 0;

  // First see if <mprofile> already contains a UIOP profile.
  for (TAO_PHandle i = 0; i != mprofile.profile_count (); ++i)
    {
      pfile = mprofile.get_profile (i);
      if (pfile->tag () == TAO_TAG_UIOP_PROFILE)
      {
        uiop_profile = ACE_dynamic_cast (TAO_UIOP_Profile *,
                                         pfile);
        break;
      }
    }

  if (uiop_profile == 0)
    {
      // If <mprofile> doesn't contain UIOP_Profile, we need to create
      // one.
      return create_new_profile (object_key,
                                 mprofile,
                                 priority);
    }
  else
    {
      // A UIOP_Profile already exists - just add our endpoint to it.
      ACE_UNIX_Addr addr;

      if (this->base_acceptor_.acceptor ().get_local_addr (addr) == -1)
        return 0;

      TAO_UIOP_Endpoint *endpoint = 0;
      ACE_NEW_RETURN (endpoint,
                      TAO_UIOP_Endpoint (addr),
                      -1);
      endpoint->priority (priority);
      uiop_profile->add_endpoint (endpoint);

      return 0;
    }
}

int
TAO_UIOP_Acceptor::is_collocated (const TAO_Endpoint *endpoint)
{
  const TAO_UIOP_Endpoint *endp =
    ACE_dynamic_cast (const TAO_UIOP_Endpoint *, endpoint);

  // Make sure the dynamically cast pointer is valid.
  if (endp == 0)
    return 0;

  // For UNIX Files this is relatively cheap.
  ACE_UNIX_Addr address;
  if (this->base_acceptor_.acceptor ().get_local_addr (address) == -1)
    return 0;

  return endp->object_addr () == address;
}

int
TAO_UIOP_Acceptor::close (void)
{
  if (this->unlink_on_close_)
    {
      ACE_UNIX_Addr addr;

      if (this->base_acceptor_.acceptor ().get_local_addr (addr) == 0)
        (void) ACE_OS::unlink (addr.get_path_name ());

      this->unlink_on_close_ = 0;
    }

  return this->base_acceptor_.close ();
}

int
TAO_UIOP_Acceptor::open (TAO_ORB_Core *orb_core,
                         ACE_Reactor *reactor,
                         int major,
                         int minor,
                         const char *address,
                         const char *options)
{
  this->orb_core_ = orb_core;

  if (this->init_uiop_properties () != 0)
    return -1;

  if (address == 0)
    return -1;

  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;
  else
    return this->open_i (address,
                         reactor);
}

int
TAO_UIOP_Acceptor::open_default (TAO_ORB_Core *orb_core,
                                 ACE_Reactor *reactor,
                                 int major,
                                 int minor,
                                 const char *options)
{
  this->orb_core_ = orb_core;

  if (this->init_uiop_properties () != 0)
    return -1;

  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;

  ACE_Auto_String_Free tempname (ACE_OS::tempnam (0,
                                                  "TAO"));

  if (tempname.get () == 0)
    return -1;

  return this->open_i (tempname.get (),
                       reactor);
}

int
TAO_UIOP_Acceptor::open_i (const char *rendezvous,

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?