int
run_main (int argc, ACE_TCHAR *argv[])
{
  ACE_START_TEST (ACE_TEXT ("MT_Reference_Counted_Event_Handler_Test"));

  // Validate options.
  int result =
    parse_args (argc, argv);
  if (result != 0)
    return result;

  disable_signal (SIGPIPE, SIGPIPE);

  int ignore_nested_upcalls = 1;
  int perform_nested_upcalls = 0;

  int event_loop_thread_required = 1;
  int event_loop_thread_not_required = 0;

  if (test_select_reactor)
    {
      ACE_DEBUG ((LM_DEBUG,
                  ACE_TEXT ("\n\n(%t) Testing Select Reactor....\n\n")));

      test<ACE_Select_Reactor> test (ignore_nested_upcalls,
                                     event_loop_thread_not_required);
      ACE_UNUSED_ARG (test);
    }

  if (test_tp_reactor)
    {
      ACE_DEBUG ((LM_DEBUG,
                  ACE_TEXT ("\n\n(%t) Testing TP Reactor....\n\n")));

      test<ACE_TP_Reactor> test (perform_nested_upcalls,
                                 event_loop_thread_not_required);
      ACE_UNUSED_ARG (test);
    }

#if defined (ACE_HAS_EVENT_POLL)

  if (test_dev_poll_reactor)
    {
      ACE_DEBUG ((LM_DEBUG,
                  ACE_TEXT ("\n\n(%t) Testing Dev Poll Reactor....\n\n")));

      test<ACE_Dev_Poll_Reactor> test (perform_nested_upcalls,
                                       event_loop_thread_not_required);
      ACE_UNUSED_ARG (test);
    }

#endif

#if defined (ACE_WIN32)

  if (test_wfmo_reactor)
    {
      ACE_DEBUG ((LM_DEBUG,
                  ACE_TEXT ("\n\n(%t) Testing WFMO Reactor....\n\n")));

      test<ACE_WFMO_Reactor> test (ignore_nested_upcalls,
                                   event_loop_thread_required);
      ACE_UNUSED_ARG (test);
    }

#else /* ACE_WIN32 */

  ACE_UNUSED_ARG (event_loop_thread_required);

#endif /* ACE_WIN32 */

  ACE_END_TEST;

  return 0;
}
int
Invocation_Thread::svc (void)
{
  int connection_counter = 0;
  ACE_DEBUG ((LM_DEBUG,
    ACE_TEXT("(%t) Invocation_Thread::svc commencing\n")));

  disable_signal (SIGPIPE, SIGPIPE);

  for (int message_counter = 1;; ++message_counter)
    {
      // Get a connection from the cache.
      Sender *sender =
        this->connection_cache_.acquire_connection ();

      // If no connection is available in the cache, create a new one.
      if (sender == 0)
        {
          if (connection_counter < number_of_connections)
            {
              sender = this->create_connection ();

              // This lets the Close_Socket_Thread know that the new
              // connection has been created.
              int result =
                this->new_connection_event_.signal ();
              ACE_TEST_ASSERT (result == 0);
              ACE_UNUSED_ARG (result);

              ++connection_counter;
              message_counter = 1;
            }
          else
            // Stop the thread, if the maximum number of connections
            // for the test has been reached.
            break;
        }

      // The reference count on the sender was increased by the cache
      // before it was returned to us.
      ACE_Event_Handler_var safe_sender (sender);

      // If the test does not require making invocations, immediately
      // release the connection.
      if (!this->make_invocations_)
        {
          this->connection_cache_.release_connection (sender);

          // Sleep for a short while
          ACE_OS::sleep (ACE_Time_Value (0, 10 * 1000));
        }
      else
        {
          // Make invocation.
          ssize_t result =
            sender->send_message ();

          // If successful, release connection.
          if (result == message_size)
            {
              if (debug)
                ACE_DEBUG ((LM_DEBUG,
                            ACE_TEXT ("(%t) Message %d:%d delivered on handle %d\n"),
                            connection_counter,
                            message_counter,
                            sender->handle_));

              this->connection_cache_.release_connection (sender);
            }
          else
            {
              // If failure in making invocation, close the sender.
              if (debug)
                ACE_DEBUG ((LM_DEBUG,
                            ACE_TEXT ("(%t) /*** Problem in delivering message ")
                            ACE_TEXT ("%d:%d on handle %d: shutting down ")
                            ACE_TEXT ("invocation thread ***/\n"),
                            connection_counter,
                            message_counter,
                            sender->handle_));

              ACE_DEBUG ((LM_DEBUG,
                          ACE_TEXT ("(%t) Invocation thread calling ")
                          ACE_TEXT ("Sender::close() for handle %d\n"),
                          sender->handle_));

              sender->close ();
            }
        }
    }
  ACE_DEBUG ((LM_DEBUG,
    ACE_TEXT("(%t) Invocation_Thread::svc calling end_reactor_event_loop\n")));

  // Close the Reactor event loop.
  this->reactor_.end_reactor_event_loop ();
  ACE_DEBUG ((LM_DEBUG,
    ACE_TEXT("(%t) Invocation_Thread::svc terminating\n")));

  return 0;
}
Exemplo n.º 3
0
int
run_main (int, ACE_TCHAR *[])
{
  ACE_START_TEST (ACE_TEXT ("Bug_2912_Regression_Test"));

  // SSL_CTX_set_cipher_list, etc.
  init_ssl ();

  // Keep RT signals on POSIX from killing us.
  disable_signal (ACE_SIGRTMIN, ACE_SIGRTMAX);

  int ret = 0;
  Client_Service_Handler client_handler;
  Server_Service_Handler server_handler;
  ACE_Time_Value wait_time (10, 0);

  // Client and Server will utilize different proactors since this test
  // depends on SSL thread error state behavior.

  CLIENT_PROACTOR_TASK->activate ();
  SERVER_PROACTOR_TASK->activate ();

  // Open server acceptor and client connector

  if (0 == ret)
  {
    ret = ACCEPTOR->open (
      ACE_INET_Addr (ACE_DEFAULT_SERVER_PORT),
      0,
      0,
      ACE_DEFAULT_ASYNCH_BACKLOG,
      1,
      SERVER_PROACTOR,
      1);

      if (-1 == ret)
      {
        ACE_DEBUG ((LM_DEBUG, ACE_TEXT (
          "ACE_Asynch_Acceptor::open failed, %d\n"), (int)errno));
      }
  }

  if (0 == ret)
  {
    ret = CONNECTOR->open (0, CLIENT_PROACTOR, 1);

    if (-1 == ret)
    {
      ACE_DEBUG ((LM_DEBUG, ACE_TEXT (
        "ACE_Asynch_Connector::open failed, %d\n"), (int)errno));
    }
  }

  // Supply server_handler and client_handler to acceptor and connector and
  // connect client to the server.

  if (0 == ret)
  {
    ACCEPTOR->prepare_for_connection (&server_handler);
    CONNECTOR->prepare_for_connection (&client_handler);

    ret = CONNECTOR->connect (
      ACE_INET_Addr (ACE_DEFAULT_SERVER_PORT, ACE_LOCALHOST));

    if (-1 == ret)
    {
      ACE_DEBUG ((LM_DEBUG, ACE_TEXT (
        "ACE_Asynch_Connector::connect failed, %d\n"), (int)errno));
    }
  }

  if (0 == ret)
  {
    ret = client_handler.wait_for_external_write_queue (&wait_time);
    if (-1 == ret)
    {
      ACE_DEBUG ((LM_DEBUG, ACE_TEXT (
        "Timed out waiting for client's write readiness\n")));
    }
  }

  // Client sends data to server

  if (0 == ret)
  {
    ret = client_handler.write_data ();
  }

  // Client waits for echo reply from server

  if (0 == ret)
  {
    ret = client_handler.wait_for_read_completed (&wait_time);

    if (-1 == ret)
    {
      ACE_DEBUG ((LM_DEBUG, ACE_TEXT (
        "Timed out waiting for client's read to complete\n")));
    }
  }

  if (0 == ret)
  {
    if (client_handler.read_successful () == 1)
    {
      ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Success\n")));
      ret = 0;
    }
    else
    {
      ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Client's read failed\n")));
      ret = -1;
    }
  }

  // Cleanup and shutdown

  ACCEPTOR->cancel ();
  while (!ACCEPTOR->safe_to_delete ())
    ACE_OS::sleep (ACE_Time_Value (0, 500000));

  CONNECTOR->cancel ();
  while (!CONNECTOR->safe_to_delete ())
    ACE_OS::sleep (ACE_Time_Value (0, 500000));

  client_handler.cancel_and_close ();
  while (!client_handler.safe_to_delete ())
    ACE_OS::sleep (ACE_Time_Value (0, 500000));

  server_handler.cancel_and_close ();
  while (!server_handler.safe_to_delete ())
    ACE_OS::sleep (ACE_Time_Value (0, 500000));

  CLIENT_PROACTOR->proactor_end_event_loop ();
  CLIENT_PROACTOR_TASK->wait ();

  SERVER_PROACTOR->proactor_end_event_loop ();
  SERVER_PROACTOR_TASK->wait ();

  ACE_END_TEST;

  return 0;
}
int
Close_Socket_Thread::svc (void)
{
  unsigned int seed = (unsigned int) ACE_OS::time ();
  ACE_Time_Value timeout (0, close_timeout * 1000);
  ACE_DEBUG ((LM_DEBUG,
    ACE_TEXT("(%t) Close_Socket_Thread::svc commencing\n")));

  disable_signal (SIGPIPE, SIGPIPE);

  for (; !this->reactor_.reactor_event_loop_done ();)
    {
      // Wait for the new connection to be established.
      int result =
        this->new_connection_event_.wait (&timeout,
                                          0);
      ACE_TEST_ASSERT (result == 0 ||
                  (result == -1 && errno == ETIME));

      if (result == -1 &&
          errno == ETIME)
        continue;

      // Sleep for half a second.
      ACE_OS::sleep (timeout);

      int close_client = 0;

      // If the invocation thread is making invocations and if the
      // receiver is threaded, either socket can be closed.
      if (this->make_invocations_ &&
          this->run_receiver_thread_)
        // Randomize which socket to close.
        close_client = ACE_OS::rand_r (&seed) % 2;

      // If the invocation thread is making invocations, only close
      // the client socket.
      else if (this->make_invocations_)
        close_client = 1;
      else
        // If the receiver is threaded, only close the server socket.
        close_client = 0;

      if (close_client)
        {
          // Close the client socket.
          if (debug)
            ACE_DEBUG ((LM_DEBUG,
                        ACE_TEXT ("(%t) Close socket thread closing client ")
                        ACE_TEXT ("handle %d\n"),
                        client_handle));

          ACE_OS::shutdown (client_handle, ACE_SHUTDOWN_BOTH);
          ACE_OS::closesocket (client_handle);
        }
      else
        {
          // Close the server socket.
          if (debug)
            ACE_DEBUG ((LM_DEBUG,
                        ACE_TEXT ("(%t) Close socket thread closing server ")
                        ACE_TEXT ("handle %d\n"),
                        server_handle));
          ACE_OS::shutdown (server_handle, ACE_SHUTDOWN_BOTH);
          ACE_OS::closesocket (server_handle);
        }
    }
  ACE_DEBUG ((LM_DEBUG,
    ACE_TEXT("(%t) Close_Socket_Thread::svc terminating\n")));

  return 0;
}
Exemplo n.º 5
0
// *************************************************************
//   Configuration helpers
// *************************************************************
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  ACE_START_TEST (ACE_TEXT ("PSSL_Test"));


  if (cfg.parse_args (argc, argv) < 0)
    return -1;

  disable_signal (ACE_SIGRTMIN, ACE_SIGRTMAX);
  disable_signal (SIGPIPE, SIGPIPE);
  disable_signal (SIGIO, SIGIO);

  //ACE_DEBUG ((LM_DEBUG,
  //            ACE_TEXT ("FD_SETSIZE=%d ACE_FDSETSIZE=%d\n"),
  //            FD_SETSIZE,
  //            ACE_FD_SETSIZE));

  ACE_DEBUG ((LM_DEBUG,
             "s_blksize=%u r_blksize=%u win_size=%u\n",
              cfg.s_blksize(),
              cfg.r_blksize(),
              cfg.w_size()));

  ACE_SSL_Context *context = ACE_SSL_Context::instance ();
  // Note - the next two strings are naked on purpose... the arguments to
  // the ACE_SSL_Context methods are const char *, not ACE_TCHAR *.
  context->certificate ("dummy.pem", SSL_FILETYPE_PEM);
  context->private_key ("key.pem", SSL_FILETYPE_PEM);


  {
  int rc = 0;

  ProactorTask task1(cfg);

  RecvFactory r_factory;
  SendFactory s_factory;

  PSessionManager r_manager (task1, r_factory,"R_Manager");
  PSessionManager s_manager (task1, s_factory,"S_Manager");

  Acceptor  acceptor  (r_manager);
  Connector connector (s_manager);

  ACE_Time_Value time_begin = ACE_OS::gettimeofday ();
  ACE_Time_Value time_end = ACE_OS::gettimeofday ();
  ACE_Time_Value time_run;

  if (task1.start () == 0)
    {
      ACE_Time_Value timeout (cfg.timeout(), 0);
      r_manager.set_timeout (timeout);
      s_manager.set_timeout (timeout);

      if (cfg.both() != 0 || cfg.connections () == 0) // Acceptor
        {
          // Simplify, initial read with zero size
          if (acceptor.start (ACE_INET_Addr (cfg.listen_port())) == 0)
            rc = 1;
        }

      if (cfg.both() != 0 || cfg.connections () > 0) // Connector
        {
          ACE_INET_Addr addr;

          addr.set (cfg.connect_port(), cfg.connect_host());

          rc += connector.start (addr, cfg.connections ());
        }

      time_begin = ACE_OS::gettimeofday ();

      if (rc > 0)
        {
          task1.enable_event_loop();
          
          ACE_Time_Value  sleep_time (cfg.seconds());
           
          while ( sleep_time != ACE_Time_Value::zero)
            {
              ACE_Countdown_Time countdown ( & sleep_time );

              ACE_OS::sleep (sleep_time );
            }


          if (cfg.seconds () == 0)
            {
              // comment this later
              char c;
              cout << "Press any key to stop=>" << flush;
              cin.clear ();
              cin >> c;
            }
        }
Exemplo n.º 6
0
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  ACE_START_TEST (ACE_TEXT ("TM_Test"));

  if (cfg.parse_args (argc, argv) < 0)
    return -1;

  disable_signal (ACE_SIGRTMIN, ACE_SIGRTMAX);
  disable_signal (SIGPIPE, SIGPIPE);
  disable_signal (SIGIO, SIGIO);

  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("FD_SETSIZE=%d ACE_FDSETSIZE=%d\n"),
              FD_SETSIZE,
              ACE_FD_SETSIZE));

  ACE_DEBUG ((LM_DEBUG,
             "s_blksize=%u r_blksize=%u win_size=%u\n",
              cfg.s_blksize(),
              cfg.r_blksize(),
              cfg.w_size()));


  int rc = 0;

  TP_ReactorTask     task1(cfg);
  RecvFactory        r_factory;
  SendFactory        s_factory;
  TConnectionManager r_mgr (task1, "RManager");
  TConnectionManager s_mgr (task1, "SManager");

  TAcceptor  acceptor (r_factory, r_mgr);
  TConnector connector(s_factory, s_mgr);
  


  ACE_Time_Value time_begin = ACE_OS::gettimeofday ();
  ACE_Time_Value time_end = ACE_OS::gettimeofday ();
  ACE_Time_Value time_run;

  if (task1.start () == 0)
    {
      if (cfg.both() != 0 || cfg.connections () == 0) // Acceptor
        {
          if (acceptor.start (ACE_INET_Addr (cfg.listen_port())) == 0)
            rc = 1;
        }
      
      if (cfg.both() != 0 || cfg.connections () > 0) // Connector
        {
          ACE_INET_Addr addr;

          addr.set (cfg.connect_port(), cfg.connect_host());

          rc += connector.start (addr, cfg.connections ());
        }

      time_begin = ACE_OS::gettimeofday ();

      if (rc > 0)
        {
          task1.enable_event_loop();
          
          ACE_Time_Value  sleep_time (cfg.seconds());
           
          while ( sleep_time != ACE_Time_Value::zero)
            {
              ACE_Countdown_Time countdown ( & sleep_time );

              ACE_OS::sleep (sleep_time );
            }

          if (cfg.seconds() == 0)
            {
              // comment this later
              char c;
              cout << "Press any key to stop=>" << flush;
              cin.clear ();
              cin >> c;
            }
        }
Exemplo n.º 7
0
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  ACE_START_TEST (ACE_TEXT ("W_Test"));


  if (cfg.parse_args (argc, argv) < 0)
    return -1;

  disable_signal (ACE_SIGRTMIN, ACE_SIGRTMAX);
  disable_signal (SIGPIPE, SIGPIPE);
  disable_signal (SIGIO, SIGIO);

  //ACE_DEBUG ((LM_DEBUG,
  //            ACE_TEXT ("FD_SETSIZE=%d ACE_FDSETSIZE=%d\n"),
  //            FD_SETSIZE,
  //            ACE_FD_SETSIZE));

  ACE_DEBUG ((LM_DEBUG,
             "s_blksize=%u r_blksize=%u win_size=%u\n",
              cfg.s_blksize(),
              cfg.r_blksize(),
              cfg.w_size()));


  ACE_SSL_Context *context = ACE_SSL_Context::instance ();
  // Note - the next two strings are naked on purpose... the arguments to
  // the ACE_SSL_Context methods are const char *, not ACE_TCHAR *.
  context->certificate ("dummy.pem", SSL_FILETYPE_PEM);
  context->private_key ("key.pem", SSL_FILETYPE_PEM);


  {
  int rc = 0;

  ProactorTask task1(cfg);

  RecvFactory    r_factory;
  RecvFactorySSL r_ssl_factory;

  PConnectionManager r_manager     (task1, r_factory,"R_Manager");
  PConnectionManager r_ssl_manager (task1, r_ssl_factory,"R_SSL_Manager");

  Acceptor  acceptor     (r_manager);
  Acceptor  acceptor_ssl (r_ssl_manager);

  ACE_Time_Value time_begin = ACE_OS::gettimeofday ();
  ACE_Time_Value time_end = ACE_OS::gettimeofday ();
  ACE_Time_Value time_run;

  if (task1.start () == 0)
    {
      ACE_Time_Value timeout (cfg.timeout(), 0);
      r_manager.set_timeout (timeout);

      // Simplify, initial read with zero size
      if (acceptor.start (ACE_INET_Addr (cfg.listen_port())) == 0)
        rc = 1;

      if (acceptor_ssl.start (ACE_INET_Addr (cfg.listen_port()+1)) == 0)
        rc = 1;

      time_begin = ACE_OS::gettimeofday ();

      if (rc > 0)
        {
          task1.enable_event_loop();
          
          char c;
          cout << "Press any key to stop=>" << flush;
          cin.clear ();
          cin >> c;
        }
    }
Exemplo n.º 8
0
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  ACE_START_TEST (ACE_TEXT ("U_Test"));


  if (cfg.parse_args (argc, argv) < 0)
    return -1;

  disable_signal (ACE_SIGRTMIN, ACE_SIGRTMAX);
  disable_signal (SIGPIPE, SIGPIPE);
  disable_signal (SIGIO, SIGIO);

//  ACE_DEBUG ((LM_DEBUG,
//              ACE_TEXT ("FD_SETSIZE=%d ACE_FDSETSIZE=%d\n"),
//              FD_SETSIZE,
//              ACE_FD_SETSIZE));

  ACE_DEBUG ((LM_DEBUG,
             "s_blksize=%u r_blksize=%u win_size=%u\n",
              cfg.s_blksize(),
              cfg.r_blksize(),
              cfg.w_size()));


  {
  int rc = 0;

  ProactorTask    task1(cfg);
  DOwner      acceptor(task1);
  DOwner      connector(task1);

  ACE_Time_Value time_begin = ACE_OS::gettimeofday ();
  ACE_Time_Value time_end = ACE_OS::gettimeofday ();
  ACE_Time_Value time_run;

  if (task1.start () == 0)
    {
      if (cfg.both() != 0 || cfg.connections () == 0) // Acceptor
        {
          // Simplify, initial read with zero size
          if (acceptor.start_receiver(ACE_INET_Addr (cfg.listen_port())) == 0)
            rc = 1;
        }

      if (cfg.both() != 0 || cfg.connections () > 0) // Connector
        {
          ACE_INET_Addr addr;

          addr.set (cfg.connect_port(),
                    cfg.connect_host());

          for (u_int i=0; i < cfg.connections (); ++i, ++rc)
            {
              if (connector.start_sender (addr) != 0)
                break;

            }
        }

      time_begin = ACE_OS::gettimeofday ();

      if (rc > 0)
        {
          task1.enable_event_loop();
          
          ACE_Time_Value  sleep_time (cfg.seconds());
           
          while ( sleep_time != ACE_Time_Value::zero)
            {
              ACE_Countdown_Time countdown ( & sleep_time );

              ACE_OS::sleep (sleep_time );
            }


          if (cfg.seconds () == 0)
            {
              // comment this later
              char c[80];

              for (;;)
                {
                  cout << "Press any key to stop=>" << flush;

                  cin.clear ();
                  cin.getline(c, 80);

                  switch (tolower(c[0]))
                  {
                  case 'p':
                    connector.post_all ();
                    acceptor.post_all ();
                    continue;
                  default:
                    break;
                  }
                  break;
                }

            }
        }
    }


  u_int  num_ssn_s = connector.get_number_connections ();
  u_int  num_ssn_r = acceptor.get_number_connections ();


  // Cancel all pending AIO on Connector and Senders
  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("(%t)******* Cancel Connector/Senders: connections_=%d\n"),
              connector.get_number_connections ()));
  connector.cancel_all ();
 
  //Cancel all pending AIO on Acceptor And Receivers
  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("(%t)******* Cancel Acceptor/Receivers:connections_=%d\n"),
              acceptor.get_number_connections ()
            ));
  acceptor.cancel_all ();
   

  while ( connector.get_number_connections () > 0 ||
          acceptor.get_number_connections () > 0 )
    {
        task1.wait_signal ();
    }


  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("(%t) Stop Thread Pool Task\n")));

  task1.stop ();
 

  // As Proactor event loop now is inactive it is safe to destroy all
  // Senders
  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("(%t)******** Stop Connector/Senders: connections_=%d\n"),
              connector.get_number_connections ()));
  connector.stop ();

  // As Proactor event loop now is inactive it is safe to destroy all
  // Receivers
  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("(%t)******** Stop Acceptor/Receivers:connections_=%d\n"),
              acceptor.get_number_connections ()));
  acceptor.stop ();

  time_end = ACE_OS::gettimeofday ();
  time_run = time_end - time_begin;

  u_long snd_bytes_s = connector.get_total_snd();
  u_long rcv_bytes_s = connector.get_total_rcv();
  u_long snd_op_s = connector.get_total_w();
  u_long rcv_op_s = connector.get_total_r();

  u_long snd_bytes_r = acceptor.get_total_snd();
  u_long rcv_bytes_r = acceptor.get_total_rcv();
  u_long snd_op_r = acceptor.get_total_w();
  u_long rcv_op_r = acceptor.get_total_r();

  //Print statistic
  ACE_TCHAR bufs [256];
  ACE_TCHAR bufr [256];

  ACE_OS::sprintf (bufs, ACE_TEXT ("%lu(%lu)"),
                   snd_bytes_s,
                   snd_op_s);

  ACE_OS::sprintf (bufr, ACE_TEXT ("%lu(%lu)"),
                   rcv_bytes_s,
                   rcv_op_s);

  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("Connector/Senders  total bytes: snd=%s rcv=%s\n"),
              bufs,
              bufr));

  ACE_OS::sprintf (bufs, ACE_TEXT ("%lu(%lu)"),
                   snd_bytes_r,
                   snd_op_r);

  ACE_OS::sprintf (bufr, ACE_TEXT ("%lu(%lu)"),
                   rcv_bytes_r,
                   rcv_op_r);
  
  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("Acceptor/Receivers total bytes: snd=%s rcv=%s\n"),
              bufs,
              bufr));

  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("Threads = %d BlkSize=%d\n"),
              cfg.threads(),
              cfg.blksize()));

  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("Sessions = %d (%d) \n"),
              rc-1,
              cfg.connections ()));


  float  fsec = (float)(time_run.msec()/1000);
  double fspeed = ((float) snd_bytes_s
                  +(float) snd_bytes_r
                  +(float) rcv_bytes_s
                  +(float) rcv_bytes_r
                  );

  if ( fsec > 0.1 )
    fspeed /= fsec; 

  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("Effective run time = %f sec\n"),
              fsec));


  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("Effective bytes/sec = %f\n"),
              fspeed));



  } // ProactorTask

  ACE_END_TEST;

  return 0;
}
Exemplo n.º 9
0
int
run_main (int argc, ACE_TCHAR *argv[])
{
  ACE_START_TEST (ACE_TEXT ("TP_Reactor_Test"));

#if defined(ACE_HAS_THREADS)
  if (::parse_args (argc, argv) == -1)
    return -1;

  disable_signal (SIGPIPE, SIGPIPE);

  MyTask    task1;
  Acceptor  acceptor;
  Connector connector;

  if (task1.start (threads) == 0)
    {
      int rc = 0;

      ACE_INET_Addr addr (port);
      if (both != 0 || host == 0) // Acceptor
        rc += acceptor.start (addr);

      if (both != 0 || host != 0)
        {
          if (host == 0)
            host = ACE_LOCALHOST;

          if (addr.set (port, host, 1, addr.get_type ()) == -1)
            ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), host));
          rc += connector.start (addr, senders);

        }

      if (rc > 0)
        ACE_OS::sleep (seconds);
    }

  task1.stop ();

  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("\nNumber of Receivers objects = %d\n")
              ACE_TEXT ("\nNumber of Sender objects = %d\n"),
              acceptor.get_number_sessions (),
              connector.get_number_sessions ()));

  // As Reactor event loop now is inactive it is safe to destroy all
  // senders

  connector.stop ();
  acceptor.stop ();

  //Print statistic
  ACE_TCHAR bufs [256];
  ACE_TCHAR bufr [256];

  ACE_OS::sprintf ( bufs , ACE_TEXT ("%ld(%ld)"),
                    connector.get_total_snd(),
                    connector.get_total_w() );

  ACE_OS::sprintf ( bufr , ACE_TEXT ("%ld(%ld)"),
                    connector.get_total_rcv(),
                    connector.get_total_r() );

  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("Connector/Senders  total bytes: snd=%s rcv=%s\n"),
              bufs,
              bufr
            ));

  ACE_OS::sprintf ( bufs , ACE_TEXT ("%ld(%ld)"),
                    acceptor.get_total_snd(),
                    acceptor.get_total_w() );

  ACE_OS::sprintf ( bufr , ACE_TEXT ("%ld(%ld)"),
                    acceptor.get_total_rcv(),
                    acceptor.get_total_r() );

  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("Acceptor/Receivers total bytes: snd=%s rcv=%s\n"),
              bufs,
              bufr
            ));

#else /* ACE_HAS_THREADS */
   ACE_UNUSED_ARG( argc );
   ACE_UNUSED_ARG( argv );
#endif /* ACE_HAS_THREADS */

  ACE_END_TEST;

  return 0;
}