int Echo_Handler::dispatch_echo_checks (int first_call) { // Set ones , if this is the first call (not from handle_timeout) if (first_call) { for (size_t j = 0; j < this->number_remotes_; ++j) { this->success_status_[j] = 1; } this->current_attempt_ = this->max_attempts_num_; } // Send echo-checks. for (size_t i = 0; i < this->number_remotes_; ++i) { if (this->success_status_[i] != 0) { if (this->ping_socket ().send_echo_check ( this->remote_addrs_[i], this->connect_to_remote_) == -1) ACE_ERROR ((LM_ERROR, ACE_TEXT ("(%P|%t) Echo_Handler::dispatch_echo_checks - ") ACE_TEXT ("failed for this->remote_addrs_[%d].\n"), i)); } } int rval_sched = -1; if ((rval_sched = this->reactor ()->schedule_timer (this, 0, ACE_Time_Value (1), this->reply_wait_)) == -1) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("(%P|%t) Echo_Handler::dispatch_echo_checks:") ACE_TEXT (" %p\n"), ACE_TEXT ("schedule_timer")), -1); return 0; }
int ACE_TMAIN (int argc, ACE_TCHAR* argv[]) { try { if (argc < 2) throw args (); ACE_INET_Addr addr (argv[1]); //FUZZ: disable check_for_lack_ACE_OS // Turn on message loss and reordering simulation. // ACE_RMCast::Socket socket (addr, false, true); //FUZZ: enable check_for_lack_ACE_OS Message msg; msg.sn = 0; for (unsigned short i = 0; i < payload_size; i++) { msg.payload[i] = i; } for (; msg.sn < message_count; msg.sn++) { socket.send (&msg, sizeof (msg)); } // Keep running in case retransmissions are needed. // ACE_OS::sleep (ACE_Time_Value (60, 0)); return 0; } catch (args const&) { ACE_ERROR ((LM_ERROR, "usage: %s <IPv4 multicast address>:<port>\n", argv[0])); } return 1; }
int DllOrb::fini (void) { try { mv_poaManager_->deactivate (1, 1); mv_poaManager_ = PortableServer::POAManager::_nil (); // attempt to protect against sporadic BAD_INV_ORDER exceptions ACE_OS::sleep (ACE_Time_Value (0, 500)); mv_rootPOA_->destroy (1, 1); mv_rootPOA_ = PortableServer::POA::_nil (); mv_orb_->shutdown (1); ACE_DEBUG ((LM_ERROR, ACE_TEXT ("wait() ...\n"))); // wait for our threads to finish wait(); ACE_DEBUG ((LM_ERROR, ACE_TEXT ("wait() done\n"))); ACE_auto_ptr_reset (ma_barrier_, static_cast<ACE_Thread_Barrier *> (0)); } catch (...) { ACE_DEBUG ((LM_ERROR, ACE_TEXT ("ERROR: exception\n"))); return -1; } try { mv_orb_->destroy (); mv_orb_ = CORBA::ORB::_nil (); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Exception caught:"); return -1; } return 0; }
void Connection::write(Message& message) { ACE_Time_Value av(ACE_OS::gettimeofday() + ACE_Time_Value(1)); if (writeMutex.acquire(av) == -1) throw Miro::CException(errno, "Error writing can device."); // Roland: Is this sleep necessary for Sparrow2003 can ??? ACE_Time_Value time = ACE_OS::gettimeofday(); ACE_Time_Value delta = time - lastWrite; if (delta < canTimeOut) { // is this sleep necessary ??? // well, yes ACE_OS::sleep(canTimeOut - delta); // this is at least 10usec thanks to linux time = ACE_OS::gettimeofday(); } // will definitely choke if base is off int rc; if (parameters_.module == "pcan") { pcanmsg * msgp; message.canMessage((int **) &msgp); msgp->msg.msgtype = MSGTYPE_EXTENDED; for(int i = 0; i < msgp->msg.len; i++) std::cout << msgp->msg.data[i]; rc = ioctl(ioBuffer.get_handle(), PCAN_WRITE_MSG, msgp); } else { canmsg * msg; message.canMessage((int **) &msg); rc = ioBuffer.send_n(msg, sizeof(canmsg)); } lastWrite = time; writeMutex.release(); if (rc == -1) throw Miro::CException(errno, "Error writing can device."); }
virtual int handle_timeout (const ACE_Time_Value &, const void *arg) { ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%t) Test_Handler::handle_timeout\n"))); ++this->nr_expirations_; void *nc_arg = const_cast<void *> (arg); Thread_Timer_Queue *timer_queue = reinterpret_cast<Thread_Timer_Queue *> (nc_arg); ACE_Time_Value timeout = ACE_OS::gettimeofday () + ACE_Time_Value (1, 0); ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%t) scheduling new timer 1 sec from now\n"))); if (timer_queue->schedule (this, timer_queue, timeout) == -1) ACE_ERROR ((LM_ERROR, ACE_TEXT ("(%t) %p\n"), ACE_TEXT ("schedule failed"))); return 0; }
int AC_Output_Handler::svc () { ACE_Message_Block *chunk[ACE_IOV_MAX]; size_t message_index = 0; ACE_Time_Value time_of_last_send (ACE_OS::gettimeofday ()); ACE_Time_Value timeout; ACE_Sig_Action no_sigpipe ((ACE_SignalHandler) SIG_IGN); ACE_Sig_Action original_action; no_sigpipe.register_action (SIGPIPE, &original_action); for (;;) { if (message_index == 0) { timeout = ACE_OS::gettimeofday (); timeout += FLUSH_TIMEOUT; } ACE_Message_Block *mblk = 0; if (getq (mblk, &timeout) == -1) { if (errno == ESHUTDOWN) { if (connector_->reconnect () == -1) break; continue; } else if (errno != EWOULDBLOCK) break; else if (message_index == 0) continue; } else { if (mblk->size () == 0 && mblk->msg_type () == ACE_Message_Block::MB_STOP) { mblk->release (); break; } chunk[message_index] = mblk; ++message_index; } if (message_index >= ACE_IOV_MAX || (ACE_OS::gettimeofday () - time_of_last_send >= ACE_Time_Value(FLUSH_TIMEOUT))) { if (this->send (chunk, message_index) == -1) break; time_of_last_send = ACE_OS::gettimeofday (); } } if (message_index > 0) this->send (chunk, message_index); no_sigpipe.restore_action (SIGPIPE, original_action); return 0; }
void Receiver_exec_i::ccm_activate (void) { ACE_DEBUG ((LM_DEBUG, "Receiver_exec_i::ccm_activate \n ")); /// No need to implement anything /// Start the timer . if (this->reactor ()->schedule_timer( this->hello_generator_, // The callback object 0, // No arguments for this callback ACE_Time_Value (1, 0), // Initial delay this->interval_) == -1) // Time interval { ACE_ERROR ((LM_ERROR, "Receiver_exec_i::ccm_activate - " "Error scheduling timer\n")); } else { ACE_DEBUG ((LM_DEBUG, "Receiver_exec_i::ccm_activate - " "Hello generator is running\n")); } }
TAO_BEGIN_VERSIONED_NAMESPACE_DECL // Constructor. TAO_Time_Service_Clerk::TAO_Time_Service_Clerk (int timer_value, int timer_value_usecs, const IORS& servers) : server_ (servers), helper_ (this) { // Schedule the helper to be invoked by the reactor // periodically. if (TAO_ORB_Core_instance ()->reactor ()->schedule_timer (&helper_, 0, ACE_Time_Value::zero, ACE_Time_Value(timer_value,timer_value_usecs)) == -1) ORBSVCS_ERROR ((LM_ERROR, "%p\n", "schedule_timer ()")); }
int reuseAddr_test (void) { # if defined ACE_WIN32 || !defined ACE_LACKS_IOCTL ACE_SOCK_Dgram_Bcast sock1; if (sock1.open(ACE_INET_Addr(UDP_PORT),PF_INET,0,1) != 0) { ACE_ERROR ((LM_ERROR, ACE_TEXT ("Could not open socket for broadcast on port %d\n"), UDP_PORT )); ++result; } else { // Keep the socket open for some time ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Opened socket on port %d and keep it open for %d sec\n"), UDP_PORT, SEC_TO_KEEP_SOCKET_OPEN)); ACE_OS::sleep(ACE_Time_Value(SEC_TO_KEEP_SOCKET_OPEN,0)); sock1.close(); } # endif return result; }
int main (int, char* []) { ACE_Reactor reactor; Time_Handler* th = new Time_Handler; int timer_id[NUMBER_TIMERS]; for (int i = 0; i < NUMBER_TIMERS; i++) { timer_id[i] = reactor.schedule_timer(th, (const void *)i, // argument sent to handle_timeout() ACE_Time_Value(2 * i + 1)); //set timer to go off with delay } //Cancel the fifth timer before it goes off reactor.cancel_timer(timer_id[5]);//Timer ID of timer to be removed while (!done) { reactor.handle_events(); } return 0; }
int svc( ) { if ( m_sleep == ACE_Time_Value( 0 ) ) { printf( "###### TIMEBOMB Disabled. ######\n" ); fflush( stdout ); return 0; } ACE_Time_Value start = ACE_OS::gettimeofday(); ACE_Time_Value now = ACE_OS::gettimeofday(); do { ACE_OS::sleep( 1 ); now = ACE_OS::gettimeofday(); } while( now - start < m_sleep ); printf( "####### ERROR: TIMEBOMB WENT OFF, TEST TIMED OUT ########\n" ); fflush( stdout ); callClientCleanup(); exit( -1 ); return 0; }
int CLogManager::PutLog(_LogBlockInfo* pLogBlockInfo) { ACE_Message_Block* mb = pLogBlockInfo->GetQueueMessage(); //如果正在重新加载 if(m_blIsNeedReset == true) { //回收日志块 m_objLogBlockPool.ReturnBlockInfo(pLogBlockInfo); return 0; } if(mb) { int msgcount = (int)msg_queue()->message_count(); if (msgcount >= m_nQueueMax) { OUR_DEBUG((LM_INFO,"[CLogManager::PutLog] CLogManager queue is full!\n")); //回收日志块 m_objLogBlockPool.ReturnBlockInfo(pLogBlockInfo); return -1; } ACE_Time_Value xtime = ACE_OS::gettimeofday()+ACE_Time_Value(0, MAX_MSG_PUTTIMEOUT); if(this->putq(mb, &xtime) == -1) { OUR_DEBUG((LM_ERROR,"[CLogManager::PutLog] CLogManager putq error(%s)!\n", pLogBlockInfo->m_pBlock)); //回收日志块 m_objLogBlockPool.ReturnBlockInfo(pLogBlockInfo); return -1; } return 0; } OUR_DEBUG((LM_ERROR,"[CLogManager::PutLog] CLogManager new ACE_Message_Block error!\n")); return -1; }
int Time_Handler::handle_timeout (const ACE_Time_Value &tv, const void *arg) { long current_count = static_cast<long> (reinterpret_cast<size_t> (arg)); if (current_count >= 0) ACE_TEST_ASSERT (current_count == the_count); ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("[%x] Timer id %d with count #%d|%d timed out at %d!\n"), this, this->timer_id (), the_count, current_count, tv.sec ())); if (current_count == long (ACE_MAX_TIMERS - 1)) done = 1; else if (the_count == long (ACE_MAX_TIMERS - 1)) { done = 1; return -1; } else if (current_count == -1) { #if defined (ACE_HAS_CPP11) int result = ACE_Reactor::instance ()->reset_timer_interval (this->timer_id (), std::chrono::seconds {the_count + 1}); #else int result = ACE_Reactor::instance ()->reset_timer_interval (this->timer_id (), ACE_Time_Value (the_count + 1)); #endif if (result == -1) ACE_ERROR ((LM_ERROR, ACE_TEXT ("Error resetting timer interval\n"))); } the_count += (1 + odd); return 0; }
static void test_registering_all_handlers (void) { ACE_Trace t (ACE_TEXT ("test_registering_all_handler"), __LINE__, ACE_TEXT_CHAR_TO_TCHAR (__FILE__)); Time_Handler rt[ACE_MAX_TIMERS]; long t_id[ACE_MAX_TIMERS]; for (size_t i = 0; i < ACE_MAX_TIMERS; i++) { t_id[i] = ACE_Reactor::instance ()->schedule_timer (&rt[i], (const void *) i, ACE_Time_Value (2 * i + 1)); ACE_TEST_ASSERT (t_id[i] != -1); rt[i].timer_id (t_id[i]); } while (!done) ACE_Reactor::instance ()->handle_events (); }
CORBA::Long Simple_Server_i::test_method (CORBA::Boolean do_callback) { if (do_callback) { // Scheduling ourselves for doing the callbacks if (TAO_debug_level > 0) ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Scheduling for callback\n"))); if (this->orb_->orb_core ()->reactor ()->schedule_timer (this, 0, ACE_Time_Value (1)) == -1) { ACE_ERROR ((LM_ERROR, "(%P|%t) Can't schedule timers, aborting ..\n")); ACE_OS::abort (); } } return 0; }
/* Closing the thread pool can be a tricky exercise. I've decided to take an easy approach and simply enqueue a secret message for each thread we have active. */ int Thread_Pool::close (u_long flags) { ACE_UNUSED_ARG(flags); /* Find out how many threads are currently active */ int counter = active_threads_.value (); /* For each one of the active threads, enqueue a "null" event handler. Below, we'll teach our svc() method that "null" means "shutdown". */ while (counter--) this->enqueue (0); /* As each svc() method exits, it will decrement the active thread counter. We just wait here for it to reach zero. Since we don't know how long it will take, we sleep for a quarter of a second between tries. */ while (active_threads_.value ()) ACE_OS::sleep (ACE_Time_Value (0, 250000)); return(0); }
int Purger_Thread::svc (void) { ACE_DEBUG ((LM_DEBUG, ACE_TEXT("(%t) Purger_Thread::svc commencing\n"))); disable_signal (SIGPIPE, SIGPIPE); for (; !this->reactor_.reactor_event_loop_done ();) { // Get a connection from the cache. Sender *sender = this->connection_cache_.acquire_connection (); // If no connection is available in the cache, sleep for a while. if (sender == 0) ACE_OS::sleep (ACE_Time_Value (0, 10 * 1000)); else { // The reference count on the sender was increased by the // cache before it was returned to us. ACE_Event_Handler_var safe_sender (sender); // Actively close the connection. ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%t) Purger thread calling Sender::close() ") ACE_TEXT ("for handle %d\n"), sender->handle_)); sender->close (); } } ACE_DEBUG ((LM_DEBUG, ACE_TEXT("(%t) Purger_Thread::svc terminating\n"))); return 0; }
bool MyMain::init_server (const ACE_TCHAR* args) { std::string my_args (ACE_TEXT_ALWAYS_CHAR(args)); // main thread and extra thread for backdoor operations int thread_pool = 2; ACE_auto_ptr_reset (server_task_, new Server_Task (my_args)); ACE_ASSERT (server_task_.get() != 0); server_task_->activate (THR_NEW_LWP | THR_JOINABLE |THR_INHERIT_SCHED , thread_pool); int duration = 4; //wait 3 seconds for initialization ACE_Time_Value current = ACE_High_Res_Timer::gettimeofday_hr (); ACE_Time_Value timeout = current + ACE_Time_Value(duration); while (current < timeout) { if (server_task_->ready()) { break; } ACE_Time_Value sleep_time; sleep_time.msec (10); ACE_OS::sleep (sleep_time); current += sleep_time; } if (!server_task_->ready()) { server_task_->force_shutdown (); server_task_->wait (); ACE_auto_ptr_reset (server_task_, (Server_Task*)0); return false; } return true; }
int KSG_Task_Queue_Pool::wait_for_queue(const std::string &key,long time_out) { queue_cond_map_type::const_iterator i = _queue_cond.find(key); if(i == _queue_cond.end()) { ACE_DEBUG((LM_ERROR,"没有对应的队列[%s]",key.c_str())); return -1; } Queue_List_Cond *cond = i->second; ACE_DEBUG((LM_DEBUG,"等待队列组[%s]...",key.c_str())); int ret; if(time_out > 0) { ACE_Time_Value tv = ACE_Time_Value(time_out/1000,time_out%1000); tv += ACE_OS::gettimeofday(); ret = cond->wait(&tv); // maybe timeout if( ret == -1 && ACE_OS::last_error() == ETIME ) ret = 1; } else ret = cond->wait(NULL); return ret; }
static void test_canceling_odd_timers (void) { ACE_Trace t (ACE_TEXT ("test_canceling_odd_timers"), __LINE__, ACE_TEXT_CHAR_TO_TCHAR (__FILE__)); Time_Handler rt[ACE_MAX_TIMERS]; long t_id[ACE_MAX_TIMERS]; done = 0; the_count = 1; odd = 1; for (size_t i = 0; i < ACE_MAX_TIMERS; i++) { t_id[i] = ACE_Reactor::instance ()->schedule_timer (&rt[i], (const void *) i, ACE_Time_Value (2 * i + 1)); ACE_TEST_ASSERT (t_id[i] != -1); rt[i].timer_id (t_id[i]); } for (size_t j = 0; (u_long) j < ACE_MAX_TIMERS; j++) // Cancel handlers with odd numbered timer ids. if (ACE_ODD (rt[j].timer_id ())) { int result = ACE_Reactor::instance ()->cancel_timer (rt[j].timer_id ()); if (result == -1) ACE_ERROR ((LM_ERROR, ACE_TEXT ("Error cancelling timer\n"))); } while (!done) ACE_Reactor::instance ()->handle_events (); }
static void test_canceling_odd_timers (void) { ACE_Trace t (ACE_TEXT ("test_canceling_odd_timers"), __LINE__, ACE_TEXT_CHAR_TO_TCHAR (__FILE__)); Time_Handler rt[ACE_MAX_TIMERS]; long t_id[ACE_MAX_TIMERS]; size_t which[ACE_MAX_TIMERS]; done = 0; counter = 1; odd = 1; size_t i = 0; long secs = 0; for ( ; i < ACE_MAX_TIMERS; i++, secs++) { which[i] = i; t_id[i] = ACE_Proactor::instance ()->schedule_timer (rt[i], &which[i], ACE_Time_Value (2 * secs + 1)); if (t_id[i] == -1) ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("schedule_timer"))); rt[i].timer_id (t_id[i]); } for (i = 0; i < ACE_MAX_TIMERS; i++) // Cancel handlers with odd numbered timer ids. if (ACE_ODD (rt[i].timer_id ())) { if (ACE_Proactor::instance ()->cancel_timer (rt[i].timer_id ()) == -1) ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("cancel_timer"))); } while (!done) ACE_Proactor::instance ()->handle_events (); }
void CUnit_TimerManager::Test_TimerManager(void) { bool blRet = false; ActiveTimer objActiveTimer; objActiveTimer.activate(); ACE_Time_Value tvNow = ACE_OS::gettimeofday(); long lTimerID = objActiveTimer.schedule(m_pTimeTask, NULL, tvNow + ACE_Time_Value(0, 1000)); if (-1 == lTimerID) { CPPUNIT_ASSERT_MESSAGE("[Test_TimerManager]schedule is fail.", true == blRet); } ACE_Time_Value tvSleep(0, 2000); ACE_OS::sleep(tvSleep); objActiveTimer.deactivate(); objActiveTimer.close(); ACE_Time_Value tvSleepClose(0, 1000); ACE_OS::sleep(tvSleepClose); OUR_DEBUG((LM_INFO, "[CUnit_TimerManager]objActiveTimer is close.\n")); }
int run_main (int, ACE_TCHAR *[]) { ACE_START_TEST (ACE_TEXT ("Future_Test")); #if defined (ACE_HAS_THREADS) // @@ Should make these be <auto_ptr>s... Prime_Scheduler *andres, *peter, *helmut, *matias; // Create active objects.. ACE_NEW_RETURN (andres, Prime_Scheduler (ACE_TEXT ("andres")), -1); int result = andres->open (); ACE_TEST_ASSERT (result != -1); ACE_NEW_RETURN (peter, Prime_Scheduler (ACE_TEXT ("peter")), -1); result = peter->open (); ACE_TEST_ASSERT (result != -1); ACE_NEW_RETURN (helmut, Prime_Scheduler (ACE_TEXT ("helmut")), -1); result = helmut->open (); ACE_TEST_ASSERT (result != -1); // Matias passes all asynchronous method calls on to Andres... ACE_NEW_RETURN (matias, Prime_Scheduler (ACE_TEXT ("matias"), andres), -1); result = matias->open (); ACE_TEST_ASSERT (result != -1); for (int i = 0; i < n_loops; i++) { { ACE_Future<u_long> fresulta; ACE_Future<u_long> fresultb; ACE_Future<u_long> fresultc; ACE_Future<u_long> fresultd; ACE_Future<u_long> fresulte; ACE_Future<const ACE_TCHAR *> fname; ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%t) going to do a non-blocking call\n"))); // Spawn off the methods, which run in a separate thread as // active object invocations. fresulta = andres->work (9013); fresultb = peter->work (9013); fresultc = helmut->work (9013); fresultd = matias->work (9013); fname = andres->name (); // See if the result is available... if (fresulta.ready ()) ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%t) wow.. work is ready.....\n"))); ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%t) non-blocking call done... now blocking...\n"))); // Save the result of fresulta. fresulte = fresulta; if (i % 3 == 0) { // Every 3rd time... disconnect the futures... but // "fresulte" should still contain the result... fresulta.cancel (10ul); fresultb.cancel (20ul); fresultc.cancel (30ul); fresultd.cancel (40ul); } u_long resulta = 0, resultb = 0, resultc = 0, resultd = 0, resulte = 0; fresulta.get (resulta); fresultb.get (resultb); fresultc.get (resultc); fresultd.get (resultd); fresulte.get (resulte); ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%t) result a %u\n") ACE_TEXT ("(%t) result b %u\n") ACE_TEXT ("(%t) result c %u\n") ACE_TEXT ("(%t) result d %u\n") ACE_TEXT ("(%t) result e %u\n"), (u_int) resulta, (u_int) resultb, (u_int) resultc, (u_int) resultd, (u_int) resulte)); const ACE_TCHAR *name = 0; fname.get (name); ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%t) name %s\n"), name)); } ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%t) task_count %d future_count %d ") ACE_TEXT ("capsule_count %d method_request_count %d\n"), task_count.value (), future_count.value (), capsule_count.value (), method_request_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 future_count %d ") ACE_TEXT ("capsule_count %d method_request_count %d\n"), task_count.value (), future_count.value (), capsule_count.value (), method_request_count.value ())); { // Check if set then get works, older versions of <ACE_Future> // will lock forever (or until the timer expires), will use a // small timer value to avoid blocking the process. ACE_Future<int> f1; f1.set (100); // Note you need to use absolute time, not relative time. ACE_Time_Value timeout (ACE_OS::gettimeofday () + ACE_Time_Value (10)); int value = 0; if (f1.get (value, &timeout) == 0 && value == 100) ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Ace_Future<T>::Set followed by Ace_Future<T>::Get works.\n"))); else ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("ACE_Future<T>::Set followed by Ace_Future<T>::Get does ") ACE_TEXT ("not work, broken Ace_Future<> implementation.\n"))); } { ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Checking if Ace_Future<T>::operator= is implemented ") ACE_TEXT ("incorrectly this might crash the program.\n"))); ACE_Future<int> f1; { // To ensure that a rep object is created. ACE_Future<int> f2 (f1); } // Now it is one ACE_Future<int> referencing the rep instance ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("0.\n"))); //Check that self assignment works. f1 = f1; // Is there any repesentation left, and if so what is the ref // count older ACE_Future<> implementations have deleted the rep // instance at this moment // The stuff below might crash the process if the <operator=> // implementation was bad. int value = 0; ACE_Time_Value timeout (ACE_OS::gettimeofday () + ACE_Time_Value (10)); f1.set (100); f1.get (value, &timeout); ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("1.\n"))); { // Might delete the same data a couple of times. ACE_Future<int> f2 (f1); f1.set (100); f1.get (value, &timeout); } ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("2.\n"))); { ACE_Future<int> f2 (f1); f1.set (100); f1.get (value, &timeout); } ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("3.\n"))); { ACE_Future<int> f2 (f1); f1.set (100); f1.get (value, &timeout); } ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("4.\n"))); { ACE_Future<int> f2 (f1); f1.set (100); f1.get (value, &timeout); } ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("5.\n"))); { ACE_Future<int> f2 (90); f2.get (value, &timeout); f1.get (value, &timeout); } } ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("No it did not crash the program.\n"))); 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; }
void TAO_DTP_POA_Strategy::set_dtp_config (TAO_DTP_Definition &tp_config) { if (tp_config.min_threads_ <= 0) { this->dtp_task_.set_min_pool_threads (1); this->dtp_task_.set_thread_idle_time (ACE_Time_Value (0,0)); } else { this->dtp_task_.set_min_pool_threads (tp_config.min_threads_); this->dtp_task_.set_thread_idle_time (tp_config.timeout_); } // initial_pool_threads_ if ((tp_config.init_threads_ <= 0) || (tp_config.init_threads_ < tp_config.min_threads_)) { this->dtp_task_.set_init_pool_threads (this->dtp_task_.get_min_pool_threads()); } else { this->dtp_task_.set_init_pool_threads (tp_config.init_threads_); } // max_pool_threads_ if (tp_config.max_threads_ <= 0) { // Set to 0 so that max is unbounded. this->dtp_task_.set_max_pool_threads(0); } else { if (tp_config.max_threads_ < tp_config.init_threads_) { this->dtp_task_.set_max_pool_threads( this->dtp_task_.get_init_pool_threads ()); } else { this->dtp_task_.set_max_pool_threads (tp_config.max_threads_); } } // thread_stack_size_ if (tp_config.stack_size_ <= 0) { this->dtp_task_.set_thread_stack_size (ACE_DEFAULT_THREAD_STACKSIZE); } else { this->dtp_task_.set_thread_stack_size (tp_config.stack_size_); } // max_request_queue_depth_ if (tp_config.queue_depth_ < 0) { this->dtp_task_.set_max_request_queue_depth (0); } else { this->dtp_task_.set_max_request_queue_depth (tp_config.queue_depth_); } if (TAO_debug_level > 4) { TAOLIB_DEBUG ((LM_DEBUG, ACE_TEXT ("TAO (%P|%t) - DTP_POA_Strategy: ") ACE_TEXT ("Initialized with:\n") ACE_TEXT ("TAO (%P|%t) - DTP_POA_Strategy initial_pool_threads_=") ACE_TEXT ("[%d]\n") ACE_TEXT ("TAO (%P|%t) - DTP_POA_Strategy min_pool_threads_=[%d]\n") ACE_TEXT ("TAO (%P|%t) - DTP_POA_Strategy max_pool_threads_=[%d]\n") ACE_TEXT ("TAO (%P|%t) - DTP_POA_Strategy max_request_queue_depth_=") ACE_TEXT ("[%d]\n") ACE_TEXT ("TAO (%P|%t) - DTP_POA_Strategy thread_stack_size_=[%d]\n") ACE_TEXT ("TAO (%P|%t) - DTP_POA_Strategy thread_idle_time_=[%d]\n"), this->dtp_task_.get_init_pool_threads(), this->dtp_task_.get_min_pool_threads(), this->dtp_task_.get_max_pool_threads(), this->dtp_task_.get_max_request_queue_depth(), this->dtp_task_.get_thread_stack_size(), this->dtp_task_.get_thread_idle_time())); } }
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; }
int run_main (int argc, ACE_TCHAR *argv[]) { ACE_START_TEST (ACE_TEXT ("XtMotifReactor_Test")); XtAppContext app_context; Widget topLevel, goodbye, PressMe, lbl, digits_rc; Widget children[5]; #if defined (HummingBird_X) HCLXmInit (); #endif /* HummingBird_X */ topLevel = XtVaAppInitialize (&app_context, "XTReactor_Test", 0, 0, &argc, argv, 0, static_cast<void *>(0)); digits_rc = create_box(topLevel, "digits_rc"); //"Stop Test" button. goodbye = XtCreateWidget ( (char *) "goodbye", BUTTON_WIDGET, digits_rc, 0, 0); set_label(goodbye, "Stop Test"); //"Press Me" button PressMe = XtCreateWidget ((char *) "PressMe", BUTTON_WIDGET, digits_rc, 0, 0); //Display for event counter lbl = XtCreateWidget ((char *) "label_for_event_one", LABEL_WIDGET, digits_rc, 0, 0); set_label(lbl, "label_for_all_events"); int ac = 0; children[ac++] = goodbye; children[ac++] = PressMe; children[ac++] = lbl; XtManageChildren (children, ac); XtManageChild (digits_rc); //Register callback for "Stop Test" button XtAddCallback (goodbye, PRESS_ME_CALLBACK, Quit, 0); //Register callback for "Press Me" button XtAddCallback (PressMe, PRESS_ME_CALLBACK, inc_count, (XtPointer) lbl); // Register callback for X Timer (void) XtAppAddTimeOut (app_context, 1000, inc_tmo, (XtPointer) lbl); XtRealizeWidget (topLevel); // It will perform X Main Loop ACE_XtReactor reactor (app_context); ACE_Reactor r (&reactor); //Event Handler for ACE Timer. EV_handler evh; ACE_Acceptor <Connection_Handler, ACE_SOCK_ACCEPTOR> acceptor; if (acceptor.open (ACE_INET_Addr ((u_short) SERV_TCP_PORT), &r) == -1) ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "open"), -1); if (reactor.schedule_timer (&evh, (const void *) lbl, ACE_Time_Value (2), ACE_Time_Value (2))==-1) ACE_ERROR_RETURN ((LM_ERROR, " (%P|%t) can't register with reactor\n"), -1); ACE_Thread_Manager::instance ()->spawn ((ACE_THR_FUNC) client, 0, THR_NEW_LWP | THR_DETACHED); XtAppMainLoop (XtWidgetToApplicationContext (topLevel)); ACE_END_TEST; return 0; }
int main (int, char *[]) { ACE_Time_Value tv1; ACE_Time_Value tv2 (2); ACE_Time_Value tv3 (100); ACE_Time_Value tv4 (1, 1000000); ACE_Time_Value tv5 (2); ACE_Time_Value tv6 (1, -1000000); ACE_ASSERT (tv1 == ACE_Time_Value (0)); ACE_ASSERT (tv2 < tv3); ACE_ASSERT (tv2 <= tv2); ACE_ASSERT (tv2 >= tv4); ACE_ASSERT (tv5 >= tv6); ACE_ASSERT (tv2 == ACE_Time_Value (1, 1000000)); ACE_ASSERT (tv5 == tv4); ACE_ASSERT (tv2 == tv4); ACE_ASSERT (tv1 != tv2); ACE_ASSERT (tv6 == tv1); # if defined (ACE_NDEBUG) ACE_UNUSED_ARG (tv1); ACE_UNUSED_ARG (tv2); ACE_UNUSED_ARG (tv3); ACE_UNUSED_ARG (tv4); ACE_UNUSED_ARG (tv5); ACE_UNUSED_ARG (tv6); # endif /* ACE_NDEBUG */ cout << "0,0 :\t\t" << ACE_Time_Value (0,0) << endl; cout << "-0,0 :\t\t" << ACE_Time_Value (-0,0) << endl; cout << "0,-0 :\t\t" << ACE_Time_Value (0,-0) << endl; cout << "-0,-0 :\t\t" << ACE_Time_Value (-0,-0) << endl; cout << endl; cout << "0,1 :\t\t" << ACE_Time_Value (0,1) << endl; cout << "1,0 :\t\t" << ACE_Time_Value (1,0) << endl; cout << "-1,0 :\t\t" << ACE_Time_Value (-1,0) << endl; cout << "-1,-0 :\t\t" << ACE_Time_Value (-1,-0) << endl; cout << endl; cout << "1,1 :\t\t" << ACE_Time_Value (1,1) << endl; cout << "-1,1 :\t\t" << ACE_Time_Value (-1,1) << endl; cout << "1,-1 :\t\t" << ACE_Time_Value (1,-1) << endl; cout << "-1,-1 :\t\t" << ACE_Time_Value (-1,-1) << endl; cout << endl; cout << "1,-1111111 :\t" << ACE_Time_Value (1,-1111111) << endl; cout << "1,-100000 :\t" << ACE_Time_Value (1,-100000) << endl; cout << "1,-1000000 :\t" << ACE_Time_Value (1,-1000000) << endl; cout << "-1,1000000 :\t" << ACE_Time_Value (-1,1000000) << endl; cout << "5,-1000000 :\t" << ACE_Time_Value (5,-1000000) << endl; cout << "5,-1500000 :\t" << ACE_Time_Value (5,-1500000) << endl; cout << "2,-2500000 :\t" << ACE_Time_Value (2,-2500000) << endl; cout << "2,-4500000 :\t" << ACE_Time_Value (2,-4500000) << endl; return 0; }
int ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { try { CORBA::ORB_var orb = CORBA::ORB_init (argc, argv); if (parse_args (argc, argv) != 0) return 1; CORBA::Object_var object = orb->string_to_object (ior); A::AMI_Test_var server = A::AMI_Test::_narrow (object.in ()); if (CORBA::is_nil (server.in ())) { ACE_ERROR_RETURN ((LM_ERROR, "Object reference <%s> is nil.\n", ior), 1); } // Activate POA to handle the call back. CORBA::Object_var poa_object = orb->resolve_initial_references("RootPOA"); if (CORBA::is_nil (poa_object.in ())) ACE_ERROR_RETURN ((LM_ERROR, " (%P|%t) Unable to initialize the POA.\n"), 1); PortableServer::POA_var root_poa = PortableServer::POA::_narrow (poa_object.in ()); PortableServer::POAManager_var poa_manager = root_poa->the_POAManager (); poa_manager->activate (); // Let the client perform the test in a separate thread Handler* handler = 0; ACE_NEW_RETURN (handler, Handler, 1); PortableServer::ServantBase_var owner_transfer(handler); PortableServer::ObjectId_var id = root_poa->activate_object (handler); CORBA::Object_var object2 = root_poa->id_to_reference (id.in ()); A::AMI_AMI_TestHandler_var hello = A::AMI_AMI_TestHandler::_narrow (object2.in ()); object2 = CORBA::Object::_nil (); server->shutdown (); // oneway, so returns here immediately but server waits 5 sec Client client (server.in (), niterations, hello.in ()); if (client.activate (THR_NEW_LWP | THR_JOINABLE, nthreads) != 0) ACE_ERROR_RETURN ((LM_ERROR, "Cannot activate client threads\n"), 1); // Main thread collects replies. It needs to collect // <nthreads*niterations> replies. number_of_replies = nthreads *niterations; if (debug) { ACE_DEBUG ((LM_DEBUG, "(%P|%t) : Entering perform_work loop to receive <%d> replies\n", number_of_replies)); } // ORB loop. ACE_Time_Value tv (1,0); orb->run (tv); if (debug) { ACE_DEBUG ((LM_DEBUG, "(%P|%t) : Exited perform_work loop Received <%d> replies\n", (nthreads*niterations) - number_of_replies)); } ACE_DEBUG ((LM_DEBUG, "threads finished\n")); client.wait (); tv = ACE_Time_Value (1,0); orb->run (tv); root_poa->deactivate_object (id.in ()); root_poa->destroy (1, // ethernalize objects 0); // wait for completion hello = A::AMI_AMI_TestHandler::_nil (); root_poa = PortableServer::POA::_nil (); poa_object = CORBA::Object::_nil (); object = CORBA::Object::_nil (); server = A::AMI_Test::_nil (); poa_manager = PortableServer::POAManager::_nil (); client.clear (); orb->shutdown (); orb->destroy (); CORBA::ULong ref_count = orb->_refcount(); if (ref_count > 1) { ACE_DEBUG ((LM_DEBUG, ACE_TEXT("Refcount orb %d\n"), ref_count)); ++parameter_corruption; } else { TAO_ORB_Core* core = orb->orb_core (); if (core != 0) { ACE_DEBUG ((LM_DEBUG, ACE_TEXT("Core <> null\n"))); ++parameter_corruption; } } orb = CORBA::ORB::_nil (); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Caught exception:"); return 1; } return parameter_corruption; }
int RASocket::subnegotiate() { char buf[1024]; ACE_Data_Block db(sizeof (buf), ACE_Message_Block::MB_DATA, buf, 0, 0, ACE_Message_Block::DONT_DELETE, 0); ACE_Message_Block message_block(&db, ACE_Message_Block::DONT_DELETE, 0); const size_t recv_size = message_block.space(); // Wait a maximum of 1000ms for negotiation packet - not all telnet clients may send it ACE_Time_Value waitTime = ACE_Time_Value(1); const ssize_t n = peer().recv(message_block.wr_ptr(), recv_size, &waitTime); if (n <= 0) return int(n); if (n >= 1024) { sLog->outRemote("RASocket::subnegotiate: allocated buffer 1024 bytes was too small for negotiation packet, size: %u", n); return -1; } buf[n] = '\0'; #ifdef _DEBUG for (uint8 i = 0; i < n; ) { uint8 iac = buf[i]; if (iac == 0xFF) // "Interpret as Command" (IAC) { uint8 command = buf[++i]; std::stringstream ss; switch (command) { case 0xFB: // WILL ss << "WILL "; break; case 0xFC: // WON'T ss << "WON'T "; break; case 0xFD: // DO ss << "DO "; break; case 0xFE: // DON'T ss << "DON'T "; break; default: return -1; // not allowed } uint8 param = buf[++i]; ss << uint32(param); sLog->outRemote(ss.str().c_str()); } ++i; } #endif //! Just send back end of subnegotiation packet uint8 const reply[2] = {0xFF, 0xF0}; return peer().send(reply, 2); }
void Writer::rsleep(const int wait) { int lwait = 1 + (ACE_OS::rand() % wait); ACE_OS::sleep(ACE_Time_Value(0, lwait)); }