Example #1
0
/*
static struct sigaction sa={
   .sa_handler = SIG_IGN
};
*/
int server(int port, int maxevents)
{
 
  // sigaction(SIGINT, &sa, 0);
  // sigaction(SIGTERM, &sa, 0);  
   
   int srv_fd = -1;
   int epoll_fd = -1;
	reactor* r = 0;
	event_handler* seh = 0;
   
   if((srv_fd=create_server(port,"127.0.0.1")) == -1){
      return -1;
   }
   if((epoll_fd = create_epoll(srv_fd, maxevents)) == -1){
      return -1;
   }
   r = create_reactor(epoll_fd, maxevents);
	seh = create_acceptor(srv_fd, r);
	r->add_eh(r, seh);
   r->event_loop(r);
   
   destroy_reactor(r);
   os_close(srv_fd);
   os_close(epoll_fd);
	return 0;
}
Example #2
0
File: main.c Project: krodzik/ncm
int main(int argc, const char *argv[])
{
	// Read arguments from "config.cfg" file and printing them
	int port;
	int max_clients;
	if(get_config(&port, &max_clients))
		return(-1);

	// Main
	int srv_fd = -1;
	int epoll_fd = -1;

	reactor* r = 0;
	event_handler* seh = 0;

	if (init_server(&srv_fd, &epoll_fd, port, max_clients) != 0)
		return 1;

	r  = create_reactor(epoll_fd, max_clients);
	seh = create_acceptor(srv_fd, r);
	r->add_eh(r, seh);

	r->event_loop(r);

	return 0;
}
int
run_main (int argc, ACE_TCHAR *argv[])
{
  ACE_START_TEST (ACE_TEXT ("Reactor_Performance_Test"));

  //FUZZ: disable check_for_lack_ACE_OS
  ACE_Get_Opt getopt (argc, argv, ACE_TEXT ("dswc:l:"), 1);
  for (int c; (c = getopt ()) != -1; )
  //FUZZ: enble check_for_lack_ACE_OS
    switch (c)
      {
      case 's':
        opt_select_reactor = 1;
        break;
      case 'w':
        opt_wfmo_reactor = 1;
        break;
      case 'c':
        opt_nconnections = ACE_OS::atoi (getopt.opt_arg ());
        break;
      case 'l':
        opt_nloops = ACE_OS::atoi (getopt.opt_arg ());
        break;
      case 'd':
        opt_debug = 1;
        break;
      }

  // Sets up the correct reactor (based on platform and options).
  create_reactor ();

  // Manage memory automagically.
  auto_ptr<ACE_Reactor> reactor (ACE_Reactor::instance ());
  auto_ptr<ACE_Reactor_Impl> impl;

  // If we are using other that the default implementation, we must
  // clean up.
  if (opt_select_reactor || opt_wfmo_reactor)
    {
      auto_ptr<ACE_Reactor_Impl> auto_impl (ACE_Reactor::instance ()->implementation ());
      impl = auto_impl;
    }

  Read_Handler::set_countdown (opt_nconnections);

  // Acceptor
  ACCEPTOR acceptor;
  ACE_INET_Addr server_addr;

  // Bind acceptor to any port and then find out what the port was.
  ACE_INET_Addr local_addr (ACE_sap_any_cast (const ACE_INET_Addr &));
  if (acceptor.open (local_addr) == -1
      || acceptor.acceptor ().get_local_addr (server_addr) == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT ("(%t) %p\n"),
                       ACE_TEXT ("open")),
                      -1);

  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("(%t) starting server at port %d\n"),
              server_addr.get_port_number ()));

  ACE_INET_Addr connection_addr (server_addr.get_port_number (),
                                 ACE_DEFAULT_SERVER_HOST);

  if (ACE_Thread_Manager::instance ()->spawn
      (ACE_THR_FUNC (client),
       (void *) &connection_addr,
       THR_NEW_LWP | THR_DETACHED) == -1)
    ACE_ERROR ((LM_ERROR,
                ACE_TEXT ("(%t) %p\n"),
                ACE_TEXT ("thread create failed")));

  ACE_Time_Value run_limit (opt_nloops / 10);

  ACE_Profile_Timer timer;
  timer.start ();
  const int status =
    ACE_Reactor::instance ()->run_reactor_event_loop (run_limit);
  timer.stop ();

  ACE_Profile_Timer::ACE_Elapsed_Time et;
  timer.elapsed_time (et);

  // Print results
  print_results (et);

  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("(%t) waiting for the client thread...\n")));

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

  ACE_END_TEST;
  return status;
}
int
run_main (int argc, ACE_TCHAR *argv[])
{
  ACE_START_TEST (ACE_TEXT ("Notify_Performance_Test"));

  //FUZZ: disable check_for_lack_ACE_OS
  ACE_Get_Opt getopt (argc, argv, ACE_TEXT ("pswdc:l:"));

  for (int c; (c = getopt ()) != -1; )
    switch (c)
      {
  //FUZZ: enable check_for_lack_ACE_OS
      case 'p':
        opt_dev_poll_reactor = 1;
        break;
      case 's':
        opt_select_reactor = 1;
        break;
      case 'w':
        opt_wfmo_reactor = 1;
        break;
      case 'c':
        opt_nthreads = ACE_OS::atoi (getopt.opt_arg ());
        break;
      case 'l':
        opt_nloops = ACE_OS::atoi (getopt.opt_arg ());
        break;
      case 'd':
        opt_pass_notify_data = 1;
        break;
      }

  // Sets up the correct reactor (based on platform and options)
  create_reactor ();

  // Manage memory automagically.
  auto_ptr<ACE_Reactor> reactor (ACE_Reactor::instance ());
  auto_ptr<ACE_Reactor_Impl> impl;

  // If we are using other that the default implementation, we must
  // clean up.
  if (opt_select_reactor || opt_wfmo_reactor || opt_dev_poll_reactor)
    {
      auto_ptr<ACE_Reactor_Impl> auto_impl (ACE_Reactor::instance ()->implementation ());
      impl = auto_impl;
    }

  // Callback object
  Handler handler;

  // Spawn worker threads
  if (ACE_Thread_Manager::instance ()->spawn_n
      (opt_nthreads,
       ACE_THR_FUNC (client),
       (void *) &handler,
       THR_NEW_LWP | THR_DETACHED) == -1)
    ACE_ERROR ((LM_ERROR, ACE_TEXT ("(%P|%t) %p\n%a"), ACE_TEXT ("thread create failed")));

  // Timer business
  ACE_Profile_Timer timer;
  timer.start ();

  // Run event loop
  ACE_Reactor::instance()->run_reactor_event_loop ();

  timer.stop ();

  ACE_Profile_Timer::ACE_Elapsed_Time et;
  timer.elapsed_time (et);

  // Print results
  print_results (et);

  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("(%P|%t) waiting for the worker threads...\n")));

  // Wait for all worker to get done.
  ACE_Thread_Manager::instance ()->wait ();

  ACE_END_TEST;
  return 0;
}
Example #5
0
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  int result = 0;

  //FUZZ: disable check_for_lack_ACE_OS
  // Parse args
  ACE_Get_Opt getopt (argc, argv, ACE_TEXT ("swmc"), 1);

  for (int c; (c = getopt ()) != -1; )
  //FUZZ: enable check_for_lack_ACE_OS
    switch (c)
      {
      case 's':
        opt_select_reactor = 1;
        break;
      case 'w':
        opt_wfmo_reactor = 1;
        break;
      case 'm':
        write_to_pipe_in_main = 1;
        break;
      case 'c':
        cancel_reads = 1;
        break;
      }

  // Create pipes
  ACE_Pipe pipe1, pipe2;

  result = pipe1.open ();
  ACE_ASSERT (result == 0);

  result = pipe2.open ();
  ACE_ASSERT (result == 0);

  // Create handlers
  Handler handler (pipe1);
  Different_Handler different_handler (pipe2);

  // Manage memory automagically.
  auto_ptr<ACE_Reactor> reactor (create_reactor ());

  // Register handlers
  ACE_Reactor_Mask handler_mask =
    ACE_Event_Handler::READ_MASK |
    ACE_Event_Handler::WRITE_MASK |
    ACE_Event_Handler::EXCEPT_MASK;

  ACE_Reactor_Mask different_handler_mask =
    ACE_Event_Handler::WRITE_MASK |
    ACE_Event_Handler::EXCEPT_MASK;

  result = reactor->register_handler (&handler,
                                      handler_mask);
  ACE_ASSERT (result == 0);

  result = reactor->register_handler (&different_handler,
                                      different_handler_mask);
  ACE_ASSERT (result == 0);

  // Write to the pipe; this causes handle_input to get called.
  if (write_to_pipe_in_main)
    {
      write_to_pipe (pipe1);
      write_to_pipe (pipe2);
    }

  // Note that handle_output will get called automatically since the
  // pipe is writable!

  //FUZZ: disable check_for_lack_ACE_OS
  // Run for three seconds
  ACE_Time_Value time (3);
  //FUZZ: enable check_for_lack_ACE_OS

  reactor->run_reactor_event_loop (time);

  ACE_DEBUG ((LM_DEBUG, "\nClosing down the application\n\n"));

  return 0;
}
Example #6
0
int
run_main (int argc, ACE_TCHAR *argv[])
{
  u_short port = 0;

  if (argc == 1)
    {
      // This is the "master" process.

      ACE_START_TEST (ACE_TEXT ("MEM_Stream_Test"));
      create_reactor ();
      ACE_MEM_Addr server_addr (port);

      reset_handler (NUMBER_OF_REACTIVE_CONNECTIONS);

      test_reactive (argc > 0 ? argv[0] : ACE_TEXT ("MEM_Stream_Test"), server_addr);

      ACE_Reactor::instance ()->reset_reactor_event_loop ();

#if !defined (ACE_WIN32) && defined (_ACE_USE_SV_SEM)
      ACE_ERROR ((LM_DEBUG,
                  ACE_TEXT ("\n *** Platform only supports non-scalable SysV semaphores ***\n\n")));
#endif /* !ACE_WIN32 && _ACE_USE_SV_SEM */
      reset_handler (NUMBER_OF_MT_CONNECTIONS);

      test_concurrent (argc > 0 ? argv[0] : ACE_TEXT ("MEM_Stream_Test"), server_addr);

      ACE_END_TEST;
      return 0;
    }
  else
    {
      // We end up here if this is a child process spawned for one of
      // the test passes.  command line is: -p <port> -r (reactive) |
      // -m (multithreaded)

      ACE_TCHAR lognm[MAXPATHLEN];
      int mypid (ACE_OS::getpid ());
      ACE_OS::sprintf(lognm, ACE_TEXT ("MEM_Stream_Test-%d"), mypid);
      ACE_START_TEST (lognm);

      ACE_Get_Opt opts (argc, argv, ACE_TEXT ("p:rm"));
      int opt, iport, status;
      ACE_MEM_IO::Signal_Strategy model = ACE_MEM_IO::Reactive;

      while ((opt = opts()) != -1)
        {
          switch (opt)
            {
            case 'p':
              iport = ACE_OS::atoi (opts.opt_arg ());
              port = static_cast <u_short> (iport);
              break;

            case 'r':
              model = ACE_MEM_IO::Reactive;
              break;

            case 'm':
              model = ACE_MEM_IO::MT;
              break;

            default:
              ACE_ERROR_RETURN ((LM_ERROR,
                                 ACE_TEXT ("Invalid option (-p <port> -r | -m)\n")),
                                1);
            }
        }
      status = run_client (port, model);
      ACE_END_TEST;
      return status;
    }
}
Example #7
0
int
main (int argc, char *argv[])
{
  int result = 0;

  // Parse args
  ACE_Get_Opt getopt (argc, argv, ACE_TEXT ("swmc"), 1);
  for (int c; (c = getopt ()) != -1; )
    switch (c)
      {
      case 's':
        opt_select_reactor = 1;
        break;
      case 'w':
        opt_wfmo_reactor = 1;
        break;
      case 'm':
        write_to_pipe_in_main = 1;
        break;
      case 'c':
        cancel_reads = 1;
        break;
      }

  // Create pipes
  ACE_Pipe pipe1, pipe2;

  result = pipe1.open ();
  ACE_ASSERT (result == 0);

  result = pipe2.open ();
  ACE_ASSERT (result == 0);

  // Create handlers
  Handler handler (pipe1);
  Different_Handler different_handler (pipe2);

  // Create reactor
  create_reactor ();

  // Manage memory automagically.
  auto_ptr<ACE_Reactor> reactor (ACE_Reactor::instance ());
  auto_ptr<ACE_Reactor_Impl> impl;

  // If we are using other that the default implementation, we must
  // clean up.
  if (opt_select_reactor || opt_wfmo_reactor)
    impl = auto_ptr<ACE_Reactor_Impl> (ACE_Reactor::instance ()->implementation ());

  // Register handlers
  ACE_Reactor_Mask handler_mask =
    ACE_Event_Handler::READ_MASK |
    ACE_Event_Handler::WRITE_MASK |
    ACE_Event_Handler::EXCEPT_MASK;

  ACE_Reactor_Mask different_handler_mask =
    ACE_Event_Handler::WRITE_MASK |
    ACE_Event_Handler::EXCEPT_MASK;

  result = ACE_Reactor::instance ()->register_handler (&handler,
                                                       handler_mask);
  ACE_ASSERT (result == 0);

  result = ACE_Reactor::instance ()->register_handler (&different_handler,
                                                       different_handler_mask);
  ACE_ASSERT (result == 0);

  // Write to the pipe; this causes handle_input to get called.
  if (write_to_pipe_in_main)
    {
      write_to_pipe (pipe1);
      write_to_pipe (pipe2);
    }

  // Note that handle_output will get called automatically since the
  // pipe is writable!

  // Run for three seconds
  ACE_Time_Value time (3);
  ACE_Reactor::instance ()->run_event_loop (time);

  ACE_DEBUG ((LM_DEBUG, "\nClosing down the application\n\n"));

  return 0;
}