Ejemplo n.º 1
0
static void
test_for_spin (ACE_Reactor &reactor)
{
  Handler handler (reactor, true);

  // This should trigger a call to <handle_input>.
  ssize_t result =
    ACE::send_n (handler.pipe_.write_handle (),
                 message,
                 ACE_OS::strlen (message));
  if (result != ssize_t (ACE_OS::strlen (message)))
    ACE_ERROR ((LM_ERROR, ACE_TEXT ("Handler sent %b bytes; should be %B\n"),
                result, ACE_OS::strlen (message)));

  reactor.run_reactor_event_loop ();

  if (0 != reactor.remove_handler (handler.pipe_.read_handle (),
                                   ACE_Event_Handler::ALL_EVENTS_MASK |
                                   ACE_Event_Handler::DONT_CALL))
    ACE_ERROR ((LM_ERROR,
                ACE_TEXT ("%p\n"),
                ACE_TEXT ("test_for_spin, remove pipe")));

  if (0 == reactor.remove_handler (handler.other_pipe_.write_handle (),
                                   ACE_Event_Handler::ALL_EVENTS_MASK |
                                   ACE_Event_Handler::DONT_CALL))
    ACE_ERROR ((LM_ERROR,
                ACE_TEXT ("test_for_spin remove other_pipe succeeded ")
                ACE_TEXT ("but shouldn't\n")));
}
Ejemplo n.º 2
0
static ACE_THR_FUNC_RETURN event_loop (void *arg) {
  ACE_Reactor *reactor = static_cast<ACE_Reactor *> (arg);

  reactor->owner (ACE_OS::thr_self ());
  reactor->run_reactor_event_loop ();
  return 0;
}
Ejemplo n.º 3
0
int
Task::svc()
{
  ACE_DEBUG ((LM_DEBUG, "(%P|%t) Starting thread for %s\n", endpoint_));
  (void) reactor_.run_reactor_event_loop();
  return 0;
}
Ejemplo n.º 4
0
int
run_main (int, ACE_TCHAR *[])
{
  ACE_START_TEST (ACE_TEXT ("Timer_Cancellation_Test"));

  ACE_Reactor reactor (new ACE_TP_Reactor,
                       1);

  Deadlock deadlock;
  deadlock.reactor (&reactor);

  Event_Handler handler (deadlock);

  // Scheduler a timer to kick things off.
  reactor.schedule_timer (&handler,
                          0,
                          ACE_Time_Value (1));

  // Run the event loop for a while.
  ACE_Time_Value timeout (4);
  reactor.run_reactor_event_loop (timeout);

  ACE_END_TEST;

  return 0;
}
Ejemplo n.º 5
0
    void run ()
    {
        uint16 raport = sConfig.GetIntDefault ("Ra.Port", 3443);
        std::string stringip = sConfig.GetStringDefault ("Ra.IP", "0.0.0.0");

        ACE_INET_Addr listen_addr(raport, stringip.c_str());

        if (m_Acceptor->open (listen_addr, m_Reactor, ACE_NONBLOCK) == -1)
        {
            sLog.outError ("MaNGOS RA can not bind to port %d on %s", raport, stringip.c_str ());
        }

        sLog.outString ("Starting Remote access listner on port %d on %s", raport, stringip.c_str ());

        while (!m_Reactor->reactor_event_loop_done())
        {
            ACE_Time_Value interval (0, 10000);

            if (m_Reactor->run_reactor_event_loop (interval) == -1)
                break;

            if(World::IsStopped())
            {
                m_Acceptor->close();
                break;
            }
        }
        sLog.outString("RARunnable thread ended");
    }
Ejemplo n.º 6
0
/**
 * This is the function run by all threads in the thread pool.
 *
 * @param arg is expected to be of type (ACE_Reactor *)
 */
ACE_THR_FUNC_RETURN threadFunc(void *arg) {
    ACE_TRACE("threadFunc(void *)");

    ACE_Reactor *reactor = (ACE_Reactor *) arg;
    reactor->run_reactor_event_loop();

    return 0;
}
Ejemplo n.º 7
0
static void *run_reactor (void *pReactor)
{
    ACE_Reactor *pLogReactor = (ACE_Reactor *)pReactor;

    pLogReactor->owner(ACE_Thread_Manager::instance ()->thr_self());
    pLogReactor->run_reactor_event_loop ();

    ACE_DEBUG((LM_INFO, ACE_TEXT("(%P|%t) %M run_reactor exit[%N,%l]\n")));
    return 0;
}
Ejemplo n.º 8
0
int main(int argc, char *argv[])
{
    ACE_Reactor reactor;
    Server_Logging_Deamon *server = 0;
    ACE_NEW_RETURN(server, Server_Logging_Deamon(argc, argv, &reactor), 1);

    if (reactor.run_reactor_event_loop() == -1)
        ACE_ERROR_RETURN((LM_ERROR, "%p\n", "run_reactor_event_loop()"), 1);

    return 0;
}
Ejemplo n.º 9
0
int main(int argc, char* argv[])
{
	ACE_Reactor reactor;
	ACE_Acceptor<EchoServerHandler, ACE_SOCK_Acceptor> echoServerAcceptor;

	if (echoServerAcceptor.open(ACE_INET_Addr(DEFAULT_PORT), &reactor) == -1)
		return 1;

	reactor.run_reactor_event_loop();

	return 0;
}
Ejemplo n.º 10
0
//for ACE_TP_Reactor
static ACE_THR_FUNC_RETURN event_loop (void *arg)
{
    //ACE_Reactor *reactor = ACE_static_cast(ACE_Reactor *, arg);
    ACE_Reactor *reactor = static_cast< ACE_Reactor *> (arg);

    ACE_DEBUG((LM_INFO, "[%D] ace tp reactor event loop, tid=%d,pid=%d\n"
            , ACE_OS::thr_self ()
            , ACE_OS::getpid()
            ));
    
    reactor->owner(ACE_OS::getpid());
    reactor->run_reactor_event_loop ();
    return 0;
}
Ejemplo n.º 11
0
int
run_main (int, ACE_TCHAR *[])
{
  ACE_START_TEST (ACE_TEXT ("Bug_1890_Regression_Test"));

  bool success = true;

  // Bug 1890 is all about ACE_Select_Reactor, so run it on that reactor
  // regardless of platform.
  ACE_Select_Reactor *impl_ptr = 0;
  ACE_NEW_RETURN (impl_ptr, ACE_Select_Reactor, -1);
  auto_ptr<ACE_Select_Reactor> auto_impl (impl_ptr);

  ACE_Reactor reactor (impl_ptr);

  // Create the timer, this is the main driver for the test
  Timer * timer = new Timer;

  // Initialize the timer and register with the reactor
  if (-1 == timer->open (&reactor))
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         ACE_TEXT ("%p\n"),
                         ACE_TEXT ("Cannot initialize timer")),
                        -1);
    }

  reactor.run_reactor_event_loop ();

  // Verify that the results are what we expect
  if (!(success = timer->check_expected_results ()))
    ACE_ERROR ((LM_ERROR, ACE_TEXT ("Test failed\n")));

  // Cleanup
  timer->close ();
  delete timer;

  ACE_END_TEST;

  return success ? 0 : -1;
}
Ejemplo n.º 12
0
void testNativeReactor (int, ACE_TCHAR *[])
{
  ACE_DEBUG ((LM_INFO, ACE_TEXT ("Testing autotest using native reactor\n")));

  ACE_Reactor      reactor;
  HandlersRegister handlersRegister (&reactor);
  ACE_Time_Value   testTime (TotalTestTime / 1000, (TotalTestTime % 1000) * 1000);

  if (0 <= handlersRegister.scheduleTimers (testTime)  &&
      0 <= handlersRegister.registerDgramHandlers () &&
      0 <= handlersRegister.registerTCPHandlers ())
    {
      reactor.run_reactor_event_loop (testTime);

      if (0  != handlersRegister.analyze ())
        ACE_ERROR ((LM_ERROR,
                    ACE_TEXT ("Test failed for native reactor. "
                              "Fix QtReactor_Test or ACE_Reactor.\n")));
      else
        ACE_ERROR ((LM_INFO, ACE_TEXT ("Test seems to work with native reactor.\n")));
    }
}
Ejemplo n.º 13
0
/* Program's entry point */
int ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
  ACE_OS::printf("Usage: %s [port-number]\n", argv[0]);
  u_short port = argc < 2 ? ACE_DEFAULT_SERVER_PORT : ACE_OS::atoi(argv[1]);
  ACE_INET_Addr addr(port);

  ACE_DEBUG((LM_DEBUG,
	     "(%t) Program's entry point\n"));

  ACE_OS::printf("listening at port %d\n", port);

  // Implement a main() function that:

  //1. Creates an Echo_Task instance and have it spawn a pool of N threads
  // (where N > 1) within itself (Echo_Task::activate()).
  Echo_Task echo_task;
  Echo_Task *ptask = &echo_task;
  //Create POOL_SIZE kernel-level threads and allow the new threads to be joined with.
  echo_task.activate(THR_NEW_LWP | THR_JOINABLE, POOL_SIZE);  

  ///2. Creates an Echo_Acceptor instance and associate it with the Echo_Task.
  Echo_Acceptor acceptor;
  acceptor.echo_task(ptask); // Using a setter method defined in Echo_Acceptor

  //3. Creates an  ACE_Reactor(or use the singleton instance of the ACE_Reactor)
  ACE_Reactor *reactor = ACE_Reactor::instance();
	
  //4. Registers the Echo_Acceptor instance with the reactor
  acceptor.open(addr, reactor);

  //5. Run the reactor's event loop [ACE_Reactor::run_reactor_event_loop()] 
  // to wait for connections/data to arrive from a client. 
  reactor->run_reactor_event_loop();

  // Wait for all threads to exit
  ACE_Thread_Manager::instance()->wait();

  return 0;
}
Ejemplo n.º 14
0
int
run_main (int, ACE_TCHAR *[])
{
  ACE_START_TEST (ACE_TEXT ("Bug_2540_Regression_Test"));

  // Bug 2540 is all about ACE_Select_Reactor, so run it on that reactor
  // regardless of platform. In particular, this test relies on a handler
  // that doesn't consume ready-to-read data being called back - this won't
  // happen with ACE_WFMO_Reactor.
  ACE_Select_Reactor select_reactor;
  ACE_Reactor reactor (&select_reactor);

  // Create the timer, this is the main driver for the test
  Timer * timer = new Timer;

  // Initialize the timer and register with the reactor
  if (-1 == timer->open (&reactor))
    {
      ACE_ERROR_RETURN ((LM_ERROR, "Cannot initialize timer\n"), -1);
    }

  reactor.run_reactor_event_loop ();

  // Verify that the results are what we expect
  if (!timer->check_expected_results ())
    {
      ACE_ERROR_RETURN ((LM_ERROR, "Test failed\n"), -1);
    }

  // Cleanup
  timer->close ();
  delete timer;

  ACE_END_TEST;

  return 0;
}
Ejemplo n.º 15
0
void
test (ACE_Reactor_Impl &reactor_impl,
      const char *reactor_type)
{
  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("\nTesting with %C\n\n"),
              reactor_type));

  ACE_Reactor reactor (&reactor_impl,
                       0);

  Event_Handler *e = new Event_Handler (reactor,
                                        ACE_INVALID_HANDLE,
                                        ACE_INVALID_HANDLE);
  if (!e->ok_)
    {
      ACE_ERROR ((LM_ERROR,
                  ACE_TEXT ("Error initializing test; aborting.\n")));
      delete e;
      return;
    }

  reactor.run_reactor_event_loop ();
}
static bool
test_reactor_dispatch_order (ACE_Reactor &reactor)
{
    Handler handler (reactor);
    if (!handler.ok_)
    {
        ACE_ERROR ((LM_ERROR, ACE_TEXT ("Error initializing test; abort.\n")));
        return false;
    }

    bool ok_to_go = true;

    // This should trigger a call to <handle_input>.
    ssize_t result =
        ACE::send_n (handler.pipe_.write_handle (),
                     message,
                     ACE_OS::strlen (message));
    if (result != ssize_t (ACE_OS::strlen (message)))
    {
        ACE_ERROR ((LM_ERROR, ACE_TEXT ("Handler sent %b bytes; should be %B\n"),
                    result, ACE_OS::strlen (message)));
        ok_to_go = false;
    }

    // This should trigger a call to <handle_timeout>.
    if (-1 == reactor.schedule_timer (&handler,
                                      0,
                                      ACE_Time_Value (0)))
    {
        ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("schedule_timer")));
        ok_to_go = false;
    }

    // Suspend the handlers - only the timer should be dispatched
    ACE_Time_Value tv (1);
    reactor.suspend_handlers ();
    reactor.run_reactor_event_loop (tv);

    // only the timer should have fired
    if (handler.dispatch_order_ != 2)
    {
        ACE_ERROR ((LM_ERROR, ACE_TEXT ("Incorrect number fired %d\n"),
                    handler.dispatch_order_));
        ok_to_go = false;
    }

    // Reset the dispatch_order_ count and schedule another timer
    handler.dispatch_order_ = 1;
    if (-1 == reactor.schedule_timer (&handler,
                                      0,
                                      ACE_Time_Value (0)))
    {
        ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("schedule_timer")));
        ok_to_go = false;
    }

    // Resume the handlers - things should work now
    reactor.resume_handlers ();

    if (ok_to_go)
    {
        reactor.run_reactor_event_loop (tv);
    }

    if (0 != reactor.remove_handler (handler.pipe_.read_handle (),
                                     ACE_Event_Handler::ALL_EVENTS_MASK |
                                     ACE_Event_Handler::DONT_CALL))
        ACE_ERROR ((LM_ERROR,
                    ACE_TEXT ("%p\n"),
                    ACE_TEXT ("remover_handler pipe")));

    if (handler.dispatch_order_ != 4)
    {
        ACE_ERROR ((LM_ERROR, ACE_TEXT ("Incorrect number fired %d\n"),
                    handler.dispatch_order_));
        ok_to_go = false;
    }

    return ok_to_go;
}
int ManageClientValidation::svc(void)
{
	FUNCTIONTRACE(ManageClientValidation::svc);
	REPORT_THREAD_INFO("ManageClientValidation::svc", ACE_OS::thr_self());

	ACE_Reactor * reactor = NULL;
	while (!m_stop)
	{

#ifdef WIN32
		reactor = new ACE_Reactor(new ACE_Select_Reactor(), true);
#else
		reactor = new ACE_Reactor(new ACE_Dev_Poll_Reactor(), true);
#endif

		LoginAcceptor login_acceptor;
		ACE_INET_Addr port_to_listen(sMsgCfg->getLSCfg().listen_port, sMsgCfg->getLSCfg().host.c_str());
		if (login_acceptor.open(port_to_listen, reactor) == -1)
		{
			GATE_LOG_ERROR(ACE_TEXT("Failed to call login_acceptor.open, host is <%s>, the port is <%d>, last error is <%d>\n"), sMsgCfg->getClientCfg().host.c_str(), sMsgCfg->getClientCfg().listen_port, ACE_OS::last_error());
			return 1;
		}

		ReportTrafficToLoginServer report_traffic;

		m_timer_id = reactor->schedule_timer(this, NULL, ACE_Time_Value(3, 0), ACE_Time_Value(3, 0));
		if (m_timer_id == -1)
		{
			GATE_LOG_ERROR(ACE_TEXT("Failed to schedule timer in ManageClientValidation::svc, last error is <%d>\n"), ACE_OS::last_error());
			return 1;
		}

		//m_report_traffic_timer_id = reactor->schedule_timer(&report_traffic, NULL, ACE_Time_Value(sMsgCfg->getLSCfg().report_interval), ACE_Time_Value(sMsgCfg->getLSCfg().report_interval));
		//if (m_report_traffic_timer_id == -1)
		//{
		//	GATELogp(LM_ERROR, ACE_TEXT("Failed to schedule timer in ManageClientValidation::svc for report traffic, last error is <%d>\n"), ACE_OS::last_error());
		//	return 1;
		//}

		//reactor->run_reactor_event_loop();
		while (true)
		{
			reactor->run_reactor_event_loop();
#ifdef WIN32
			break;
#else
			if (ACE_OS::last_error() == EINTR)
			{
				continue;
			}
			else
			{
				break;
			}
#endif
		}


		GATE_LOG_INFO(ACE_TEXT("Exit thread ManageClientValidation::svc, last error is <%d>\n"), ACE_OS::last_error());
	}

	delete reactor;

	m_wait = false;

	return 0;
}