本文整理汇总了C++中ACE_Reactor::handle_events方法的典型用法代码示例。如果您正苦于以下问题:C++ ACE_Reactor::handle_events方法的具体用法?C++ ACE_Reactor::handle_events怎么用?C++ ACE_Reactor::handle_events使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ACE_Reactor
的用法示例。
在下文中一共展示了ACE_Reactor::handle_events方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: while
static void *
dispatch (void *arg)
{
// every thread must register the same stream to write to file
if (out_stream)
{
ACE_LOG_MSG->set_flags (ACE_Log_Msg::OSTREAM);
ACE_LOG_MSG->msg_ostream (out_stream);
}
ACE_DEBUG ((LM_DEBUG, ACE_TEXT (" (%t) Dispatcher Thread started!\n")));
ACE_Reactor *r = reinterpret_cast <ACE_Reactor *> (arg);
int result;
r->owner (ACE_OS::thr_self ());
while (1)
{
result = r->handle_events ();
if (result <= 0)
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("Dispatch: handle_events (): %d"),
result));
}
ACE_NOTREACHED (return 0);
}
示例2: sa
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
ACE_Sig_Action sa ((ACE_SignalHandler) handler, SIGINT);
ACE_OS::signal (SIGCLD, SIG_IGN);
ACE_UNUSED_ARG (sa);
parse_args (argc, argv);
OUTPUT_FILE = ACE_OS::open (OUTPUT_FILE_NAME, O_CREAT | O_WRONLY, 0644);
if (OUTPUT_FILE == 0)
return 1;
ACE_Reactor reactor;
Handle_Events handle_events (UDP_PORT, MCAST_ADDR, INTERFACE, reactor);
// main loop
while (!done)
reactor.handle_events ();
ACE_OS::close (OUTPUT_FILE);
cout << "\nbenchd done.\n";
return 0;
}
示例3: ACE_TMAIN
// server main function
// uses a portable form of the "main" function along with its arguments
int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
// instantiate an object of the Proto Handler class
Proto_Handler proto;
// retrieve a reactor. Here we could have retrieved different
// implementations of reactor. For now we get the default singletom
// reactor.
ACE_Reactor *reactor = ACE_Reactor::instance ();
// initialize the proto handler object
if (proto.open (argc, argv, reactor) == -1) {
ACE_ERROR ((LM_ERROR, ACE_TEXT ("(%P|%t) %p\n"),
ACE_TEXT ("handler open")));
return -1;
}
// now let the server handle the events
for (;;) {
if (reactor->handle_events () == -1) {
ACE_ERROR ((LM_ERROR, ACE_TEXT ("(%P|%t) %p\n"),
ACE_TEXT ("handle events")));
return -1;
}
}
// return exit status
return 0;
}
示例4: timeout
static void *
worker (void *args)
{
ACE_Reactor *reactor = reinterpret_cast<ACE_Reactor *> (args);
// Make this thread the owner of the Reactor's event loop.
reactor->owner (ACE_Thread::self ());
// Use a timeout to inform the Reactor when to shutdown.
ACE_Time_Value timeout (4);
for (;;)
switch (reactor->handle_events (timeout))
{
case -1:
ACE_ERROR_RETURN ((LM_ERROR,
ACE_TEXT ("(%t) %p\n"),
ACE_TEXT ("reactor")),
0);
/* NOTREACHED */
case 0:
ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%t) Reactor shutdown\n")));
return 0;
}
ACE_NOTREACHED (return 0);
}
示例5: run
// This is run at program initialization
void CommandLineServer::run(void* args)
{
s_log = log4cxx::Logger::getLogger("interface.commandlineserver");
unsigned short tcpPort = (unsigned short)(unsigned long)args;
//unsigned short tcpPort = (unsigned short)*(int*)args;
CommandLineAcceptor peer_acceptor;
ACE_INET_Addr addr (tcpPort);
ACE_Reactor reactor;
CStdString tcpPortString = IntToString(tcpPort);
if (peer_acceptor.open (addr, &reactor) == -1)
{
LOG4CXX_ERROR(s_log, CStdString("Failed to start command line server on port:") + tcpPortString + CStdString(" do you have another instance of orkaudio running?"));
}
else
{
LOG4CXX_INFO(s_log, CStdString("Started command line server on port:")+tcpPortString);
for(;;)
{
reactor.handle_events();
}
}
}
示例6: server_events
int
main (int, char *[])
{
// Instantiate a server which will receive messages for DURATION
// seconds.
Server_Events server_events (UDP_PORT,
MCAST_ADDR,
DURATION);
// Instance of the ACE_Reactor.
ACE_Reactor reactor;
if (reactor.register_handler (&server_events,
ACE_Event_Handler::READ_MASK) == -1)
ACE_ERROR ((LM_ERROR,
"%p\n%a",
"register_handler",
1));
ACE_DEBUG ((LM_DEBUG,
"starting up server\n"));
for (;;)
reactor.handle_events (server_events.wait_time ());
ACE_NOTREACHED (return 0;)
}
示例7: timeout
static void *
worker (void *args)
{
ACE_Reactor *reactor = (ACE_Reactor *) args;
reactor->owner (ACE_Thread::self ());
ACE_Time_Value timeout (4);
for (;;)
{
//ACE_DEBUG ((LM_DEBUG, "(%t) calling handle_events\n"));
switch (reactor->handle_events (timeout))
{
case -1:
ACE_ERROR_RETURN ((LM_ERROR, "(%t) %p\n", "reactor"), 0);
/* NOTREACHED */
case 0:
ACE_ERROR_RETURN ((LM_ERROR, "(%t) timeout\n"), 0);
/* NOTREACHED */
}
// ACE_DEBUG ((LM_DEBUG, "(%t) done with handle_events\n"));
}
ACE_NOTREACHED(return 0);
}
示例8: svc
int MyTask::svc()
{
ACE_DEBUG ((LM_INFO, ACE_TEXT ("(%t) enter MyTask::svc()\n\n")));
//initialization
selector = new ACE_Select_Reactor;
ACE_Reactor* reactor = new ACE_Reactor(selector);
ACE_Reactor::instance(reactor); //then, ACE_Reactor::instance() is reactor
this->reactor(reactor); //this reactor_ of ACE_Event_Handler can not be set
//register socket handler
Handler handler(UDP_PORT);
if (reactor->register_handler(&handler, ACE_Event_Handler::READ_MASK) == -1)
{
ACE_ERROR((LM_ERROR, "%p\n", "cant't register with Reactor in MyTask::svc()\n"));
return -1;
}
//spawn mytask2
mytask2::instance()->open(&handler);
//handle_events in forever-loop until receive two data packets from socket, then, it will notify the MY_EXIT_HANDLER
while (exit_flag == 0)
{
int result = reactor->handle_events(); //timeout will not occur at all
if (result)
{
ACE_DEBUG ((LM_INFO, ACE_TEXT ("(%t) handle_events() succeed, result = %d\n\n"), result));
if (RECV_COUNT == handler.get_count())
{
ACE_DEBUG ((LM_INFO, ACE_TEXT ("(%t) MyTask::svc() notify the exit handler\n")));
ACE_Reactor::instance()->notify(&handler, ACE_Event_Handler::EXCEPT_MASK);
}
if (handler.get_flag())
exit_flag = 1;
}
else
{
ACE_ERROR((LM_ERROR, "%p\n", "handle_events() failed\n"));
return -1;
}
}
if (reactor->remove_handler(&handler, ACE_Event_Handler::READ_MASK |
ACE_Event_Handler::DONT_CALL) == -1)
{
ACE_ERROR((LM_ERROR, "%p\n", "cant't remove handler from Reactor\n"));
return -1;
}
delete reactor;
reactor = NULL;
ACE_DEBUG ((LM_INFO, ACE_TEXT ("(%t) exit MyTask::svc()\n\n")));
return 0;
}
示例9: timeout
int
handle_events (ACE_Reactor & reactor,
bool & okay_to_close)
{
ACE_Time_Value timeout (2);
// Only one event handler should have been dispatched.
if (reactor.handle_events (&timeout) != 1)
{
ACE_ERROR ((LM_ERROR,
ACE_TEXT ("Initial event dispatch failed\n")));
}
else
{
okay_to_close = true;
// Run the event loop again in an attempt to make the reactor
// dispatch the newly registered event handler. No events
// should be dispatched.
timeout.sec (2);
int const result = reactor.handle_events (&timeout);
if (result > 0)
{
ACE_ERROR ((LM_ERROR,
ACE_TEXT ("Unexpectedly dispatched an event\n")));
}
else if (result < 0)
{
overall_result = -1;
ACE_ERROR ((LM_ERROR,
ACE_TEXT ("Event loop failed unexpectedly\n")));
}
else
return 0;
}
return -1;
}
示例10: handler
int
ACE_TMAIN (int, ACE_TCHAR *[])
{
ACE_Reactor reactor;
Event_Handler handler (reactor);
int result = 0;
while (result != -1)
result = reactor.handle_events ();
return 0;
}
示例11: handler
int
main (int, char *[])
{
ACE_Reactor reactor;
Event_Handler handler (reactor);
int result = ACE_OS::thr_create ((ACE_THR_FUNC) worker, &handler, 0, 0);
ACE_ASSERT (result == 0);
for (result = 0; result != -1; result = reactor.handle_events ())
continue;
return 0;
}
示例12: sa
int
main (int, char **)
{
char addatapath[256];
ctgList url2ctg;
init_env();
// Create the acceptor that will listen for client connetions
HarvestAcceptor peer_acceptor;
StrUtil::path_merge(addatapath, adhome, "data");
htmlTagEntity::init(addatapath);
dbStore::prepare(
config.GetStrVal("DBNAME", "ANYDICT"),
config.GetStrVal("DBID", "inisoft"),
config.GetStrVal("DBPASS", "gksehf"));
/*
ctgcnt = url2ctg.load();
ACE_DEBUG ((LM_INFO, "Ctg Prefix: %d\n", ctgcnt));
url2ctg.print();
*/
categoryMapper::prepare();
if (peer_acceptor.open (ACE_INET_Addr (PORT),
&reactor) == -1)
ACE_ERROR_RETURN ((LM_ERROR,
"%p\n",
"open"),
-1);
ACE_Sig_Action sa ((ACE_SignalHandler) handler, SIGINT);
myCron mycron;
mycron.activate();
// Perform service until the signal handler receives SIGINT.
while (!finished)
reactor.handle_events ();
// Close the acceptor so that no more clients will be taken in.
peer_acceptor.close();
dbStore::finish();
ACE_DEBUG ((LM_SHUTDOWN, "[%T] -- SHUT DOWN --\n"));
return 0;
}
示例13: reactor_impl
int
ACE_TMAIN (int argc, ACE_TCHAR *[])
{
// If argc > 1 then allow multiple handlers per-signal, else just
// allow 1 handler per-signal.
ACE_Sig_Handlers multi_handlers;
#if defined (ACE_WIN32)
ACE_WFMO_Reactor reactor_impl (argc > 1
? &multi_handlers
: (ACE_Sig_Handler *) 0);
#else
ACE_Select_Reactor reactor_impl (argc > 1
? &multi_handlers
: (ACE_Sig_Handler *) 0);
#endif /* ACE_WIN32 */
ACE_Reactor reactor (&reactor_impl);
if (argc > 1)
{
// Register an "external" signal handler so that the
// ACE_Sig_Handlers code will have something to incorporate!
ACE_SignalHandler eh = (ACE_SignalHandler) external_handler;
ACE_Sig_Action sa (eh);
sa.register_action (SIGINT);
}
// Create a bevy of handlers.
Sig_Handler_1 h1 (reactor, "howdy");
Sig_Handler_1 h2 (reactor, "doody");
Sig_Handler_2 h3 (reactor, "tutty");
Sig_Handler_2 h4 (reactor, "fruity");
// Wait for user to type SIGINT and SIGQUIT.
for (;;)
{
ACE_DEBUG ((LM_DEBUG,
"\nwaiting for SIGINT or SIGQUIT\n"));
if (reactor.handle_events () == -1)
ACE_ERROR ((LM_ERROR,
"%p\n",
"handle_events"));
}
ACE_NOTREACHED (return 0);
}
示例14: handler
int
ACE_TMAIN (int, ACE_TCHAR *[])
{
ACE_Reactor reactor;
Event_Handler handler (reactor);
int result = ACE_OS::thr_create ((ACE_THR_FUNC) worker, 0, 0, 0);
ACE_TEST_ASSERT (result == 0);
for (result = 0; result != -1; result = reactor.handle_events ())
continue;
return 0;
}
示例15: sa
int
main (int, char **)
{
// Create the acceptor that will listen for client connetions
ExtractAcceptor peer_acceptor;
init_env();
dbStore::prepare(
config.GetStrVal("DBNAME", "ANYDICT"),
config.GetStrVal("DBID", "inisoft"),
config.GetStrVal("DBPASS", "gksehf"));
EDict::prepare(adhome);
TextProc::prepare();
HDict::prepare(adhome);
//unitTest();
if (peer_acceptor.open (ACE_INET_Addr (PORT),
&reactor) == -1)
ACE_ERROR_RETURN ((LM_ERROR,
"%p\n",
"open"),
-1);
ACE_Sig_Action sa ((ACE_SignalHandler) handler, SIGINT);
myCron mycron;
mycron.activate();
// Perform service until the signal handler receives SIGINT.
while (!finished)
reactor.handle_events ();
// Close the acceptor so that no more clients will be taken in.
peer_acceptor.close();
dbStore::finish();
ACE_DEBUG ((LM_DEBUG,
"[%T] -- SHUT DOWN --\n"));
return 0;
}