当前位置: 首页>>代码示例>>C++>>正文


C++ ACE_ERROR函数代码示例

本文整理汇总了C++中ACE_ERROR函数的典型用法代码示例。如果您正苦于以下问题:C++ ACE_ERROR函数的具体用法?C++ ACE_ERROR怎么用?C++ ACE_ERROR使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了ACE_ERROR函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: ACE_NEW_RETURN

int
Peer_Handler::transmit_stdin (void)
{
  // If return value is -1, then first_time_ must be reset to 1.
  int result = 0;
  if (this->connection_id_ != -1)
    {
      ACE_Message_Block *mb = 0;

      ACE_NEW_RETURN (mb,
                      ACE_Message_Block (sizeof (Event)),
                      -1);

      // Cast the message block payload into an <Event> pointer.
      Event *event = (Event *) mb->rd_ptr ();

      ssize_t n = ACE_OS::read (ACE_STDIN,
                                event->data_,
                                sizeof event->data_);
      switch (n)
        {
        case 0:
          ACE_DEBUG ((LM_DEBUG,
                      ACE_TEXT ("stdin closing down\n")));

          // Take stdin out of the ACE_Reactor so we stop trying to
          // send events.
          ACE_Reactor::instance ()->remove_handler
            (ACE_STDIN,
             ACE_Event_Handler::DONT_CALL | ACE_Event_Handler::READ_MASK);
          mb->release ();
          result = 0; //
          break;
          /* NOTREACHED */
        case -1:
          mb->release ();
          ACE_ERROR ((LM_ERROR,
                      ACE_TEXT ("%p\n"),
                      ACE_TEXT ("read")));
          result = 0; //
          break;
          /* NOTREACHED */
        default:
          // Do not return directly, save the return value.
          result = this->transmit (mb, n, ROUTING_EVENT);
          break;
          /* NOTREACHED */
        }

      // Do not return at here, but at exit of function.
      /*return 0;*/
    }
  else
  {
  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("Must transmit over an opened channel.\n")));
    result = -1; // Save return value at here, return at exit of function.
  }
  // If transmit error, the stdin-thread will be cancelled, so should
  // reset first_time_ to 1, which will register_stdin_handler again.
  if (result == -1)
    first_time_ = 1;

  return result;
}
开发者ID:asdlei00,项目名称:ACE,代码行数:65,代码来源:Peer.cpp

示例2: defined

template <class HANDLER> void
ACE_Asynch_Connector<HANDLER>::parse_address (const ACE_Asynch_Connect::Result &result,
                                              ACE_INET_Addr &remote_address,
                                              ACE_INET_Addr &local_address)
{
#if defined (ACE_HAS_IPV6)
  // Getting the addresses.
  sockaddr_in6 local_addr;
  sockaddr_in6 remote_addr;
#else
  // Getting the addresses.
  sockaddr_in local_addr;
  sockaddr_in remote_addr;
#endif /* ACE_HAS_IPV6 */

  // Get the length.
  int local_size = sizeof (local_addr);
  int remote_size = sizeof (remote_addr);

  // Get the local address.
  if (ACE_OS::getsockname (result.connect_handle (),
                           reinterpret_cast<sockaddr *> (&local_addr),
                           &local_size) < 0)
    ACE_ERROR ((LM_ERROR,
                ACE_TEXT("%p\n"),
                ACE_TEXT("ACE_Asynch_Connector::<getsockname> failed")));

  // Get the remote address.
  if (ACE_OS::getpeername (result.connect_handle (),
                           reinterpret_cast<sockaddr *> (&remote_addr),
                           &remote_size) < 0)
    ACE_ERROR ((LM_ERROR,
                ACE_TEXT("%p\n"),
                ACE_TEXT("ACE_Asynch_Connector::<getpeername> failed")));

  // Set the addresses.
  local_address.set  (reinterpret_cast<sockaddr_in *> (&local_addr),
                      local_size);
  remote_address.set (reinterpret_cast<sockaddr_in *> (&remote_addr),
                      remote_size);

#if 0
  // @@ Just debugging.
  char local_address_buf  [BUFSIZ];
  char remote_address_buf [BUFSIZ];

  if (local_address.addr_to_string (local_address_buf,
                                    sizeof local_address_buf) == -1)
    ACE_ERROR ((LM_ERROR,
                "Error:%m:can't obtain local_address's address string"));

  ACE_DEBUG ((LM_DEBUG,
              "ACE_Asynch_Connector<HANDLER>::parse_address : "
              "Local address %s\n",
              local_address_buf));

  if (remote_address.addr_to_string (remote_address_buf,
                                     sizeof remote_address_buf) == -1)
    ACE_ERROR ((LM_ERROR,
                "Error:%m:can't obtain remote_address's address string"));

  ACE_DEBUG ((LM_DEBUG,
              "ACE_Asynch_Connector<HANDLER>::parse_address : "
              "Remote address %s\n",
              remote_address_buf));
#endif /* 0 */

  return;
}
开发者ID:eSDK,项目名称:eSDKClient_Soultion,代码行数:69,代码来源:Asynch_Connector.cpp

示例3: timeout_test

static bool
timeout_test (void)
{
  bool status = true;
  SYNCH_QUEUE mq;
  MyTask task1;
  task1.create_reactor ();
  task1.start (1);
  TestHandler test_handler (task1.get_reactor (), mq);

  // The reactor of taks1 that uses a hrtimer will trigger a timeout in
  // 5 seconds which will enqueue a message block in the queue. At the
  // same moment we calculate a timeout for the dequeue operation for
  // 3 seconds in the future. Than we set the system time 4 seconds back.
  // The condition should timeout because the queue is empty and the trigger
  // only fires after the condition has timed out.
  // Next we start another dequeue for 3 seconds in the future which should
  // return before timing out because by then the trigger should have fired.
  // In case of using regular system time policy for message queue and
  // dequeue timeouts the first dequeue would not have timed out because
  // between calculating the timeout and starting the dequeue the system time
  // shifted back 4 sec causing the trigger to fire before the timeout elapsed.
  // In case timeshifting does not work because of priority problems or such
  // the test should succeed.

  if (!test_handler.trigger_in (ACE_Time_Value (5, 0)))
    ACE_ERROR_RETURN ((LM_ERROR,
                        "(%P|%t) Unable to schedule trigger.\n"),
                      false);

  if (!mq.is_empty ())
    {
      ACE_ERROR ((LM_ERROR,
                  ACE_TEXT ("New queue is not empty!\n")));
      status = false;
    }
  else
    {
      ACE_Message_Block *b;
      ACE_Time_Value_T<ACE_Monotonic_Time_Policy> tv;
      tv = (tv.now () + ACE_Time_Value (3,0)); // Now (monotonic time) + 3 sec

      // shift back in time 4 sec
      set_system_time (ACE_OS::gettimeofday () - ACE_Time_Value (4, 0));

      if (mq.dequeue_head (b, &tv) != -1)
        {
          ACE_ERROR ((LM_ERROR,
                      ACE_TEXT ("Dequeued before timeout elapsed!\n")));
          status = false;
        }
      else if (errno != EWOULDBLOCK)
        {
          ACE_ERROR ((LM_ERROR,
                      ACE_TEXT ("%p\n"),
                      ACE_TEXT ("Dequeue timeout should be EWOULDBLOCK, got")));
          status = false;
        }
      else
        {
          ACE_DEBUG ((LM_DEBUG,
                      ACE_TEXT ("First dequeue timed out: OK\n")));

          tv = (tv.now () + ACE_Time_Value (3,0)); // Now (monotonic time) + 3 sec
          if (mq.dequeue_head (b, &tv) != -1)
            {
              ACE_DEBUG ((LM_DEBUG,
                          ACE_TEXT ("Second dequeue succeeded: OK\n")));
              delete b;
            }
          else
            {
              ACE_ERROR ((LM_ERROR,
                          ACE_TEXT ("Second dequeue timed out!\n")));
              status = false;
            }
        }

      // restore time
      set_system_time (ACE_OS::gettimeofday () + ACE_Time_Value (4, 0));
    }

  ACE_DEBUG((LM_INFO,
              "(%P|%t) Asking worker thread to finish.\n"));
  task1.stop ();

  ACE_Thread_Manager::instance ()->wait ();

  return status;
}
开发者ID:asdlei00,项目名称:ACE,代码行数:90,代码来源:Monotonic_Message_Queue_Test.cpp

示例4: catch

void
Worker::setup (void)
{
  // Make sure we have a connection to the server using the test
  // protocol.
  this->policy_manager_->set_policy_overrides (this->test_protocol_policy_,
                                               CORBA::SET_OVERRIDE);

  // Since the network maybe unavailable temporarily, make sure to try
  // for a few times before giving up.
  for (CORBA::ULong j = 0;;)
    {
      try
        {
          // Send a message to ensure that the connection is setup.
          this->test_->oneway_sync ();

          break;
        }
      catch (const CORBA::TRANSIENT &)
        {
          ++j;

          if (j < this->number_of_connection_attempts_)
            {
              ACE_OS::sleep (1);

              continue;
            }
        }

      ACE_ERROR ((LM_ERROR,
                  "Cannot setup test protocol\n"));

      ACE_OS::exit (-1);
    }

  const char *test_protocol = 0;
  if (this->test_protocol_tag_ == IOP::TAG_INTERNET_IOP)
    test_protocol = "IIOP";
  else if (this->test_protocol_tag_ == TAO_TAG_DIOP_PROFILE)
    test_protocol = "DIOP";
  else if (this->test_protocol_tag_ == TAO_TAG_SCIOP_PROFILE)
    test_protocol = "SCIOP";

  // Use IIOP for setting up the test since the test protocol maybe
  // unreliable.
  this->policy_manager_->set_policy_overrides (this->base_protocol_policy_,
                                               CORBA::SET_OVERRIDE);

  // Since the network maybe unavailable temporarily, make sure to try
  // for a few times before giving up.
  for (CORBA::ULong k = 0;;)
    {
      try
        {
          // Let the server know what to expect..
          this->test_->start_test (this->session_id_,
                                   test_protocol,
                                   this->invocation_rate_,
                                   this->message_size_,
                                   this->iterations_);

          break;
        }
      catch (const CORBA::TRANSIENT &)
        {
          ACE_OS::sleep (1);

          if (k < this->number_of_connection_attempts_)
            {
              ACE_OS::sleep (1);

              continue;
            }
        }

      ACE_ERROR ((LM_ERROR,
                  "Cannot setup base protocol\n"));

      ACE_OS::exit (-1);
    }

  return;
}
开发者ID:CCJY,项目名称:ATCD,代码行数:85,代码来源:Sender_exec.cpp

示例5: ACE_ERROR

int
ClientApp::run (int argc, ACE_TCHAR* argv[])
{
    CORBA::ORB_var orb
        = CORBA::ORB_init (argc, argv);

    // Parse the command-line args for this application.
    // * Raises -1 if problems are encountered.
    // * Returns 1 if the usage statement was explicitly requested.
    // * Returns 0 otherwise.
    int result = this->parse_args (argc, argv);
    if (result != 0)
    {
        return result;
    }

    CORBA::Object_var obj
        = orb->string_to_object(this->ior_.c_str());

    if (CORBA::is_nil(obj.in()))
    {
        ACE_ERROR((LM_ERROR,
                   "(%P|%t) Failed to convert IOR string to obj ref.\n"));
        throw TestException();
    }

    Foo_var foo = Foo::_narrow(obj.in());

    if (CORBA::is_nil(foo.in()))
    {
        ACE_ERROR((LM_ERROR,
                   "(%P|%t) Failed to narrow obj ref to Foo interface.\n"));
        throw TestException();
    }

    // Create the callback object using the child poa with the custom
    // strategy.
    obj = orb->resolve_initial_references("RootPOA");

    if (CORBA::is_nil(obj.in()))
    {
        ACE_ERROR((LM_ERROR,
                   "(%P|%t) Failed to resolve initial ref for 'RootPOA'.\n"));
        throw TestException();
    }

    PortableServer::POA_var root_poa
        = PortableServer::POA::_narrow(obj.in());

    if (CORBA::is_nil(root_poa.in()))
    {
        ACE_ERROR((LM_ERROR,
                   "(%P|%t) Failed to narrow obj ref to POA interface.\n"));
        throw TestException();
    }

    PortableServer::POAManager_var poa_manager
        = root_poa->the_POAManager();

    // Create the child POA.
    CORBA::PolicyList policies(0);
    policies.length(0);

    PortableServer::POA_var child_poa
        = root_poa->create_POA("ChildPoa",
                               poa_manager.in(),
                               policies);

    if (CORBA::is_nil(child_poa.in()))
    {
        ACE_ERROR((LM_ERROR, "(%P|%t) ERROR [ServerApp::run()]: "
                   "Failed to create the child POA.\n"));
        throw TestException();
    }

    // Create the thread pool servant dispatching strategy object, and
    // hold it in a (local) smart pointer variable.
    TAO_Intrusive_Ref_Count_Handle<TAO::CSD::TP_Strategy> csd_tp_strategy =
        new TAO::CSD::TP_Strategy();

    csd_tp_strategy->set_num_threads(1);

    // Tell the strategy to apply itself to the child poa.
    if (csd_tp_strategy->apply_to(child_poa.in()) == false)
    {
        ACE_ERROR((LM_ERROR, "(%P|%t) ERROR [ServerApp::run()]: "
                   "Failed to apply custom dispatching strategy to child poa.\n"));
        throw TestException();
    }

    // Create the servant object.
    Callback_i* servant = new Callback_i ();

    // local smart pointer variable to deal with releasing the reference
    // to the servant object when the smart pointer object falls out of scope.
    PortableServer::ServantBase_var owner_transfer(servant);

    // Activate the servant using the Child POA.
    PortableServer::ObjectId_var oid
        = child_poa->activate_object(servant);
//.........这里部分代码省略.........
开发者ID:asdlei00,项目名称:ACE,代码行数:101,代码来源:ClientApp.cpp

示例6: ACE_DEBUG

void
Receiver::open (ACE_HANDLE handle,
                ACE_Message_Block &message_block)
{
  ACE_DEBUG ((LM_DEBUG,
              "%N:%l:Receiver::open called\n"));

  // New connection, so initiate stuff.

  // Cache the new connection
  this->handle_ = handle;

  // File offset starts at zero
  this->file_offset_ = 0;

  // Open dump file (in OVERLAPPED mode)
  this->dump_file_ = ACE_OS::open (dump_file,
                                   O_CREAT | O_RDWR | O_TRUNC | \
                                   FILE_FLAG_OVERLAPPED);
  if (this->dump_file_ == ACE_INVALID_HANDLE)
    {
      ACE_ERROR ((LM_ERROR,
                  "%p\n",
                  "ACE_OS::open"));
      return;
    }

  // Initiate <ACE_Asynch_Write_File>.
  if (this->wf_.open (*this,
                      this->dump_file_) == -1)
    {
      ACE_ERROR ((LM_ERROR,
                  "%p\n",
                  "ACE_Asynch_Write_File::open"));
      return;
    }

  // Initiate <ACE_Asynch_Read_Stream>.
  if (this->rs_.open (*this, this->handle_) == -1)
    {
      ACE_ERROR ((LM_ERROR,
                  "%p\n",
                  "ACE_Asynch_Read_Stream::open"));
      return;
    }

  // Fake the result and make the <handle_read_stream> get
  // called. But, not, if there is '0' is transferred.
  if (message_block.length () != 0)
    {
      // Duplicate the message block so that we can keep it around.
      ACE_Message_Block &duplicate =
        *message_block.duplicate ();

      // Fake the result so that we will get called back.
      ACE_Asynch_Read_Stream_Result_Impl *fake_result =
        ACE_Proactor::instance ()->create_asynch_read_stream_result (this->proxy (),
                                                                     this->handle_,
                                                                     duplicate,
                                                                     initial_read_size,
                                                                     0,
                                                                     ACE_INVALID_HANDLE,
                                                                     0,
                                                                     0);

      size_t bytes_transferred = message_block.length ();

      // <complete> for Accept would have already moved the <wr_ptr>
      // forward. Update it to the beginning position.
      duplicate.wr_ptr (duplicate.wr_ptr () - bytes_transferred);

      // This will call the callback.
      fake_result->complete (message_block.length (),
                             1,
                             0);

      // Zap the fake result.
      delete fake_result;
    }
  else
    // Otherwise, make sure we proceed. Initiate reading the socket
    // stream.
    if (this->initiate_read_stream () == -1)
      return;
}
开发者ID:binghuo365,项目名称:BaseLab,代码行数:85,代码来源:test_proactor.cpp

示例7: ACE_TMAIN

int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
  try
    {
      const char *location1 = "MyLocation 1";
      const char *location2 = "MyLocation 2";
      const char *location3 = "MyLocation 3";
      const char *location4 = "MyLocation 4";
      const char *location5 = "MyLocation 5";
      const char *location6 = "MyLocation 6";

      LB_server lb_server (argc, argv);

      if (lb_server.start_orb_and_poa () == -1)
        return 1;

      if (parse_args (argc, argv) == -1)
        return 1;

      if (server_id == 1 && lb_server.create_object_group () == -1)
        return 1;
      else if (lb_server.get_object_group () == -1)
        return 1;

      const char ** location = 0;

      switch (server_id)
      {
        case 1:
          location = &location1;
          break;
        case 2:
          location = &location2;
          break;
        case 3:
          location = &location3;
          break;
        case 4:
          location = &location4;
          break;
        case 5:
          location = &location5;
          break;
        case 6:
          location = &location6;
          break;
      }

      Basic *basic_servant;

      ACE_NEW_RETURN (basic_servant,
                      Basic (lb_server.object_group (),
                             lb_server.load_manager (),
                             lb_server.orb (),
                             *location,
                             server_id),
                      1);
      PortableServer::ServantBase_var owner_transfer(basic_servant);

      if (lb_server.register_servant (basic_servant, *location) == -1)
        {
          (void) lb_server.destroy ();
          return 1;
        }

      if (server_id == 2)
        {
          Basic *direct_basic_servant = 0;

          ACE_NEW_RETURN (direct_basic_servant,
                          Basic (server_id),
                          1);

          PortableServer::ServantBase_var owner_transfer(direct_basic_servant);

          Test::Basic_var direct_basic =
            direct_basic_servant->_this ();

          CORBA::String_var ior =
            lb_server.orb ()->object_to_string (direct_basic.in ());

          FILE *output_file =
            ACE_OS::fopen (direct_obj_file, "w");

          if (output_file == 0)
            {
              ACE_ERROR ((LM_ERROR,
                          "Cannot open output file(%s) for writing IOR:", direct_obj_file));
              if (lb_server.destroy () == -1)
                return 1;
            }

          ACE_OS::fprintf (output_file, "%s", ior.in());
          ACE_OS::fclose (output_file);
        }

      //  ACE_OS::sleep (1000);
      lb_server.orb ()->run ();

//.........这里部分代码省略.........
开发者ID:asdlei00,项目名称:ACE,代码行数:101,代码来源:server.cpp

示例8: run_main


//.........这里部分代码省略.........
    case '\xb2':
    case '\xb3':
    case '\xb4':
    case '\xb5':
    case '\xb6':
    case '\xb7':
    case '\xb8':
    case '\xb9':
    case '\xba':
    case '\xbb':
    case '\xbc':
    case '\xbd':
    case '\xbe':
    case '\xbf':
    case '\xc0':
    case '\xc1':
    case '\xc2':
    case '\xc3':
    case '\xc4':
    case '\xc5':
    case '\xc6':
    case '\xc7':
    case '\xc8':
    case '\xc9':
    case '\xca':
    case '\xcb':
    case '\xcc':
    case '\xcd':
    case '\xce':
    case '\xcf':
    case '\xd0':
    case '\xd1':
    case '\xd2':
    case '\xd3':
    case '\xd4':
    case '\xd5':
    case '\xd6':
    case '\xd7':
    case '\xd8':
    case '\xd9':
    case '\xda':
    case '\xdb':
    case '\xdc':
    case '\xdd':
    case '\xde':
    case '\xdf':
    case '\xe0':
    case '\xe1':
    case '\xe2':
    case '\xe3':
    case '\xe4':
    case '\xe5':
    case '\xe6':
    case '\xe7':
    case '\xe8':
    case '\xe9':
    case '\xea':
    case '\xeb':
    case '\xec':
    case '\xed':
    case '\xee':
    case '\xef':
    case '\xf0':
    case '\xf1':
    case '\xf2':
    case '\xf3':
    case '\xf4':
    case '\xf5':
    case '\xf6':
    case '\xf7':
    case '\xf8':
    case '\xf9':
    case '\xfa':
    case '\xfb':
    case '\xfc':
    case '\xfd':
    case '\xfe':
    case '\xff':
      {
        // Test works
        retval = 0;
      }
      break;
    }

  if (retval != 0)
  {
    ACE_ERROR ((LM_ERROR,
                ACE_TEXT ("ERROR: Switch doesn't worked as expected\n")));
  }
  else
  {
    ACE_DEBUG ((LM_INFO,
                ACE_TEXT ("Switch worked as expected\n")));
  }

  ACE_END_TEST;

  return retval;
}
开发者ID:suiye223,项目名称:ace-linux,代码行数:101,代码来源:Compiler_Features_33_Test.cpp

示例9: run_main


//.........这里部分代码省略.........
      fresulta.get (resulta);

      ACE_DEBUG ((LM_DEBUG,
                  ACE_TEXT ("(%t) result(%u) a %u\n"),
                  count,
                  (u_int) resulta));
    }

  count = 0;
  while (fsetb.next_readable (fresultb))
    {
      fresultb.get (resultb);

      ACE_DEBUG ((LM_DEBUG,
                  ACE_TEXT ("(%t) result(%u) b %u\n"),
                  count,
                  (u_int) resultb));
    }

  count = 0;
  while (fsetc.next_readable (fresultc))
    {
      fresultc.get (resultc);

      ACE_DEBUG ((LM_DEBUG,
                  ACE_TEXT ("(%t) result(%u) c %u\n"),
                  count,
                  (u_int) resultc));
    }

  count = 0;
  while (fsetd.next_readable (fresultd))
    {
      fresultd.get (resultd);

      ACE_DEBUG ((LM_DEBUG,
                  ACE_TEXT ("(%t) result(%u) d %u\n"),
                  count,
                  (u_int) resultd));
    }

  const ACE_TCHAR *name = 0;
  count = 0;
  while (fsetname.next_readable (fname))
    {
      fname.get (name);

      ACE_DEBUG ((LM_DEBUG,
                  ACE_TEXT ("(%t) result(%u) name %s\n"),
                  count,
                  name));
    }

  if (fseta.is_empty ())
    ACE_DEBUG ((LM_DEBUG,
                ACE_TEXT ("(%t) wow.. set a is empty.....\n")));

  if (fsetb.is_empty ())
    ACE_DEBUG ((LM_DEBUG,
                ACE_TEXT ("(%t) wow.. set b is empty.....\n")));

  if (fsetc.is_empty ())
    ACE_DEBUG ((LM_DEBUG,
                ACE_TEXT ("(%t) wow.. set c is empty.....\n")));

  if (fsetd.is_empty ())
    ACE_DEBUG ((LM_DEBUG,
                ACE_TEXT ("(%t) wow.. set d is empty.....\n")));

  if (fsetname.is_empty ())
    ACE_DEBUG ((LM_DEBUG,
                ACE_TEXT ("(%t) wow.. set name is empty.....\n")));

  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("(%t) task_count %d\n"),
              task_count.value () ));

  // Close things down.
  andres->end ();
  peter->end ();
  helmut->end ();
  matias->end ();

  ACE_Thread_Manager::instance ()->wait ();
  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("(%t) task_count %d\n"),
              task_count.value () ));

  delete andres;
  delete peter;
  delete helmut;
  delete matias;

#else
  ACE_ERROR ((LM_INFO,
              ACE_TEXT ("threads not supported on this platform\n")));
#endif /* ACE_HAS_THREADS */
  ACE_END_TEST;
  return 0;
}
开发者ID:INMarkus,项目名称:ATCD,代码行数:101,代码来源:Future_Set_Test.cpp

示例10: ACE_NEW_RETURN

int
Logging_Handler::handle_input (ACE_HANDLE)
{
  ACE_Log_Record log_record;

  // We need to use the old two-read trick here since TCP sockets
  // don't support framing natively.  Allocate a message block for the
  // payload; initially at least large enough to hold the header, but
  // needs some room for alignment.
  ACE_Message_Block *payload_p = 0;
  ACE_Message_Block *header_p = 0;
  ACE_NEW_RETURN (header_p,
                  ACE_Message_Block (ACE_DEFAULT_CDR_BUFSIZE),
                  -1);

  auto_ptr <ACE_Message_Block> header (header_p);

  // Align the Message Block for a CDR stream
  ACE_CDR::mb_align (header.get ());

  ACE_CDR::Boolean byte_order;
  ACE_CDR::ULong length;

  ssize_t count = ACE::recv_n (this->peer ().get_handle (),
                               header->wr_ptr (),
                               8);
  switch (count)
    {
      // Handle shutdown and error cases.
    default:
    case -1:
    case 0:

      ACE_DEBUG ((LM_DEBUG,
                  ACE_TEXT ("server logging daemon closing down\n")));

      return -1;
      /* NOTREACHED */

    case 8:
      // Just fall through in this case..
      break;
    }

  header->wr_ptr (8); // Reflect addition of 8 bytes.

  // Create a CDR stream to parse the 8-byte header.
  ACE_InputCDR header_cdr (header.get ());

  // Extract the byte-order and use helper methods to disambiguate
  // octet, booleans, and chars.
  header_cdr >> ACE_InputCDR::to_boolean (byte_order);

  // Set the byte-order on the stream...
  header_cdr.reset_byte_order (byte_order);

  // Extract the length
  header_cdr >> length;

  ACE_NEW_RETURN (payload_p,
                  ACE_Message_Block (length),
                  -1);
  auto_ptr <ACE_Message_Block> payload (payload_p);

  // Ensure there's sufficient room for log record payload.
  ACE_CDR::grow (payload.get (), 8 + ACE_CDR::MAX_ALIGNMENT + length);

  // Use <recv_n> to obtain the contents.
  if (ACE::recv_n (this->peer ().get_handle (),
                   payload->wr_ptr (),
                   length) <= 0)
    {
      ACE_ERROR ((LM_ERROR,
                  ACE_TEXT ("%p\n"),
                  ACE_TEXT ("recv_n()")));
      return -1;
    }

  payload->wr_ptr (length);   // Reflect additional bytes

  ACE_InputCDR payload_cdr (payload.get ());
  payload_cdr.reset_byte_order (byte_order);
  payload_cdr >> log_record;  // Finally extract the <ACE_log_record>.

  log_record.length (length);

  log_record.print (ACE_TEXT_CHAR_TO_TCHAR (this->peer_name_), 1, stderr);

  return 0;
}
开发者ID:esohns,项目名称:ATCD,代码行数:90,代码来源:server_loggerd.cpp

示例11: recv_n

int
Twoway_Handler::run (void)
{
  // Read data from client (terminate on error).

  char *request = 0;

  for (;;)
    {
      ACE_INT32 len = 0;

      if (parse_header_and_allocate_buffer (request,
                                            &len) == -1)
        return -1;

      // Subtract off the sizeof the length prefix.
      ssize_t r_bytes =
        this->ssl_stream_ -> recv_n (request,
                                     len - sizeof (ACE_UINT32));

      if (r_bytes == -1)
        {
          ACE_ERROR ((LM_ERROR,
                      ACE_TEXT ("%p\n"),
                      ACE_TEXT ("recv")));
          break;
        }
      else if (r_bytes == 0)
        {
          ACE_DEBUG ((LM_DEBUG,
                      ACE_TEXT ("(%P|%t) reached end of input, connection ")
                      ACE_TEXT ("closed by client\n")));
          break;
        }
      else if (OPTIONS::instance ()->verbose ()
               && ACE::write_n (ACE_STDOUT,
                                request,
                                r_bytes) != r_bytes)
        ACE_ERROR ((LM_ERROR,
                    ACE_TEXT ("%p\n"),
                    ACE_TEXT ("ACE::write_n")));
      else
        {
          ssize_t s_bytes =
            (ssize_t) OPTIONS::instance ()->reply_message_len ();

          // Don't try to send more than is in the request buffer!
          if (s_bytes > r_bytes)
            s_bytes = r_bytes;

          if (this->ssl_stream_ -> send_n (request,
                                           s_bytes) != s_bytes)
            ACE_ERROR ((LM_ERROR,
                        ACE_TEXT ("%p\n"),
                        ACE_TEXT ("send_n")));
        }
      this->total_bytes_ += size_t (r_bytes);
      this->message_count_++;

      delete [] request;
      request = 0;
    }

  delete [] request;
  return 0;
}
开发者ID:esohns,项目名称:ATCD,代码行数:66,代码来源:SSL-server-fancy.cpp

示例12: run_main

int
run_main (int , ACE_TCHAR *[])
{
  ACE_START_TEST (ACE_TEXT ("Monotonic_Task_Test"));

  int status = 0;

# if defined (ACE_HAS_THREADS)
  MyTask my_task;

  if (my_task.start () == 0)
    {
      // shift back in time 4 sec; this would mess up timeouts if
      // monotonic timer was not used
      ACE_Time_Value tv_shift (4, 0);
      set_system_time (ACE_OS::gettimeofday () - tv_shift);

      if (my_task.put_message () == 0)
        {
          // task should now have finished dequeueing and started waiting for stop signal
          // wait (2sec) on thread manager should timeout

                                                 // use the time policy aware gettimeofday()
                                                 // method of the task to get current time
          ACE_Time_Value_T<ACE_Monotonic_Time_Policy> tv (my_task.gettimeofday ());
          tv += ACE_Time_Value (2, 0);

          // shift another 3 sec back in time; without monotonic timer support in
          // thread manager this would mess up the timed wait
          tv_shift += ACE_Time_Value (3, 0);
          set_system_time (ACE_OS::gettimeofday () - ACE_Time_Value (3,0));

          if (my_task.thr_mgr ()->wait (&tv) == 0)
            {
              ACE_ERROR ((LM_ERROR, ACE_TEXT ("Thread manager did not time out\n")));
              status = 1;
            }
          else
            {
              ACE_Time_Value_T<ACE_Monotonic_Time_Policy> tv_now (my_task.gettimeofday ());

              ACE_DEBUG ((LM_INFO, ACE_TEXT ("Thread manager timed out at %#T\n"), &tv_now));
            }
        }
      else
        status = 1;

      // ok, now stop task
      if (my_task.stop () != 0)
        {
          ACE_ERROR ((LM_ERROR, ACE_TEXT ("Failed to stop task\n")));
          status = 1;
        }

      // restore time
      set_system_time (ACE_OS::gettimeofday () + tv_shift);
    }
  else
    status = 1;

# endif /* ACE_HAS_THREADS */

  ACE_END_TEST;
  return status;
}
开发者ID:CCJY,项目名称:ACE,代码行数:65,代码来源:Monotonic_Task_Test.cpp

示例13: ACE_DEBUG

int
MyTask::svc (void)
{
  ACE_DEBUG ((LM_DEBUG, ACE_TEXT (" (%P|%t) MyTask::svc started\n")));

  // Now (according to task time policy = monotonic time)
  ACE_Time_Value_T<ACE_Monotonic_Time_Policy> tv (this->gettimeofday ());

  {
    ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1);

    ACE_DEBUG ((LM_DEBUG, ACE_TEXT (" (%P|%t) MyTask::svc - signalling waiter\n")));

    this->cond_.signal (); // signal waiter we have started
    // waiter will shift system time back 4 sec after this which would mess
    // up the first wait for a message if we were not using monotonic time
  }

  if (!this->msg_queue ()->is_empty ())
    {
      ACE_ERROR ((LM_ERROR,
                  ACE_TEXT ("New task queue is not empty!\n")));
      this->status_ = -1;
    }
  else
    {
      ACE_Message_Block *b;
      tv += ACE_Time_Value (3,0); // Now + 3 sec

      if (this->getq (b, &tv) != -1)
        {
          ACE_ERROR ((LM_ERROR,
                      ACE_TEXT ("Dequeued before timeout elapsed!\n")));
          this->status_ = -1;
        }
      else if (errno != EWOULDBLOCK)
        {
          ACE_ERROR ((LM_ERROR,
                      ACE_TEXT ("%p\n"),
                      ACE_TEXT ("Dequeue timeout should be EWOULDBLOCK, got")));
          this->status_ = -1;
        }
      else
        {
          ACE_Time_Value_T<ACE_Monotonic_Time_Policy> tv_now (this->gettimeofday ());

          ACE_DEBUG ((LM_DEBUG,
                      ACE_TEXT ("First getq timed out at %#T (timeout was %#T)\n"), &tv_now, &tv));

          tv =  this->gettimeofday () + ACE_Time_Value (4,0); // Now (monotonic time) + 3 sec
          if (this->getq (b, &tv) != -1)
            {
              tv_now = tv.now ();

              ACE_DEBUG ((LM_DEBUG,
                          ACE_TEXT ("Second getq succeeded at %#T\n"), &tv_now));
              delete b;
            }
          else
            {
              ACE_ERROR ((LM_ERROR,
                          ACE_TEXT ("Second getq timed out!\n")));
              this->status_ = -1;
            }
        }
    }

  {
    ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1);

    ACE_DEBUG ((LM_DEBUG, ACE_TEXT (" (%P|%t) MyTask::svc - waiting for stop\n")));

    if (!this->stop_)
      this->cond_.wait ();
  }

  ACE_DEBUG ((LM_DEBUG, ACE_TEXT (" (%t) MyTask finished\n")));
  return 0;
}
开发者ID:CCJY,项目名称:ACE,代码行数:79,代码来源:Monotonic_Task_Test.cpp

示例14: run_main

int
run_main (int, ACE_TCHAR *[])
{
  ACE_START_TEST (ACE_TEXT("Compiler_Features_13_Test"));

  // As usual, the exit status from the test is 0 on success, 1 on
  // failure
  int status = 0;

  {
    // Make sure const cast works.  Compilation is interesting, the
    // functionality test here is just to make sure the compiler does
    // not optimize things away ...
    int x = 5;
    int const & y = x;
    const_cast<int&>(y) = 3;

    if (x != 3)
      {
        status = 1;
        ACE_ERROR((LM_ERROR,
                   ACE_TEXT("Wrong value after const_cast,")
                   ACE_TEXT(" expected %d, got %d\n"),
                   3, x));
      }
  }

  // Make sure dynamic cast through pointers work ...
  Derived d;
  d.value = 24;
  Base * b1 = &d;
  Derived * d1 = dynamic_cast<Derived*>(b1);
  if (d1 == 0)
    {
      status = 1;
      ACE_ERROR((LM_ERROR,
                 ACE_TEXT("dynamic_cast returns null, expected value\n")));
    }
  d1->value = 42;
  if (d.value != 42)
    {
      ACE_ERROR((LM_ERROR,
                 ACE_TEXT("Wrong value after dynamic_cast, expected %d, got %d\n"),
                 42, d.value));
    }

  // Make sure dynamic cast detects invalid casts
  Another a;
  Base * b2 = &a;
  Derived * d2 = dynamic_cast<Derived*>(b2);
  if (d2 != 0)
    {
      status = 1;
      ACE_ERROR((LM_ERROR,
                 ACE_TEXT("dynamic_cast should return null\n")));
    }

  // Make sure dynamic cast raises an exception
  Base & b3 = a;
  try
    {
      (void) dynamic_cast<Derived&>(b3);

      status = 1;
      ACE_ERROR((LM_ERROR,
                 ACE_TEXT("dynamic_cast should have raised exception\n")));
    }
  catch(std::exception const &)
    {
    }
  catch(...)
    {
      status = 1;
      ACE_ERROR((LM_ERROR,
                 ACE_TEXT("dynamic_cast should have raised std::exception\n")));
    }

  {
    // Just test these compile ...
    double x = 42.0;
    int y = static_cast<int>(x);
    void * z = reinterpret_cast<void*>(y);

    if (z == 0)
      {
        ACE_ERROR((LM_ERROR,
                   ACE_TEXT("My hack to make sure the code is not ")
                   ACE_TEXT("optimized away backfired!\n")));
      }
  }

  ACE_END_TEST;
  return status;
}
开发者ID:dnjsflagh2,项目名称:mmo_project,代码行数:94,代码来源:Compiler_Features_13_Test.cpp

示例15: ACE_ERROR

int TestTask::svc()
{

  try {
    // Get reference to Root POA
    CORBA::Object_var obj = orb_->resolve_initial_references("RootPOA");
    PortableServer::POA_var poa = PortableServer::POA::_narrow(obj.in());

    // Activate POA Manager
    PortableServer::POAManager_var mgr = poa->the_POAManager();
    mgr->activate();

    // Find the Naming Service
    obj = orb_->string_to_object ("corbaloc:iiop:[email protected]:9932/NameService");
    CosNaming::NamingContext_var root =
      CosNaming::NamingContext::_narrow(obj.in());

    if (CORBA::is_nil(root.in())) {
      ACE_ERROR ((LM_ERROR, "Error, Nil Naming Context reference\n"));
      return 1;
    }
    // Bind the example Naming Context, if necessary
    CosNaming::NamingContext_var example_nc;
    CosNaming::Name name;
    name.length(1);
    name[0].id = CORBA::string_dup("example");
    try
    {
      obj = root->resolve(name);
      example_nc =
        CosNaming::NamingContext::_narrow(obj.in());
    }
    catch (const CosNaming::NamingContext::NotFound&)
    {
      example_nc = root->bind_new_context(name);
    }

    // Bind the Test object
    name.length(2);
    name[1].id = CORBA::string_dup("Hello");

    // Create an object
    Hello servant(orb_.in ());
    PortableServer::ObjectId_var oid = poa->activate_object(&servant);
    obj = poa->id_to_reference(oid.in());
    root->rebind(name, obj.in());

    ACE_DEBUG ((LM_INFO, "Hello object bound in Naming Service B\n"));

    name.length(1);
    obj = orb_->string_to_object ("corbaloc:iiop:[email protected]:9931/NameService");
    root = CosNaming::NamingContext::_narrow(obj.in());
    root->bind_context (name, example_nc.in ());

    ACE_DEBUG ((LM_INFO, "'example' context of NS B bound in Naming Service A\n"));

    CORBA::String_var ior =
      orb_->object_to_string (obj.in ());

    // Output the IOR to the <ior_output_file>
    FILE *output_file= ACE_OS::fopen (ior_output_file, "w");
    if (output_file == 0)
      ACE_ERROR_RETURN ((LM_ERROR,
                          "Cannot open output file %s for writing IOR: %C\n",
                          ior_output_file,
                          ior.in ()),
                          1);
    ACE_OS::fprintf (output_file, "%s", ior.in ());
    ACE_OS::fclose (output_file);

    ACE_DEBUG ((LM_INFO, "Wrote IOR file\n"));

    // Normally we run the orb and the orb is shutdown by
    // calling TestTask::end().
    // Accept requests
    orb_->run();
    orb_->destroy();

    return 0;
  }
  catch (CORBA::Exception& ex)
  {
    ex._tao_print_exception ("CORBA exception: ");
  }

  return -1;
}
开发者ID:asdlei00,项目名称:ACE,代码行数:87,代码来源:server.cpp


注:本文中的ACE_ERROR函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。