int main (int argc, ACE_TCHAR *argv[]) { ACE_START_TEST (ACE_TEXT ("Upgradable_RW_Test")); int status = 0; #if defined (ACE_HAS_THREADS) parse_args (argc, argv); #if !defined (RW_MUTEX) use_try_upgrade = 0; // make sure that we have to acquire the write lock #endif /* RW_MUTEX */ current_readers = 0; // Possibly already done current_writers = 0; // Possibly already done init (); ACE_DEBUG ((LM_DEBUG, ACE_TEXT (" (%t) main thread starting\n"))); Time_Calculation time_Calculation; // for the time calculation ACE_Barrier barrier (n_readers + n_writers); // for a nice start of all threads (for much contention) // Initialize the readers. Reader_Task** reader_tasks; ACE_NEW_RETURN (reader_tasks, Reader_Task*[n_readers], -1); u_int i; for (i = 0; i < n_readers; i++) { ACE_NEW_RETURN (reader_tasks[i], Reader_Task (time_Calculation, barrier), -1); reader_tasks[i]->activate (thr_flags, 1, 0, ACE_DEFAULT_THREAD_PRIORITY); } // Create all the writers Writer_Task** writer_tasks; ACE_NEW_RETURN (writer_tasks, Writer_Task*[n_writers], -1); for (i = 0; i < n_writers; i++) { ACE_NEW_RETURN (writer_tasks[i], Writer_Task (time_Calculation, barrier), -1); writer_tasks[i]->activate (thr_flags, 1, 0, ACE_DEFAULT_THREAD_PRIORITY); } // Wait a maximum of 1 second per iteration. const ACE_Time_Value max_wait (n_iterations * 1); const ACE_Time_Value wait_time (ACE_OS::gettimeofday () + max_wait); if (ACE_Thread_Manager::instance ()->wait (&wait_time) == -1) { if (errno == ETIME) ACE_ERROR ((LM_ERROR, ACE_TEXT ("maximum wait time of %d msec exceeded\n"), max_wait.msec ())); else ACE_OS::perror (ACE_TEXT ("wait")); status = -1; } // compute average time. time_Calculation.print_stats (); if (not_upgraded != 0 || upgraded != 0) ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("upgraded to not upgraded ratio = %f \n"), (float) upgraded / (float) (not_upgraded + upgraded))); ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Number of times, that find was called: %d\n"), find_called)); ACE_DEBUG ((LM_DEBUG, ACE_TEXT (" (%t) exiting main thread\n"))); // Delete the memory of the Double_Linked_List ACE_CString *cString_ptr; Element *element_ptr; for (i = 0; i < n_entries; i++) { if ((element_ptr = linked_list_ptr->delete_head ())) { cString_ptr = element_ptr->value (); delete cString_ptr; delete element_ptr; } } delete linked_list_ptr; for (i = 0; i < n_writers; i++) delete writer_tasks[i]; delete [] writer_tasks; for (i = 0; i < n_readers; i++) delete reader_tasks [i]; delete [] reader_tasks; #else ACE_UNUSED_ARG (argc); ACE_UNUSED_ARG (argv); ACE_ERROR ((LM_INFO, ACE_TEXT ("threads not supported on this platform\n"))); #endif /* ACE_HAS_THREADS */ ACE_END_TEST; return status; }
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; }
ACE_Proactor * ACE_Proactor::instance (size_t threads) { ACE_UNUSED_ARG (threads); return 0; }
int STDIN_Token::handle_input (ACE_HANDLE fd) { ACE_UNUSED_ARG (fd); char tid[BUFSIZ]; char token[BUFSIZ]; char type[16]; char operation[16]; if (::scanf ("%s %s %s %s", tid, token, type, operation) <= 0) { ACE_OS::printf ("Try again.\n"); return 0; } ACE_Token_Proxy *proxy = this->get_proxy (tid, token, type[0]); if (proxy == 0) return -1; switch (operation[0]) { case 'a': case 'A': if (proxy->acquire () == 0) { ACE_OS::printf ("Succeeded.\n"); if (ACE_TOKEN_INVARIANTS::instance ()->acquired (proxy) == 0) ACE_OS::printf ("Violated invariant.\n"); } else ACE_ERROR ((LM_ERROR, "%p.\n", "Acquire failed")); break; case 'n': case 'N': ACE_TOKEN_INVARIANTS::instance ()->releasing (proxy); if (proxy->renew () == 0) { ACE_OS::printf ("Succeeded.\n"); if (ACE_TOKEN_INVARIANTS::instance ()->acquired (proxy) == 0) ACE_OS::printf ("Violated invariant.\n"); } else ACE_ERROR ((LM_ERROR, "%p.\n", "Renew failed")); break; case 'r': case 'R': ACE_TOKEN_INVARIANTS::instance ()->releasing (proxy); if (proxy->release () == 0) ACE_OS::printf ("Succeeded.\n"); else ACE_ERROR ((LM_ERROR, "%p.\n", "Release failed")); break; case 't': case 'T': if (proxy->tryacquire () == 0) { ACE_OS::printf ("Succeeded.\n"); if (ACE_TOKEN_INVARIANTS::instance ()->acquired (proxy) == 0) ACE_OS::printf ("Violated invariant.\n"); } else ACE_ERROR ((LM_ERROR, "%p.\n", "Tryacquire failed")); break; } this->display_menu (); return 0; }
void TAO_EC_Filter::get_qos_info (TAO_EC_QOS_Info& qos_info) { ACE_UNUSED_ARG (qos_info); throw CORBA::NO_IMPLEMENT (TAO::VMCID, CORBA::COMPLETED_NO); }
int ACE_TMAIN(int, ACE_TCHAR ** argv) { int result = 0; #if !defined (ACE_LACKS_FORK) ACE_Sig_Action sigUSR2((ACE_SignalHandler) shutdown_func, SIGUSR2); ACE_DEBUG ((LM_INFO, ACE_TEXT ("(%P|%t) SIGUSR2 shutdown handler installed\n"))); ACE_UNUSED_ARG(sigUSR2); pid_t pid = -1; pid = ACE_OS::fork(); ACE_Log_Msg::instance ()->sync (argv[0]); // Make %P|%t work right if (pid == 0) // child { ACE_DEBUG ((LM_INFO, ACE_TEXT ("(%P|%t) child waiting\n"))); ACE_OS::sleep(5); ACE_DEBUG ((LM_INFO, ACE_TEXT ("(%P|%t) signaling parent\n"))); result = ACE_OS::kill(ACE_OS::getppid(), SIGUSR2); ACE_DEBUG ((LM_INFO, ACE_TEXT ("(%P|%t) signaled parent\n"))); // ACE_OS::sleep (100000); return 0; } else if (pid > 0) // parent { ACE_DEBUG ((LM_INFO, ACE_TEXT ("(%P|%t) parent using ACE_Service_Config, pid=%d\n"), pid)); ACE_Service_Config serviceConfig; ACE_TCHAR signum[64]; ACE_OS::sprintf(signum, ACE_TEXT("%d"), SIGUSR1); ACE_ARGV args; args.add(argv[0]); args.add(ACE_TEXT("-s")); args.add(signum); result = serviceConfig.open ( args.argc(), args.argv(), ACE_DEFAULT_LOGGER_KEY, 1, // ignore_static_svcs = 1, 1, // ignore_default_svc_conf_file = 0, 0 // ignore_debug_flag = 0 ); if(0 != result) { ACE_ERROR ((LM_ERROR, ACE_TEXT ("(%P|%t) Error: serviceConfig.open failed\n"))); return result; } ACE_DEBUG ((LM_INFO, ACE_TEXT ("(%P|%t) serviceConfig.open done\n"))); ACE_DEBUG ((LM_INFO, ACE_TEXT ("(%P|%t) serviceConfig.process_file ...\n"))); #if (ACE_USES_CLASSIC_SVC_CONF == 1) result = serviceConfig.process_file(ACE_TEXT("Bug_3251.conf")); #else result = serviceConfig.process_file(ACE_TEXT("Bug_3251.conf.xml")); #endif if(0 != result) { ACE_ERROR ((LM_ERROR, ACE_TEXT ("(%P|%t) Error: serviceConfig.process_file failed\n"))); return result; } ACE_DEBUG ((LM_INFO, ACE_TEXT ("(%P|%t) serviceConfig.process_file done\n"))); ACE_DEBUG ((LM_INFO, ACE_TEXT ("run_event_loop ...\n"))); while(!bShutdown) { ACE_OS::last_error(0); result = ACE_Reactor::run_event_loop(); // reenter loop on EINTR if(0 != result && EINTR == ACE_OS::last_error()) { if(bShutdown) break; } else if(0 != result) { ACE_DEBUG (( LM_INFO, ACE_TEXT ("(%P|%t) run_event_loop failed (%s, %d)\n"), ACE_OS::strerror(ACE_OS::last_error()), ACE_OS::last_error() )); } } ACE_DEBUG ((LM_INFO, ACE_TEXT ("(%P|%t) run_event_loop done\n"))); ACE_DEBUG ((LM_INFO, ACE_TEXT ("(%P|%t) serviceConfig.fini_svcs ...\n"))); result = serviceConfig.fini_svcs(); if(0 != result) { ACE_ERROR ((LM_ERROR, ACE_TEXT ("(%P|%t) Error: serviceConfig.fini_svcs failed\n"))); return result; } ACE_DEBUG ((LM_INFO, ACE_TEXT ("(%P|%t) serviceConfig.fini_svcs done\n"))); ACE_DEBUG ((LM_INFO, ACE_TEXT ("(%P|%t) serviceConfig.close ...\n"))); result = serviceConfig.close(); if(0 != result) { ACE_ERROR ((LM_ERROR, ACE_TEXT ("(%P|%t) Error: serviceConfig.close failed\n"))); return result; } ACE_DEBUG ((LM_INFO, ACE_TEXT ("(%P|%t) serviceConfig.close done\n"))); return result; } /* end of if */ else // fork failed { ACE_ERROR ((LM_ERROR, ACE_TEXT ("(%P|%t) Error: fork failed\n"))); return 1; } /* end of else */ #else ACE_UNUSED_ARG (argv); ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Fork not available\n"))); #endif return result; }
int run_main (int argc, ACE_TCHAR *argv[]) { ACE_START_TEST (ACE_TEXT ("MT_Reference_Counted_Notify_Test")); // Validate options. int result = parse_args (argc, argv); if (result != 0) return result; int extra_iterations_needed = 1; int extra_iterations_not_needed = 0; if (test_select_reactor) { ACE_DEBUG ((LM_DEBUG, "\n\nTesting Select Reactor....\n\n")); test<ACE_Select_Reactor> test (extra_iterations_not_needed); ACE_UNUSED_ARG (test); } if (test_tp_reactor) { ACE_DEBUG ((LM_DEBUG, "\n\nTesting TP Reactor....\n\n")); test<ACE_TP_Reactor> test (extra_iterations_not_needed); ACE_UNUSED_ARG (test); } #if defined (ACE_HAS_EVENT_POLL) if (test_dev_poll_reactor) { ACE_DEBUG ((LM_DEBUG, "\n\nTesting Dev Poll Reactor....\n\n")); test<ACE_Dev_Poll_Reactor> test (extra_iterations_not_needed); ACE_UNUSED_ARG (test); } #endif #if defined (ACE_WIN32) if (test_wfmo_reactor) { ACE_DEBUG ((LM_DEBUG, "\n\nTesting WFMO Reactor....\n\n")); test<ACE_WFMO_Reactor> test (extra_iterations_needed); ACE_UNUSED_ARG (test); } #else /* ACE_WIN32 */ ACE_UNUSED_ARG (extra_iterations_needed); #endif /* ACE_WIN32 */ ACE_END_TEST; return 0; }
template <typename SVC_HANDLER, typename PEER_CONNECTOR> int ACE_Strategy_Connector<SVC_HANDLER, PEER_CONNECTOR>::open (ACE_Reactor *r, ACE_Creation_Strategy<SVC_HANDLER> *cre_s, ACE_Connect_Strategy<SVC_HANDLER, PEER_CONNECTOR> *conn_s, ACE_Concurrency_Strategy<SVC_HANDLER> *con_s, int flags) { ACE_TRACE ("ACE_Strategy_Connector<SVC_HANDLER, PEER_CONNECTOR>::open"); this->reactor (r); // @@ Not implemented yet. // this->flags_ = flags; ACE_UNUSED_ARG (flags); // Initialize the creation strategy. // First we decide if we need to clean up. if (this->creation_strategy_ != 0 && this->delete_creation_strategy_ && cre_s != 0) { delete this->creation_strategy_; this->creation_strategy_ = 0; this->delete_creation_strategy_ = false; } if (cre_s != 0) this->creation_strategy_ = cre_s; else if (this->creation_strategy_ == 0) { ACE_NEW_RETURN (this->creation_strategy_, CREATION_STRATEGY (0, r), -1); this->delete_creation_strategy_ = true; } // Initialize the accept strategy. if (this->connect_strategy_ != 0 && this->delete_connect_strategy_ && conn_s != 0) { delete this->connect_strategy_; this->connect_strategy_ = 0; this->delete_connect_strategy_ = false; } if (conn_s != 0) this->connect_strategy_ = conn_s; else if (this->connect_strategy_ == 0) { ACE_NEW_RETURN (this->connect_strategy_, CONNECT_STRATEGY, -1); this->delete_connect_strategy_ = true; } // Initialize the concurrency strategy. if (this->concurrency_strategy_ != 0 && this->delete_concurrency_strategy_ && con_s != 0) { delete this->concurrency_strategy_; this->concurrency_strategy_ = 0; this->delete_concurrency_strategy_ = false; } if (con_s != 0) this->concurrency_strategy_ = con_s; else if (this->concurrency_strategy_ == 0) { ACE_NEW_RETURN (this->concurrency_strategy_, CONCURRENCY_STRATEGY, -1); this->delete_concurrency_strategy_ = true; } return 0; }
int ACE_ATM_Connector::connect (ACE_ATM_Stream &new_stream, const ACE_ATM_Addr &remote_sap, ACE_ATM_Params params, ACE_ATM_QoS options, ACE_Time_Value *timeout, const ACE_ATM_Addr &local_sap, int reuse_addr, int flags, int perms) { ACE_TRACE ("ACE_ATM_Connector::connect"); #if defined (ACE_HAS_FORE_ATM_XTI) return connector_.connect(new_stream.get_stream(), remote_sap, timeout, local_sap, reuse_addr, flags, perms, params.get_device(), params.get_info(), params.get_rw_flag(), params.get_user_data(), &options.get_qos()); #elif defined (ACE_HAS_FORE_ATM_WS2) ACE_DEBUG(LM_DEBUG, ACE_TEXT ("ATM_Connector(connect): set QoS parameters\n" )); ACE_HANDLE s = new_stream.get_handle(); struct sockaddr_atm *saddr = ( struct sockaddr_atm *)remote_sap.get_addr(); ACE_QoS cqos = options.get_qos(); ACE_QoS_Params qos_params = ACE_QoS_Params(0, 0, &cqos, 0, 0); ACE_DEBUG(LM_DEBUG, ACE_TEXT ("ATM_Connector(connect): connecting...\n")); int result = ACE_OS::connect( s, ( struct sockaddr *)saddr, sizeof( struct sockaddr_atm ), qos_params ); if( result != 0 ) ACE_OS::printf( "ATM_Connector(connect): connection failed, %d\n", ::WSAGetLastError()); return result; #elif defined (ACE_HAS_LINUX_ATM) ACE_UNUSED_ARG (params); ACE_UNUSED_ARG (timeout); ACE_UNUSED_ARG (reuse_addr); ACE_UNUSED_ARG (perms); ACE_UNUSED_ARG (flags); ACE_HANDLE handle = new_stream.get_handle(); ATM_QoS qos =options.get_qos(); ATM_Addr *local_addr=(ATM_Addr*)local_sap.get_addr(), *remote_addr=(ATM_Addr*)remote_sap.get_addr(); if(ACE_OS::setsockopt(handle, SOL_ATM, SO_ATMSAP, reinterpret_cast<char*> (&(local_addr->atmsap)), sizeof(local_addr->atmsap)) < 0) { ACE_OS::printf( "ATM_Connector(connect): unable to set atmsap %d\nContinuing...", errno); } if(ACE_OS::setsockopt(handle, SOL_ATM, SO_ATMQOS, reinterpret_cast<char*> (&qos), sizeof(qos)) < 0) { ACE_DEBUG((LM_DEBUG,ACE_TEXT ("ATM_Connector(connect): unable to set qos %d\n"), errno)); return -1; } int result = ACE_OS::connect(handle, (struct sockaddr *)&(remote_addr->sockaddratmsvc), sizeof( remote_addr->sockaddratmsvc)); if( result != 0 ) ACE_DEBUG(LM_DEBUG, ACE_TEXT ("ATM_Connector(connect): connection failed, %d\n"), errno); return result; #else ACE_UNUSED_ARG (new_stream); ACE_UNUSED_ARG (remote_sap); ACE_UNUSED_ARG (params); ACE_UNUSED_ARG (options); ACE_UNUSED_ARG (timeout); ACE_UNUSED_ARG (local_sap); ACE_UNUSED_ARG (reuse_addr); ACE_UNUSED_ARG (flags); ACE_UNUSED_ARG (perms); return 0; #endif /* ACE_HAS_FORE_ATM_XTI || ACE_HAS_FORE_ATM_WS2 || ACE_HAS_LINUX_ATM */ }
ACE_Mutex::ACE_Mutex (int type, const ACE_TCHAR *name, ACE_mutexattr_t *arg, mode_t mode) : #if defined (ACE_HAS_PTHREADS) || defined(ACE_HAS_STHREADS) process_lock_ (0), lockname_ (0), #endif /* ACE_HAS_PTHREADS || ACE_HAS_STHREADS */ removed_ (false) { // ACE_TRACE ("ACE_Mutex::ACE_Mutex"); // These platforms need process-wide mutex to be in shared memory. #if defined(ACE_HAS_PTHREADS) || defined (ACE_HAS_STHREADS) if (type == USYNC_PROCESS) { // Let's see if the shared memory entity already exists. ACE_HANDLE fd = ACE_OS::shm_open (name, O_RDWR | O_CREAT | O_EXCL, mode); if (fd == ACE_INVALID_HANDLE) { if (errno == EEXIST) fd = ACE_OS::shm_open (name, O_RDWR | O_CREAT, mode); else return; } else { // We own this shared memory object! Let's set its size. if (ACE_OS::ftruncate (fd, sizeof (ACE_mutex_t)) == -1) { ACE_OS::close (fd); return; } this->lockname_ = ACE_OS::strdup (name); if (this->lockname_ == 0) { ACE_OS::close (fd); return; } } this->process_lock_ = (ACE_mutex_t *) ACE_OS::mmap (0, sizeof (ACE_mutex_t), PROT_RDWR, MAP_SHARED, fd, 0); ACE_OS::close (fd); if (this->process_lock_ == MAP_FAILED) return; if (this->lockname_ && ACE_OS::mutex_init (this->process_lock_, type, name, arg) != 0) { ACELIB_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("ACE_Mutex::ACE_Mutex"))); return; } } else { // local mutex init if USYNC_PROCESS flag is not enabled. #else ACE_UNUSED_ARG (mode); #endif /* ACE_HAS_PTHREADS || ACE_HAS_STHREADS */ if (ACE_OS::mutex_init (&this->lock_, type, name, arg) != 0) ACELIB_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("ACE_Mutex::ACE_Mutex"))); #if defined(ACE_HAS_PTHREADS) || defined (ACE_HAS_STHREADS) } #endif /* ACE_HAS_PTHREADS || ACE_HAS_STHREADS */ }
template <class SVC_HANDLER, ACE_PEER_CONNECTOR_1, class CACHING_STRATEGY, class ATTRIBUTES, class MUTEX> int ACE_Cached_Connect_Strategy_Ex<SVC_HANDLER, ACE_PEER_CONNECTOR_2, CACHING_STRATEGY, ATTRIBUTES, MUTEX>::check_hint_i (SVC_HANDLER *&sh, const ACE_PEER_CONNECTOR_ADDR &remote_addr, ACE_Time_Value *timeout, const ACE_PEER_CONNECTOR_ADDR &local_addr, bool reuse_addr, int flags, int perms, ACE_Hash_Map_Entry<ACE_Refcounted_Hash_Recyclable<ACE_PEER_CONNECTOR_ADDR>, std::pair<SVC_HANDLER *, ATTRIBUTES> > *&entry, int &found) { ACE_UNUSED_ARG (remote_addr); ACE_UNUSED_ARG (timeout); ACE_UNUSED_ARG (local_addr); ACE_UNUSED_ARG (reuse_addr); ACE_UNUSED_ARG (flags); ACE_UNUSED_ARG (perms); found = 0; // Get the recycling act for the svc_handler CONNECTION_CACHE_ENTRY *possible_entry = (CONNECTION_CACHE_ENTRY *) sh->recycling_act (); // Check to see if the hint svc_handler has been closed down if (possible_entry->ext_id_.recycle_state () == ACE_RECYCLABLE_CLOSED) { // If close, decrement refcount if (possible_entry->ext_id_.decrement () == 0) { // If refcount goes to zero, close down the svc_handler possible_entry->int_id_.first->recycler (0, 0); possible_entry->int_id_.first->close (); this->purge_i (possible_entry); } // Hint not successful found = 0; // Reset hint sh = 0; } // If hint is not closed, see if it is connected to the correct // address and is recyclable else if ((possible_entry->ext_id_.recycle_state () == ACE_RECYCLABLE_IDLE_AND_PURGABLE || possible_entry->ext_id_.recycle_state () == ACE_RECYCLABLE_IDLE_BUT_NOT_PURGABLE) && possible_entry->ext_id_.subject () == remote_addr) { // Hint successful found = 1; // Tell the <svc_handler> that it should prepare itself for // being recycled. this->prepare_for_recycling (sh); // // Update the caching attributes directly since we don't do a // find() on the cache map. // // Indicates successful find. int find_result = 0; int result = this->caching_strategy ().notify_find (find_result, possible_entry->int_id_.second); if (result == -1) return result; } else { // This hint will not be used. possible_entry->ext_id_.decrement (); // Hint not successful found = 0; // If <sh> is not connected to the correct address or is busy, // we will not use it. sh = 0; } if (found) entry = possible_entry; return 0; }
// returns -2 when the hostname is truncated int ACE_INET_Addr::get_host_name_i (char hostname[], size_t len) const { ACE_TRACE ("ACE_INET_Addr::get_host_name_i"); #if defined (ACE_HAS_IPV6) if ((this->get_type () == PF_INET6 && 0 == ACE_OS::memcmp (&this->inet_addr_.in6_.sin6_addr, &in6addr_any, sizeof (this->inet_addr_.in6_.sin6_addr))) || (this->get_type () == PF_INET && this->inet_addr_.in4_.sin_addr.s_addr == INADDR_ANY)) #else if (this->inet_addr_.in4_.sin_addr.s_addr == INADDR_ANY) #endif /* ACE_HAS_IPV6 */ { if (ACE_OS::hostname (hostname, len) == -1) return -1; else return 0; } else { #if defined (ACE_VXWORKS) && defined (ACE_LACKS_GETHOSTBYADDR) ACE_UNUSED_ARG (len); int error = ::hostGetByAddr ((int) this->inet_addr_.in4_.sin_addr.s_addr, hostname); if (error == OK) return 0; else { errno = error; return -1; } #else void* addr = this->ip_addr_pointer (); int size = this->ip_addr_size (); int type = this->get_type (); # if defined (ACE_HAS_IPV6) && defined (ACE_HAS_BROKEN_GETHOSTBYADDR_V4MAPPED) // Most OS can not handle IPv6-mapped-IPv4 addresses (even // though they are meant to) so map them back to IPv4 addresses // before trying to resolve them in_addr demapped_addr; if (type == PF_INET6 && (this->is_ipv4_mapped_ipv6 () || this->is_ipv4_compat_ipv6 ())) { ACE_OS::memcpy (&demapped_addr.s_addr, &this->inet_addr_.in6_.sin6_addr.s6_addr[12], 4); addr = &demapped_addr; size = sizeof(demapped_addr); type = PF_INET; } # endif /* ACE_HAS_IPV6 */ int h_error; // Not the same as errno! hostent hentry; ACE_HOSTENT_DATA buf; hostent * const hp = ACE_OS::gethostbyaddr_r (static_cast <char *> (addr), size, type, &hentry, buf, &h_error); if (hp == 0 || hp->h_name == 0) return -1; if (ACE_OS::strlen (hp->h_name) >= len) { // We know the length, so use memcpy if (len > 0) { ACE_OS::memcpy (hostname, hp->h_name, len - 1); hostname[len-1]= '\0'; } errno = ENOSPC; return -2; // -2 Means that we have a good string // Using errno looks ok, but ENOSPC could be set on // other places. } ACE_OS::strcpy (hostname, hp->h_name); return 0; #endif /* ACE_VXWORKS */ } }
static void test_active_map_manager (size_t table_size, size_t iterations, int test_iterators) { ACTIVE_MAP_MANAGER map (table_size); TYPE i; TYPE j = 0; ssize_t k; ACTIVE_MAP_MANAGER::key_type *active_keys; ACE_NEW (active_keys, ACTIVE_MAP_MANAGER::key_type[iterations]); for (i = 0; i < iterations; i++) ACE_ASSERT (map.bind (i, active_keys[i]) != -1); if (test_iterators) { { i = 0; ACTIVE_MAP_MANAGER::iterator end = map.end (); for (ACTIVE_MAP_MANAGER::iterator iter = map.begin (); iter != end; ++iter) { ACTIVE_MAP_MANAGER::ENTRY &entry = *iter; ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%d|%d-%d|%d)"), i, entry.ext_id_.slot_index (), entry.ext_id_.slot_generation (), entry.int_id_)); ++i; } ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\n"))); ACE_ASSERT (i == iterations); } { k = iterations - 1; ACTIVE_MAP_MANAGER::reverse_iterator rend = map.rend (); for (ACTIVE_MAP_MANAGER::reverse_iterator iter = map.rbegin (); iter != rend; ++iter) { ACTIVE_MAP_MANAGER::ENTRY &entry = *iter; ACE_UNUSED_ARG (entry); ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%d|%d-%d|%d)"), k, entry.ext_id_.slot_index (), entry.ext_id_.slot_generation (), entry.int_id_)); k--; } ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\n"))); ACE_ASSERT (k == -1); } } for (i = 0; i < iterations; ++i) { ACE_ASSERT (map.find (active_keys[i], j) != -1); ACE_ASSERT (i == j); } size_t remaining_entries = iterations; for (i = 0; i < iterations; ++i) { ACE_ASSERT (map.unbind (active_keys[i]) != -1); --remaining_entries; ACE_ASSERT (map.current_size () == remaining_entries); } delete [] active_keys; }
int ACE_Shared_Memory_Pool::handle_signal (int , siginfo_t *siginfo, ucontext_t *) { ACE_TRACE ("ACE_Shared_Memory_Pool::handle_signal"); // ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("signal %S occurred\n"), signum)); // While FreeBSD 5.X has a siginfo_t struct with a si_addr field, // it does not define SEGV_MAPERR. #if defined (ACE_HAS_SIGINFO_T) && !defined (ACE_LACKS_SI_ADDR) && \ (defined (SEGV_MAPERR) || defined (SEGV_MEMERR)) ACE_OFF_T offset; // Make sure that the pointer causing the problem is within the // range of the backing store. if (siginfo != 0) { // ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) si_signo = %d, si_code = %d, addr = %u\n"), siginfo->si_signo, siginfo->si_code, siginfo->si_addr)); size_t counter; if (this->in_use (offset, counter) == -1) ACE_ERROR ((LM_ERROR, ACE_TEXT ("(%P|%t) %p\n"), ACE_TEXT ("in_use"))); else if (!(siginfo->si_code == SEGV_MAPERR && siginfo->si_addr < (((char *) this->base_addr_) + offset) && siginfo->si_addr >= ((char *) this->base_addr_))) ACE_ERROR_RETURN ((LM_ERROR, "(%P|%t) address %u out of range\n", siginfo->si_addr), -1); } // The above if case will check to see that the address is in the // proper range. Therefore there is a segment out there that the // pointer wants to point into. Find the segment that someone else // has used and attach to it ([email protected]) size_t counter; // ret value to get shmid from the st table. if (this->find_seg (siginfo->si_addr, offset, counter) == -1) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("(%P|%t) %p\n"), ACE_TEXT ("in_use")), -1); void *address = (void *) (((char *) this->base_addr_) + offset); SHM_TABLE *st = reinterpret_cast<SHM_TABLE *> (this->base_addr_); void *shmem = ACE_OS::shmat (st[counter].shmid_, (char *) address, 0); if (shmem != address) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT("(%P|%t) %p, shmem = %u, address = %u\n"), ACE_TEXT("shmat"), shmem, address), -1); // NOTE: this won't work if we dont have SIGINFO_T or SI_ADDR #else ACE_UNUSED_ARG (siginfo); #endif /* ACE_HAS_SIGINFO_T && !defined (ACE_LACKS_SI_ADDR) */ return 0; }
struct tm * ACE_OS::localtime_r (const time_t *t, struct tm *res) { ACE_OS_TRACE ("ACE_OS::localtime_r"); #if defined (ACE_HAS_REENTRANT_FUNCTIONS) ACE_OSCALL_RETURN (::localtime_r (t, res), struct tm *, 0); #elif defined (ACE_HAS_TR24731_2005_CRT) ACE_SECURECRTCALL (localtime_s (res, t), struct tm *, 0, res); return res; #elif !defined (ACE_HAS_WINCE) ACE_OS_GUARD ACE_UNUSED_ARG (res); struct tm * res_ptr = 0; ACE_OSCALL (::localtime (t), struct tm *, 0, res_ptr); if (res_ptr == 0) return 0; else { *res = *res_ptr; return res; } #elif defined (ACE_HAS_WINCE) // This is really stupid, converting FILETIME to timeval back and // forth. It assumes FILETIME and DWORDLONG are the same structure // internally. TIME_ZONE_INFORMATION pTz; const unsigned short int __mon_yday[2][13] = { /* Normal years. */ { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 }, /* Leap years. */ { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 } }; ULARGE_INTEGER _100ns; ::GetTimeZoneInformation (&pTz); _100ns.QuadPart = (DWORDLONG) *t * 10000 * 1000 + ACE_Time_Value::FILETIME_to_timval_skew; FILETIME file_time; file_time.dwLowDateTime = _100ns.LowPart; file_time.dwHighDateTime = _100ns.HighPart; FILETIME localtime; SYSTEMTIME systime; FileTimeToLocalFileTime (&file_time, &localtime); FileTimeToSystemTime (&localtime, &systime); res->tm_hour = systime.wHour; if(pTz.DaylightBias!=0) res->tm_isdst = 1; else res->tm_isdst = 1; int iLeap; iLeap = (res->tm_year % 4 == 0 && (res->tm_year% 100 != 0 || res->tm_year % 400 == 0)); // based on leap select which group to use res->tm_mday = systime.wDay; res->tm_min = systime.wMinute; res->tm_mon = systime.wMonth - 1; res->tm_sec = systime.wSecond; res->tm_wday = systime.wDayOfWeek; res->tm_yday = __mon_yday[iLeap][systime.wMonth] + systime.wDay; res->tm_year = systime.wYear;// this the correct year but bias the value to start at the 1900 res->tm_year = res->tm_year - 1900; return res; #else // @@ Same as ACE_OS::localtime (), you need to implement it // yourself. ACE_UNUSED_ARG (t); ACE_UNUSED_ARG (res); ACE_NOTSUP_RETURN (0); #endif /* ACE_HAS_REENTRANT_FUNCTIONS */ }
TAO_Active_Object_Map::TAO_Active_Object_Map ( int user_id_policy, int unique_id_policy, int persistent_id_policy, const TAO_Server_Strategy_Factory::Active_Object_Map_Creation_Parameters & creation_parameters) : user_id_map_ (0) , servant_map_ (0) , id_uniqueness_strategy_ (0) , lifespan_strategy_ (0) , id_assignment_strategy_ (0) , id_hint_strategy_ (0) , using_active_maps_ (false) { TAO_Active_Object_Map::set_system_id_size (creation_parameters); TAO_Id_Uniqueness_Strategy *id_uniqueness_strategy = 0; if (unique_id_policy) { ACE_NEW_THROW_EX (id_uniqueness_strategy, TAO_Unique_Id_Strategy, CORBA::NO_MEMORY ()); } else { #if !defined (CORBA_E_MICRO) ACE_NEW_THROW_EX (id_uniqueness_strategy, TAO_Multiple_Id_Strategy, CORBA::NO_MEMORY ()); #else TAOLIB_ERROR ((LM_ERROR, "Multiple Id Strategy not supported with CORBA/e\n")); #endif } // Give ownership to the auto pointer. auto_ptr<TAO_Id_Uniqueness_Strategy> new_id_uniqueness_strategy (id_uniqueness_strategy); TAO_Lifespan_Strategy *lifespan_strategy = 0; if (persistent_id_policy) { #if !defined (CORBA_E_MICRO) ACE_NEW_THROW_EX (lifespan_strategy, TAO_Persistent_Strategy, CORBA::NO_MEMORY ()); #else ACE_UNUSED_ARG (persistent_id_policy); TAOLIB_ERROR ((LM_ERROR, "Persistent Id Strategy not supported with CORBA/e\n")); #endif } else { ACE_NEW_THROW_EX (lifespan_strategy, TAO_Transient_Strategy, CORBA::NO_MEMORY ()); } // Give ownership to the auto pointer. auto_ptr<TAO_Lifespan_Strategy> new_lifespan_strategy (lifespan_strategy); TAO_Id_Assignment_Strategy *id_assignment_strategy = 0; if (user_id_policy) { #if !defined (CORBA_E_MICRO) ACE_NEW_THROW_EX (id_assignment_strategy, TAO_User_Id_Strategy, CORBA::NO_MEMORY ()); #else TAOLIB_ERROR ((LM_ERROR, "User Id Assignment not supported with CORBA/e\n")); #endif } else if (unique_id_policy) { ACE_NEW_THROW_EX (id_assignment_strategy, TAO_System_Id_With_Unique_Id_Strategy, CORBA::NO_MEMORY ()); } else { #if !defined (CORBA_E_MICRO) ACE_NEW_THROW_EX (id_assignment_strategy, TAO_System_Id_With_Multiple_Id_Strategy, CORBA::NO_MEMORY ()); #else TAOLIB_ERROR ((LM_ERROR, "System Id Assignment with multiple " "not supported with CORBA/e\n")); #endif } // Give ownership to the auto pointer. auto_ptr<TAO_Id_Assignment_Strategy> new_id_assignment_strategy (id_assignment_strategy); TAO_Id_Hint_Strategy *id_hint_strategy = 0; if ((user_id_policy || creation_parameters.allow_reactivation_of_system_ids_) && creation_parameters.use_active_hint_in_ids_) { this->using_active_maps_ = true; ACE_NEW_THROW_EX (id_hint_strategy, TAO_Active_Hint_Strategy ( creation_parameters.active_object_map_size_), CORBA::NO_MEMORY ()); } else { ACE_NEW_THROW_EX (id_hint_strategy, TAO_No_Hint_Strategy, CORBA::NO_MEMORY ()); } // Give ownership to the auto pointer. auto_ptr<TAO_Id_Hint_Strategy> new_id_hint_strategy (id_hint_strategy); servant_map *sm = 0; if (unique_id_policy) { switch (creation_parameters.reverse_object_lookup_strategy_for_unique_id_policy_) { case TAO_LINEAR: #if (TAO_HAS_MINIMUM_POA_MAPS == 0) ACE_NEW_THROW_EX (sm, servant_linear_map ( creation_parameters.active_object_map_size_), CORBA::NO_MEMORY ()); break; #else TAOLIB_ERROR ((LM_ERROR, "linear option for " "-ORBUniqueidPolicyReverseDemuxStrategy " "not supported with minimum POA maps. " "Ingoring option to use default...\n")); /* FALL THROUGH */ #endif /* TAO_HAS_MINIMUM_POA_MAPS == 0 */ case TAO_DYNAMIC_HASH: default: ACE_NEW_THROW_EX (sm, servant_hash_map ( creation_parameters.active_object_map_size_), CORBA::NO_MEMORY ()); break; } } // Give ownership to the auto pointer. auto_ptr<servant_map> new_servant_map (sm); user_id_map *uim = 0; if (user_id_policy || creation_parameters.allow_reactivation_of_system_ids_) { switch (creation_parameters.object_lookup_strategy_for_user_id_policy_) { case TAO_LINEAR: #if (TAO_HAS_MINIMUM_POA_MAPS == 0) ACE_NEW_THROW_EX (uim, user_id_linear_map ( creation_parameters.active_object_map_size_), CORBA::NO_MEMORY ()); break; #else TAOLIB_ERROR ((LM_ERROR, "linear option for -ORBUseridPolicyDemuxStrategy " "not supported with minimum POA maps. " "Ingoring option to use default...\n")); /* FALL THROUGH */ #endif /* TAO_HAS_MINIMUM_POA_MAPS == 0 */ case TAO_DYNAMIC_HASH: default: ACE_NEW_THROW_EX (uim, user_id_hash_map (creation_parameters.active_object_map_size_), CORBA::NO_MEMORY ()); break; } } else { switch (creation_parameters.object_lookup_strategy_for_system_id_policy_) { #if (TAO_HAS_MINIMUM_POA_MAPS == 0) case TAO_LINEAR: ACE_NEW_THROW_EX (uim, user_id_linear_map (creation_parameters.active_object_map_size_), CORBA::NO_MEMORY ()); break; case TAO_DYNAMIC_HASH: ACE_NEW_THROW_EX (uim, user_id_hash_map (creation_parameters.active_object_map_size_), CORBA::NO_MEMORY ()); break; #else case TAO_LINEAR: case TAO_DYNAMIC_HASH: TAOLIB_ERROR ((LM_ERROR, "linear and dynamic options for -ORBSystemidPolicyDemuxStrategy " "are not supported with minimum POA maps. " "Ingoring option to use default...\n")); /* FALL THROUGH */ #endif /* TAO_HAS_MINIMUM_POA_MAPS == 0 */ case TAO_ACTIVE_DEMUX: default: this->using_active_maps_ = true; ACE_NEW_THROW_EX (uim, user_id_active_map (creation_parameters.active_object_map_size_), CORBA::NO_MEMORY ()); break; } } // Give ownership to the auto pointer. auto_ptr<user_id_map> new_user_id_map (uim); id_uniqueness_strategy->set_active_object_map (this); lifespan_strategy->set_active_object_map (this); id_assignment_strategy->set_active_object_map (this); // Finally everything is fine. Make sure to take ownership away // from the auto pointer. this->id_uniqueness_strategy_ = new_id_uniqueness_strategy; this->lifespan_strategy_ = new_lifespan_strategy; this->id_assignment_strategy_ = new_id_assignment_strategy; this->id_hint_strategy_ = new_id_hint_strategy; this->servant_map_ = new_servant_map; this->user_id_map_ = new_user_id_map; #if defined (TAO_HAS_MONITOR_POINTS) && (TAO_HAS_MONITOR_POINTS == 1) ACE_NEW (this->monitor_, ACE::Monitor_Control::Size_Monitor); #endif /* TAO_HAS_MONITOR_POINTS==1 */ }
void Splot_BackgroundSea::setVariation (int index_in) { ACE_UNUSED_ARG (index_in); }
void ReplayerListener::on_replayer_matched(Replayer* replayer, const ::DDS::PublicationMatchedStatus & status ) { ACE_UNUSED_ARG(replayer); ACE_UNUSED_ARG(status); }
int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { ACE_UNUSED_ARG (argc); ACE_UNUSED_ARG (argv); ACE_DLL dll; int retval = dll.open (ACE_DLL_PREFIX ACE_TEXT("DLL_Today")); if (retval != 0) ACE_ERROR_RETURN ((LM_ERROR, "%p", "dll.open"), -1); Magazine_Creator mc; // Cast the void* to non-pointer type first - it's not legal to // cast a pointer-to-object directly to a pointer-to-function. void *void_ptr = dll.symbol (ACE_TEXT ("create_magazine")); ptrdiff_t tmp = reinterpret_cast<ptrdiff_t> (void_ptr); mc = reinterpret_cast<Magazine_Creator> (tmp); if (mc == 0) { ACE_ERROR_RETURN ((LM_ERROR, "%p", "dll.symbol"), -1); } { auto_ptr <Magazine> magazine (mc ()); magazine->title (); } dll.close (); // The other library is now loaded on demand. retval = dll.open (ACE_DLL_PREFIX ACE_TEXT ("DLL_Newsweek")); if (retval != 0) { ACE_ERROR_RETURN ((LM_ERROR, "%p", "dll.open"), -1); } // Cast the void* to non-pointer type first - it's not legal to // cast a pointer-to-object directly to a pointer-to-function. void_ptr = dll.symbol (ACE_TEXT ("create_magazine")); tmp = reinterpret_cast<ptrdiff_t> (void_ptr); mc = reinterpret_cast<Magazine_Creator> (tmp); if (mc == 0) { ACE_ERROR_RETURN ((LM_ERROR, "%p", "dll.symbol"), -1); } { auto_ptr <Magazine> magazine (mc ()); magazine->title (); } dll.close (); return 0; }
ACE_BEGIN_VERSIONED_NAMESPACE_DECL int ACE_OS::getmacaddress (struct macaddr_node_t *node) { ACE_OS_TRACE ("ACE_OS::getmacaddress"); #if defined (ACE_WIN32) && !defined (ACE_HAS_WINCE) # if !defined (ACE_HAS_PHARLAP) /** Define a structure for use with the netbios routine */ struct ADAPTERSTAT { ADAPTER_STATUS adapt; NAME_BUFFER NameBuff [30]; }; NCB ncb; LANA_ENUM lenum; unsigned char result; ACE_OS::memset (&ncb, 0, sizeof(ncb)); ncb.ncb_command = NCBENUM; ncb.ncb_buffer = reinterpret_cast<unsigned char*> (&lenum); ncb.ncb_length = sizeof(lenum); result = Netbios (&ncb); for(int i = 0; i < lenum.length; i++) { ACE_OS::memset (&ncb, 0, sizeof(ncb)); ncb.ncb_command = NCBRESET; ncb.ncb_lana_num = lenum.lana [i]; /** Reset the netbios */ result = Netbios (&ncb); if (ncb.ncb_retcode != NRC_GOODRET) { return -1; } ADAPTERSTAT adapter; ACE_OS::memset (&ncb, 0, sizeof (ncb)); ACE_OS::strcpy (reinterpret_cast<char*> (ncb.ncb_callname), "*"); ncb.ncb_command = NCBASTAT; ncb.ncb_lana_num = lenum.lana[i]; ncb.ncb_buffer = reinterpret_cast<unsigned char*> (&adapter); ncb.ncb_length = sizeof (adapter); result = Netbios (&ncb); if (result == 0) { ACE_OS::memcpy (node->node, adapter.adapt.adapter_address, 6); return 0; } } return 0; # else # if defined (ACE_HAS_PHARLAP_RT) DEVHANDLE ip_dev = (DEVHANDLE)0; EK_TCPIPCFG *devp = 0; size_t i; ACE_TCHAR dev_name[16]; for (i = 0; i < 10; i++) { // Ethernet. ACE_OS::sprintf (dev_name, "ether%d", i); ip_dev = EtsTCPGetDeviceHandle (dev_name); if (ip_dev != 0) break; } if (ip_dev == 0) return -1; devp = EtsTCPGetDeviceCfg (ip_dev); if (devp == 0) return -1; ACE_OS::memcpy (node->node, &devp->EthernetAddress[0], 6); return 0; # else ACE_UNUSED_ARG (node); ACE_NOTSUP_RETURN (-1); # endif /* ACE_HAS_PHARLAP_RT */ # endif /* ACE_HAS_PHARLAP */ #elif defined (sun) /** obtain the local host name */ char hostname [MAXHOSTNAMELEN]; ACE_OS::hostname (hostname, sizeof (hostname)); /** Get the hostent to use with ioctl */ struct hostent *phost = ACE_OS::gethostbyname (hostname); if (phost == 0) return -1; ACE_HANDLE handle = ACE_OS::socket (PF_INET, SOCK_DGRAM, IPPROTO_UDP); if (handle == ACE_INVALID_HANDLE) return -1; char **paddrs = phost->h_addr_list; struct arpreq ar; struct sockaddr_in *psa = (struct sockaddr_in *)&(ar.arp_pa); ACE_OS::memset (&ar, 0, sizeof (struct arpreq)); psa->sin_family = AF_INET; ACE_OS::memcpy (&(psa->sin_addr), *paddrs, sizeof (struct in_addr)); if (ACE_OS::ioctl (handle, SIOCGARP, &ar) == -1) { ACE_OS::close (handle); return -1; } ACE_OS::close (handle); ACE_OS::memcpy (node->node, ar.arp_ha.sa_data, 6); return 0; #elif defined (ACE_LINUX) && !defined (ACE_LACKS_NETWORKING) // It's easiest to know the first MAC-using interface. Use the BSD // getifaddrs function that simplifies access to connected interfaces. struct ifaddrs *ifap = 0; struct ifaddrs *p_if = 0; if (::getifaddrs (&ifap) != 0) return -1; for (p_if = ifap; p_if != 0; p_if = p_if->ifa_next) { if (p_if->ifa_addr == 0) continue; // Check to see if it's up and is not either PPP or loopback if ((p_if->ifa_flags & IFF_UP) == IFF_UP && (p_if->ifa_flags & (IFF_LOOPBACK | IFF_POINTOPOINT)) == 0) break; } if (p_if == 0) { errno = ENODEV; ::freeifaddrs (ifap); return -1; } struct ifreq ifr; ACE_OS::strcpy (ifr.ifr_name, p_if->ifa_name); ::freeifaddrs (ifap); ACE_HANDLE handle = ACE_OS::socket (PF_INET, SOCK_DGRAM, 0); if (handle == ACE_INVALID_HANDLE) return -1; if (ACE_OS::ioctl (handle/*s*/, SIOCGIFHWADDR, &ifr) < 0) { ACE_OS::close (handle); return -1; } struct sockaddr* sa = (struct sockaddr *) &ifr.ifr_addr; ACE_OS::close (handle); ACE_OS::memcpy (node->node, sa->sa_data, 6); return 0; #elif defined (ACE_HAS_SIOCGIFCONF) const long BUFFERSIZE = 4000; char buffer[BUFFERSIZE]; struct ifconf ifc; struct ifreq* ifr = 0; ACE_HANDLE handle = ACE_OS::socket (AF_INET, SOCK_DGRAM, 0); if (handle == ACE_INVALID_HANDLE) { return -1; } ifc.ifc_len = BUFFERSIZE; ifc.ifc_buf = buffer; if (ACE_OS::ioctl (handle, SIOCGIFCONF, &ifc) < 0) { ACE_OS::close (handle); return -1; } for(char* ptr=buffer; ptr < buffer + ifc.ifc_len; ) { ifr = (struct ifreq *) ptr; if (ifr->ifr_addr.sa_family == AF_LINK) { if(ACE_OS::strcmp (ifr->ifr_name, "en0") == 0) { struct sockaddr_dl* sdl = (struct sockaddr_dl *) &ifr->ifr_addr; ACE_OS::memcpy (node->node, LLADDR(sdl), 6); } } ptr += sizeof(ifr->ifr_name); if(sizeof(ifr->ifr_addr) > ifr->ifr_addr.sa_len) ptr += sizeof(ifr->ifr_addr); else ptr += ifr->ifr_addr.sa_len; } ACE_OS::close (handle); return 0; #else ACE_UNUSED_ARG (node); ACE_NOTSUP_RETURN (-1); #endif }
ACE_Process_Options::ACE_Process_Options (bool inherit_environment, size_t command_line_buf_len, size_t env_buf_len, size_t max_env_args, size_t max_cmdline_args) : #if !defined (ACE_HAS_WINCE) inherit_environment_ (inherit_environment), #endif /* ACE_HAS_WINCE */ creation_flags_ (0), avoid_zombies_ (0), #if !defined (ACE_HAS_WINCE) #if defined (ACE_WIN32) environment_inherited_ (0), process_attributes_ (0), thread_attributes_ (0), #else /* ACE_WIN32 */ stdin_ (ACE_INVALID_HANDLE), stdout_ (ACE_INVALID_HANDLE), stderr_ (ACE_INVALID_HANDLE), ruid_ ((uid_t) -1), euid_ ((uid_t) -1), rgid_ ((uid_t) -1), egid_ ((uid_t) -1), #endif /* ACE_WIN32 */ handle_inheritance_ (true), set_handles_called_ (0), environment_buf_index_ (0), environment_argv_index_ (0), environment_buf_ (0), environment_buf_len_ (env_buf_len), max_environment_args_ (max_env_args), max_environ_argv_index_ (max_env_args - 1), #endif /* !ACE_HAS_WINCE */ command_line_argv_calculated_ (false), command_line_buf_ (0), command_line_copy_ (0), command_line_buf_len_ (command_line_buf_len), max_command_line_args_ (max_cmdline_args), command_line_argv_ (0), process_group_ (ACE_INVALID_PID), use_unicode_environment_ (false) { ACE_NEW (command_line_buf_, ACE_TCHAR[command_line_buf_len]); command_line_buf_[0] = '\0'; process_name_[0] = '\0'; #if defined (ACE_HAS_WINCE) ACE_UNUSED_ARG(inherit_environment); ACE_UNUSED_ARG(env_buf_len); ACE_UNUSED_ARG(max_env_args); #endif #if !defined (ACE_HAS_WINCE) working_directory_[0] = '\0'; ACE_NEW (environment_buf_, ACE_TCHAR[env_buf_len]); ACE_NEW (environment_argv_, ACE_TCHAR *[max_env_args]); environment_buf_[0] = '\0'; environment_argv_[0] = 0; #if defined (ACE_WIN32) ACE_OS::memset ((void *) &this->startup_info_, 0, sizeof this->startup_info_); this->startup_info_.cb = sizeof this->startup_info_; #endif /* ACE_WIN32 */ #endif /* !ACE_HAS_WINCE */ ACE_NEW (command_line_argv_, ACE_TCHAR *[max_cmdline_args]); }
int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { try { Consumer_Client client; int status = client.init (argc, argv); ACE_ASSERT(status == 0); ACE_UNUSED_ARG(status); CosNotifyChannelAdmin::EventChannel_var ec = client.create_event_channel ("MyEventChannel", 1); CORBA::ORB_ptr orb = client.orb (); CORBA::Object_var object = orb->string_to_object (ior); sig_var sig = sig::_narrow (object.in ()); ACE_ASSERT(! CORBA::is_nil (sig.in ())); CosNotifyChannelAdmin::ConsumerAdmin_var admin = create_consumeradmin (ec.in ()); if (filter) { CosNotifyFilter::FilterFactory_var ffact = ec->default_filter_factory (); CosNotifyFilter::Filter_var filter = ffact->create_filter ("TCL"); ACE_ASSERT(! CORBA::is_nil(filter.in())); CosNotifyFilter::ConstraintExpSeq constraint_list (1); constraint_list.length(1); constraint_list[0].event_types.length (0); constraint_list[0].constraint_expr = CORBA::string_dup(ACE_TEXT_ALWAYS_CHAR (constraintString)); filter->add_constraints (constraint_list); admin->add_filter(filter.in()); } ACE_ASSERT (!CORBA::is_nil (admin.in ())); create_consumers(admin.in (), &client); // Tell the supplier to go sig->go (); client.ORB_run( ); ACE_DEBUG((LM_DEBUG, "Consumer done.\n")); sig->done (); return 0; } catch (const CORBA::Exception& e) { e._tao_print_exception ("Error: Consumer exception: "); } return 1; }
int ACE_SPIPE_Connector::connect (ACE_SPIPE_Stream &new_io, const ACE_SPIPE_Addr &remote_sap, ACE_Time_Value *timeout, const ACE_Addr & /* local_sap */, int /* reuse_addr */, int flags, int perms, LPSECURITY_ATTRIBUTES sa, int pipe_mode) { ACE_TRACE ("ACE_SPIPE_Connector::connect"); // Make darn sure that the O_CREAT flag is not set! ACE_CLR_BITS (flags, O_CREAT); ACE_HANDLE handle; ACE_UNUSED_ARG (pipe_mode); #if defined (ACE_WIN32) && \ !defined (ACE_HAS_PHARLAP) && !defined (ACE_HAS_WINCE) // We need to allow for more than one attempt to connect, // calculate the absolute time at which we give up. ACE_Time_Value absolute_time; if (timeout != 0) absolute_time = ACE_OS::gettimeofday () + *timeout; // Loop until success or failure. for (;;) { handle = ACE_OS::open (remote_sap.get_path_name(), flags, perms, sa); if (handle != ACE_INVALID_HANDLE) // Success! break; // Check if we have a busy pipe condition. if (::GetLastError() != ERROR_PIPE_BUSY) // Nope, this is a failure condition. break; // This will hold the time out value used in the ::WaitNamedPipe // call. DWORD time_out_value; // Check if we are to block until we connect. if (timeout == 0) // Wait for as long as it takes. time_out_value = NMPWAIT_WAIT_FOREVER; else { // Calculate the amount of time left to wait. ACE_Time_Value relative_time (absolute_time - ACE_OS::gettimeofday ()); // Check if we have run out of time. if (relative_time <= ACE_Time_Value::zero) { // Mimick the errno value returned by // ACE::handle_timed_open. if (*timeout == ACE_Time_Value::zero) errno = EWOULDBLOCK; else errno = ETIMEDOUT; // Exit the connect loop with the failure. break; } // Get the amount of time remaining for ::WaitNamedPipe. time_out_value = relative_time.msec (); } // Wait for the named pipe to become available. ACE_TEXT_WaitNamedPipe (remote_sap.get_path_name (), time_out_value); // Regardless of the return value, we'll do one more attempt to // connect to see if it is now available and to return // consistent error values. } // Set named pipe mode if we have a valid handle. if (handle != ACE_INVALID_HANDLE) { // Check if we are changing the pipe mode from the default. if (pipe_mode != (PIPE_READMODE_BYTE | PIPE_WAIT)) { DWORD dword_pipe_mode = pipe_mode; if (!::SetNamedPipeHandleState (handle, &dword_pipe_mode, 0, 0)) { // We were not able to put the pipe into the requested // mode. ACE_OS::close (handle); handle = ACE_INVALID_HANDLE; } } } #else /* ACE_WIN32 && !ACE_HAS_PHARLAP */ handle = ACE::handle_timed_open (timeout, remote_sap.get_path_name (), flags, perms, sa); #endif /* !ACE_WIN32 || ACE_HAS_PHARLAP || ACE_HAS_WINCE */ new_io.set_handle (handle); new_io.remote_addr_ = remote_sap; // class copy. return handle == ACE_INVALID_HANDLE ? -1 : 0; }
int // This has been unconditionally turned on for the time being since I can't // figure out an easy way to enable it and still keep ACE_TMAIN in a seperate // cpp. #if 1 || defined (ACE_HAS_NONSTATIC_OBJECT_MANAGER) || defined (ACE_LACKS_FORK) // ACE_HAS_NONSTATIC_OBJECT_MANAGER only allows main to have two // arguments. And on platforms that lack fork (), we can't use spawn. run_main (int argc, ACE_TCHAR* []) { ACE_UNUSED_ARG (argc); // Only Win32 can set wide-char environment strings. So, for all // others, use char string literals regardless of ACE_USES_WCHAR. # if defined (ACE_WIN32) ACE_OS::putenv (ACE_TEXT ("TEST_VALUE_POSITIVE=10.2")); ACE_OS::putenv (ACE_TEXT ("TEST_VALUE_NEGATIVE=-10.2")); # else ACE_OS::putenv ("TEST_VALUE_POSITIVE=10.2"); ACE_OS::putenv ("TEST_VALUE_NEGATIVE=-10.2"); # endif /* ACE_WIN32 */ #else /* ! ACE_HAS_NONSTATIC_OBJECT_MANAGER && ! ACE_LACKS_FORK */ run_main (int argc, ACE_TCHAR * [], ACE_TCHAR *envp[]) { if (argc == 1) { int status; // No arguments means we're the initial test. ACE_Process_Options options (1); status = options.setenv (envp); if (status != 0) ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("setenv(envp)"))); options.command_line (ACE_TEXT (".") ACE_DIRECTORY_SEPARATOR_STR ACE_TEXT ("Env_Value_Test run_as_test")); status = options.setenv (ACE_TEXT ("TEST_VALUE_POSITIVE"), ACE_TEXT ("%s"), ACE_TEXT ("10.2")); if (status != 0) ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("setenv(TEST_VALUE_POSITIVE)"))); status = options.setenv (ACE_TEXT ("TEST_VALUE_NEGATIVE"), ACE_TEXT ("%s"), ACE_TEXT ("-10.2")); if (status != 0) ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("setenv(TEST_VALUE_NEGATIVE)"))); ACE_Process p; pid_t result = p.spawn (options); if (result == -1) ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("spawn"))); else p.wait (); } else #endif /* ! ACE_HAS_NONSTATIC_OBJECT_MANAGER && ! ACE_LACKS_FORK */ { // In this case we're the child ACE_START_TEST (ACE_TEXT ("Env_Value_Test")); TEST_THIS (int, ACE_TEXT ("TEST_VALUE_POSITIVE"), 4, 10); TEST_THIS (double, ACE_TEXT ("TEST_VALUE_POSITIVE"), -1.0, 10.2); TEST_THIS (long, ACE_TEXT ("TEST_VALUE_POSITIVE"), 0, 10); TEST_THIS (unsigned long, ACE_TEXT ("TEST_VALUE_POSITIVE"), 0, 10); TEST_THIS (short, ACE_TEXT ("TEST_VALUE_POSITIVE"), 0, 10); TEST_THIS (unsigned short, ACE_TEXT ("TEST_VALUE_POSITIVE"), 0, 10); TEST_THIS (int, ACE_TEXT ("TEST_VALUE_NEGATIVE"), 4, -10); TEST_THIS (double, ACE_TEXT ("TEST_VALUE_NEGATIVE"), -1.0, -10.2); TEST_THIS (long, ACE_TEXT ("TEST_VALUE_NEGATIVE"), 0, -10L); TEST_THIS (unsigned long, ACE_TEXT ("TEST_VALUE_NEGATIVE"), 0, (unsigned long) -10); TEST_THIS (short, ACE_TEXT ("TEST_VALUE_NEGATIVE"), 0, -10); TEST_THIS (unsigned short, ACE_TEXT ("TEST_VALUE_NEGATIVE"), 0, (unsigned short) -10); const ACE_TCHAR *defstr = ACE_TEXT ("Sarah Cleeland is Two!"); ACE_Env_Value<const ACE_TCHAR *> sval (ACE_TEXT ("This_Shouldnt_Be_Set_Hopefully"), defstr); if (ACE_OS::strcmp (sval, defstr) != 0) ACE_ERROR ((LM_ERROR, ACE_TEXT ("Mismatch: %s should be %s\n"), (const ACE_TCHAR *)sval, defstr)); ACE_END_TEST; } return 0; }
void Obj_Module::add_source(const char *p, int imports_only) { ACE_Process nmproc; ACE_Process_Options nm_opts; ACE_CString path (p); ACE_CString::size_type pathsep = path.rfind('/'); ACE_CString src_name; ACE_CString workpath; if (pathsep == ACE_CString::npos) { src_name = path; workpath = "."; } else { src_name = path.substr(pathsep+1); workpath= path.substr(0,pathsep); } ACE_HANDLE pipe[2]; ACE_Pipe io(pipe); nm_opts.working_directory (workpath.c_str()); nm_opts.set_handles (ACE_STDIN,pipe[1]); // Options for the command line shown here are for the GNU nm 2.9.5 int result = nm_opts.command_line ("nm -C %s",src_name.c_str()); // Prevent compiler warning about "unused variable" if ACE_ASSERT is // an empty macro. ACE_UNUSED_ARG (result); ACE_ASSERT (result == 0); nmproc.spawn (nm_opts); if (ACE_OS::close(pipe[1]) == -1) ACE_DEBUG ((LM_DEBUG, "%p\n", "close")); nm_opts.release_handles(); int import_lines = 0; int export_lines = 0; ACE_Message_Block im_buffer (102400); ACE_Message_Block ex_buffer (102400); ACE_Message_Block *im_buf_cur = &im_buffer; ACE_Message_Block *ex_buf_cur = &ex_buffer; char dummy; int eoln = 1; // ACE_Time_Value timeout (1,0); int is_import = 1; int is_export = 1; while (eoln == 1) { for (int i = 0; i < 10; i++) { if (ACE_OS::read(pipe[0],&dummy,1) != 1) { eoln = 2; break; } } if (eoln == 2) break; is_import = dummy == 'U'; is_export = !imports_only && (ACE_OS::strchr("BCDRTVW",dummy) != 0); // if (ACE::recv(pipe[0],&dummy,1,&timeout) != 1) if (ACE_OS::read(pipe[0],&dummy,1) != 1) break; eoln = this->read_line (pipe[0], is_import ? &im_buf_cur : (is_export ? &ex_buf_cur : 0)); import_lines += is_import; export_lines += is_export; } // ACE_DEBUG ((LM_DEBUG, "read %d import lines and %d export lines\n", // import_lines, export_lines)); nmproc.wait (); ACE_OS::close (pipe[0]); this->populate_sig_list (imports_,import_lines,&im_buffer); if (!imports_only) this->populate_sig_list (exports_,export_lines,&ex_buffer); }
int Connector::connect (ACE_HANDLE &client_handle, ACE_HANDLE &server_handle, int run_receiver_thread) { // // Create a connection and a receiver to receive messages on the // connection. // Pipe pipe; int result = 0; for (int i = 0; i < pipe_open_attempts; ++i) { result = pipe.open (); if (result == 0) break; if (result == -1) ACE_OS::sleep (pipe_retry_timeout); } ACE_TEST_ASSERT (result == 0); ACE_UNUSED_ARG (result); Receiver *receiver = new Receiver (this->thread_manager_, pipe.write_handle (), this->nested_upcalls_); // Either the receiver is threaded or register it with the Reactor. if (run_receiver_thread) result = receiver->activate (); else { result = this->reactor_.register_handler (pipe.write_handle (), receiver, ACE_Event_Handler::READ_MASK); // The reference count on the receiver was increased by the // Reactor. ACE_Event_Handler_var safe_receiver (receiver); } ACE_TEST_ASSERT (result == 0); ACE_UNUSED_ARG (result); client_handle = pipe.read_handle (); server_handle = pipe.write_handle (); if (debug) ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%t) New connection: client handle = %d, ") ACE_TEXT ("server handle = %d\n"), client_handle, server_handle)); return 0; }
int ACE_ATM_Stream::get_vpi_vci (ACE_UINT16 &vpi, ACE_UINT16 &vci) const { ACE_TRACE ("ACE_ATM_Stream::get_vpi_vci"); #if defined (ACE_HAS_FORE_ATM_XTI) struct t_atm_conn_prop conn_prop; char* connect_opts = (char *) &conn_prop; int opt_size = sizeof (t_atm_conn_prop); struct t_info info; struct t_optmgmt opt_req, opt_ret; if (ACE_OS::t_getinfo (stream_.get_handle (), &info) < 0) { ACE_OS::t_error ("t_getinfo"); return -1; } char *buf_req = (char *) ACE_OS::malloc (info.options); if (buf_req == 0) { ACE_OS::fprintf (stderr, "Unable to allocate %ld bytes for options\n", info.options); return -1; } char *buf_ret = (char *) ACE_OS::malloc (info.options); if (buf_ret == 0) { ACE_OS::fprintf (stderr, "Unable to allocate %ld bytes for options\n", info.options); return -1; } ACE_OS::memset (&opt_req, 0, sizeof (opt_req)); ACE_OS::memset (&opt_ret, 0, sizeof (opt_ret)); struct t_opthdr *popt = (struct t_opthdr *) buf_req; struct t_opthdr *popt_ret = (struct t_opthdr *) buf_ret; popt->len= sizeof (struct t_opthdr) + opt_size; // We are only concerned with SVCs so no other check or values are needed // here. popt->level = T_ATM_SIGNALING; popt->name = T_ATM_CONN_PROP; popt->status = 0; opt_req.opt.len = popt->len; opt_req.opt.buf = (char *) popt; opt_req.flags = T_CURRENT; popt = T_OPT_NEXTHDR (buf_req, info.options, popt); opt_ret.opt.maxlen = info.options; opt_ret.opt.buf = (char *) popt_ret; if (ACE_OS::t_optmgmt (stream_.get_handle (), &opt_req, &opt_ret) < 0) { ACE_OS::t_error ("t_optmgmt"); return -1; } ACE_OS::memcpy (connect_opts, (char *) popt_ret + sizeof (struct t_opthdr), opt_size); ACE_OS::free (buf_ret); ACE_OS::free (buf_req); vpi = conn_prop.vpi; vci = conn_prop.vci; return 0; #elif defined (ACE_HAS_FORE_ATM_WS2) ATM_CONNECTION_ID connID; DWORD bytes = 0; if (::WSAIoctl ((int) this -> get_handle (), SIO_GET_ATM_CONNECTION_ID, 0, 0, (LPVOID) &connID, sizeof (ATM_CONNECTION_ID), &bytes, 0, 0) == SOCKET_ERROR) { ACE_OS::printf ("Error: WSAIoctl %d\n", WSAGetLastError ()); } vpi = (ACE_UINT16) connID.VPI; vci = (ACE_UINT16) connID.VCI; return 0; #elif defined (ACE_HAS_LINUX_ATM) #if defined (SO_ATMPVC) /* atm version>=0.62 */ struct sockaddr_atmpvc mypvcaddr; int addrpvclen = sizeof (mypvcaddr); if (ACE_OS::getsockopt (stream_.get_handle (), SOL_ATM, SO_ATMPVC, reinterpret_cast<char*> (&mypvcaddr), &addrpvclen) < 0) { ACE_DEBUG (LM_DEBUG, ACE_TEXT ("ACE_ATM_Stream::get_vpi_vci: getsockopt %d\n"), errno); return -1; } vpi = (ACE_UINT16) mypvcaddr.sap_addr.vpi; vci = (ACE_UINT16) mypvcaddr.sap_addr.vci; return 0; #elif defined (SO_VCID) /* patch for atm version 0.59 */ struct atm_vcid mypvcid; int pvcidlen = sizeof (mypvcid); if (ACE_OS::getsockopt (stream_.get_handle (), SOL_ATM,SO_VCID, reinterpret_cast<char*> (&mypvcid), &pvcidlen) < 0) { ACE_DEBUG (LM_DEBUG, ACE_TEXT ("ACE_ATM_Stream::get_vpi_vci: getsockopt %d\n"), errno); return -1; } vpi = (ACE_UINT16) mypvcid.vpi; vci = (ACE_UINT16) mypvcid.vci; return 0; #else ACE_DEBUG (LM_DEBUG, ACE_TEXT ("ACE_ATM_Stream::get_vpi_vci: Not implemented in this ATM version. Update to >= 0.62\n Or patch 0.59")); ACE_UNUSED_ARG (vci); ACE_UNUSED_ARG (vpi); return -1; #endif /* SO_ATMPVC || SO_VCID */ #else return -1; #endif /* ACE_HAS_FORE_ATM_XTI || ACE_HAS_FORE_ATM_WS2 || ACE_HAS_LINUX_ATM */ }
int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { CORBA::Boolean result = 0; try { CORBA::ORB_var orb = CORBA::ORB_init (argc, argv); if (parse_args (argc, argv) != 0) return 1; CORBA::Object_var tmp = orb->string_to_object(ior ); Test::Hello_var hello = Test::Hello::_narrow(tmp.in () ); if (CORBA::is_nil (hello.in ())) { ACE_ERROR_RETURN ((LM_DEBUG, "Test failed - Not regression - Unexpected Nil Test::Hello reference <%s>\n", ior), 1); } // Check this isn't generating transients for any other reason hello->ping (); try { hello->throw_location_forward (); ACE_DEBUG ((LM_ERROR, "REGRESSION - Test has failed !!!\n")); result = 1; } catch (CORBA::TRANSIENT my_ex) { ACE_UNUSED_ARG (my_ex); ACE_DEBUG ((LM_DEBUG, "Client catches a TRANSIENT, as expected. No problem !\n")); } hello->shutdown (); orb->destroy (); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ( "Test failed (Not regression) because unexpected exception caught:"); return 1; } if (result) { ACE_DEBUG ((LM_ERROR, "Error: REGRESSION identified!!!\n")); } else { ACE_DEBUG ((LM_DEBUG, "Test passed !!!\n")); } return result; }
int ACE_TTY_IO::control (Control_Mode cmd, Serial_Params *arg) const { #if defined (ACE_HAS_TERMIOS) || defined (ACE_HAS_TERMIO) #if defined (ACE_HAS_TERMIOS) struct termios devpar; speed_t newbaudrate = 0; if(tcgetattr (get_handle () , &devpar) == -1) #elif defined (TCGETS) struct termios devpar; unsigned int newbaudrate = 0; if(this->ACE_IO_SAP::control (TCGETS, static_cast<void*>(&devpar)) == -1) #elif defined (TCGETA) struct termio devpar; unsigned int newbaudrate = 0; if(this->ACE_IO_SAP::control (TCGETA, static_cast<void*>(&devpar)) == -1) #else errno = ENOSYS; #endif /* ACE_HAS_TERMIOS */ return -1; switch(cmd) { case SETPARAMS: switch(arg->baudrate) { #if defined (B0) case 0: newbaudrate = B0; break; #endif /* B0 */ #if defined (B50) case 50: newbaudrate = B50; break; #endif /* B50 */ #if defined (B75) case 75: newbaudrate = B75; break; #endif /* B75 */ #if defined (B110) case 110: newbaudrate = B110; break; #endif /* B110 */ #if defined (B134) case 134: newbaudrate = B134; break; #endif /* B134 */ #if defined (B150) case 150: newbaudrate = B150; break; #endif /* B150 */ #if defined (B200) case 200: newbaudrate = B200; break; #endif /* B200 */ #if defined (B300) case 300: newbaudrate = B300; break; #endif /* B300 */ #if defined (B600) case 600: newbaudrate = B600; break; #endif /* B600 */ #if defined (B1200) case 1200: newbaudrate = B1200; break; #endif /* B1200 */ #if defined (B1800) case 1800: newbaudrate = B1800; break; #endif /* B1800 */ #if defined (B2400) case 2400: newbaudrate = B2400; break; #endif /* B2400 */ #if defined (B4800) case 4800: newbaudrate = B4800; break; #endif /* B4800 */ #if defined (B9600) case 9600: newbaudrate = B9600; break; #endif /* B9600 */ #if defined (B19200) case 19200: newbaudrate = B19200; break; #endif /* B19200 */ #if defined (B38400) case 38400: newbaudrate = B38400; break; #endif /* B38400 */ #if defined (B56000) case 56000: newbaudrate = B56000; break; #endif /* B56000 */ #if defined (B57600) case 57600: newbaudrate = B57600; break; #endif /* B57600 */ #if defined (B76800) case 76800: newbaudrate = B76800; break; #endif /* B76800 */ #if defined (B115200) case 115200: newbaudrate = B115200; break; #endif /* B115200 */ #if defined (B128000) case 128000: newbaudrate = B128000; break; #endif /* B128000 */ #if defined (B153600) case 153600: newbaudrate = B153600; break; #endif /* B153600 */ #if defined (B230400) case 230400: newbaudrate = B230400; break; #endif /* B230400 */ #if defined (B307200) case 307200: newbaudrate = B307200; break; #endif /* B307200 */ #if defined (B256000) case 256000: newbaudrate = B256000; break; #endif /* B256000 */ #if defined (B460800) case 460800: newbaudrate = B460800; break; #endif /* B460800 */ #if defined (B500000) case 500000: newbaudrate = B500000; break; #endif /* B500000 */ #if defined (B576000) case 576000: newbaudrate = B576000; break; #endif /* B576000 */ #if defined (B921600) case 921600: newbaudrate = B921600; break; #endif /* B921600 */ #if defined (B1000000) case 1000000: newbaudrate = B1000000; break; #endif /* B1000000 */ #if defined (B1152000) case 1152000: newbaudrate = B1152000; break; #endif /* B1152000 */ #if defined (B1500000) case 1500000: newbaudrate = B1500000; break; #endif /* B1500000 */ #if defined (B2000000) case 2000000: newbaudrate = B2000000; break; #endif /* B2000000 */ #if defined (B2500000) case 2500000: newbaudrate = B2500000; break; #endif /* B2500000 */ #if defined (B3000000) case 3000000: newbaudrate = B3000000; break; #endif /* B3000000 */ #if defined (B3500000) case 3500000: newbaudrate = B3500000; break; #endif /* B3500000 */ #if defined (B4000000) case 4000000: newbaudrate = B4000000; break; #endif /* B4000000 */ default: return -1; } #if defined (ACE_HAS_TERMIOS) // Can you really have different input and output baud rates?! if(cfsetospeed (&devpar, newbaudrate) == -1) return -1; if(cfsetispeed (&devpar, newbaudrate) == -1) return -1; #else devpar.c_cflag &= ~CBAUD; # if defined (CBAUDEX) devpar.c_cflag &= ~CBAUDEX; # endif /* CBAUDEX */ devpar.c_cflag |= newbaudrate; #endif /* ACE_HAS_TERMIOS */ devpar.c_cflag &= ~CSIZE; switch(arg->databits) { case 5: devpar.c_cflag |= CS5; break; case 6: devpar.c_cflag |= CS6; break; case 7: devpar.c_cflag |= CS7; break; case 8: devpar.c_cflag |= CS8; break; default: return -1; } switch(arg->stopbits) { case 1: devpar.c_cflag &= ~CSTOPB; break; case 2: devpar.c_cflag |= CSTOPB; break; default: return -1; } if(arg->paritymode) { if(ACE_OS::strcasecmp (arg->paritymode, ACE_TTY_IO_ODD) == 0) { devpar.c_cflag |= PARENB; devpar.c_cflag |= PARODD; } else if(ACE_OS::strcasecmp (arg->paritymode, ACE_TTY_IO_EVEN) == 0) { devpar.c_cflag |= PARENB; devpar.c_cflag &= ~PARODD; } else if(ACE_OS::strcasecmp (arg->paritymode, ACE_TTY_IO_NONE) == 0) devpar.c_cflag &= ~PARENB; else return -1; } else { devpar.c_cflag &= ~PARENB; } #if defined (CNEW_RTSCTS) if((arg->ctsenb) || (arg->rtsenb)) // Enable RTS/CTS protocol devpar.c_cflag |= CNEW_RTSCTS; else devpar.c_cflag &= ~CNEW_RTSCTS; #elif defined (CRTSCTS) if((arg->ctsenb) || (arg->rtsenb)) // Enable RTS/CTS protocol devpar.c_cflag |= CRTSCTS; else devpar.c_cflag &= ~CRTSCTS; #endif /* NEW_RTSCTS || CRTSCTS */ #if defined (CREAD) // Enable/disable receiver if(arg->rcvenb) devpar.c_cflag |= CREAD; else devpar.c_cflag &= ~CREAD; #endif /* CREAD */ #if defined (HUPCL) // Cause DTR to drop after port close. devpar.c_cflag |= HUPCL; #endif /* HUPCL */ #if defined (CLOCAL) // If device is not a modem set to local device. if(arg->modem) devpar.c_cflag &= ~CLOCAL; else devpar.c_cflag |= CLOCAL; #endif /* CLOCAL */ devpar.c_iflag = IGNPAR | INPCK; if(arg->databits < 8) devpar.c_iflag |= ISTRIP; #if defined (IGNBRK) // If device is not a modem set to ignore break points if(arg->modem) devpar.c_iflag &= ~IGNBRK; else devpar.c_iflag |= IGNBRK; #endif /* IGNBRK */ #if defined (IXOFF) // Enable/disable software flow control on input if(arg->xinenb) devpar.c_iflag |= IXOFF; else devpar.c_iflag &= ~IXOFF; #endif /* IXOFF */ #if defined (IXON) // Enable/disable software flow control on output if(arg->xoutenb) devpar.c_iflag |= IXON; else devpar.c_iflag &= ~IXON; #endif /* IXON */ #if defined (ICANON) // Enable noncanonical input processing mode devpar.c_lflag &= ~ICANON; #endif /* ICANON */ #if defined (ECHO) // Disable echoing of input characters devpar.c_lflag &= ~ECHO; #endif /* ECHO */ #if defined (ECHOE) // Disable echoing erase chareacter as BS-SP-BS devpar.c_lflag &= ~ECHOE; #endif /* ECHOE */ #if defined (ISIG) // Disable SIGINTR, SIGSUSP, SIGDSUSP and SIGQUIT signals devpar.c_lflag &= ~ISIG; #endif /* ISIG */ #if defined (OPOST) // Disable post-processing of output data devpar.c_oflag &= ~OPOST; #endif /* OPOST */ if(arg->readtimeoutmsec < 0) { // Settings for infinite timeout. devpar.c_cc[VTIME] = 0; // In case of infinite timeout [VMIN] must be at least 1. if(arg->readmincharacters > UCHAR_MAX) devpar.c_cc[VMIN] = UCHAR_MAX; else if(arg->readmincharacters < 1) devpar.c_cc[VMIN] = 1; else devpar.c_cc[VMIN] = static_cast<unsigned char>(arg->readmincharacters); } else { devpar.c_cc[VTIME] = static_cast<unsigned char>(arg->readtimeoutmsec / 100); if(arg->readmincharacters > UCHAR_MAX) devpar.c_cc[VMIN] = UCHAR_MAX; else if(arg->readmincharacters < 1) devpar.c_cc[VMIN] = 0; else devpar.c_cc[VMIN] = static_cast<unsigned char>(arg->readmincharacters); } #if defined (TIOCMGET) int status; this->ACE_IO_SAP::control (TIOCMGET, &status); if(arg->dtrdisable) status &= ~TIOCM_DTR; else status |= TIOCM_DTR; this->ACE_IO_SAP::control (TIOCMSET, &status); #endif /* definded (TIOCMGET) */ #if defined (ACE_HAS_TERMIOS) return tcsetattr (get_handle (), TCSANOW, &devpar); #elif defined (TCSETS) return this->ACE_IO_SAP::control (TCSETS, static_cast<void*>(&devpar)); #elif defined (TCSETA) return this->ACE_IO_SAP::control (TCSETA, static_cast<void*>(&devpar)); #else errno = ENOSYS; return -1; #endif /* ACE_HAS_TERMIOS */ case GETPARAMS: return -1; // Not yet implemented. default: return -1; // Wrong cmd. } #elif defined (ACE_WIN32) DCB dcb; dcb.DCBlength = sizeof dcb; if(!::GetCommState (this->get_handle (), &dcb)) { ACE_OS::set_errno_to_last_error (); return -1; } COMMTIMEOUTS timeouts; if(!::GetCommTimeouts (this->get_handle(), &timeouts)) { ACE_OS::set_errno_to_last_error (); return -1; } switch(cmd) { case SETPARAMS: dcb.BaudRate = arg->baudrate; switch(arg->databits) { case 4: case 5: case 6: case 7: case 8: dcb.ByteSize = arg->databits; break; default: return -1; } switch(arg->stopbits) { case 1: dcb.StopBits = ONESTOPBIT; break; case 2: dcb.StopBits = TWOSTOPBITS; break; default: return -1; } if(arg->paritymode) { dcb.fParity = TRUE; if(ACE_OS::strcasecmp (arg->paritymode, ACE_TTY_IO_ODD) == 0) dcb.Parity = ODDPARITY; else if(ACE_OS::strcasecmp (arg->paritymode, ACE_TTY_IO_EVEN) == 0) dcb.Parity = EVENPARITY; else if(ACE_OS::strcasecmp (arg->paritymode, ACE_TTY_IO_NONE) == 0) dcb.Parity = NOPARITY; else if(ACE_OS::strcasecmp (arg->paritymode, ACE_TTY_IO_MARK) == 0) dcb.Parity = MARKPARITY; else if(ACE_OS::strcasecmp (arg->paritymode, ACE_TTY_IO_SPACE) == 0) dcb.Parity = SPACEPARITY; else return -1; } else { dcb.fParity = FALSE; dcb.Parity = NOPARITY; } // Enable/disable RTS protocol. switch(arg->rtsenb) { case 1: dcb.fRtsControl = RTS_CONTROL_ENABLE; break; case 2: dcb.fRtsControl = RTS_CONTROL_HANDSHAKE; break; case 3: dcb.fRtsControl = RTS_CONTROL_TOGGLE; break; default: dcb.fRtsControl = RTS_CONTROL_DISABLE; } // Enable/disable CTS protocol. if(arg->ctsenb) dcb.fOutxCtsFlow = TRUE; else dcb.fOutxCtsFlow = FALSE; // Enable/disable DSR protocol. if(arg->dsrenb) dcb.fOutxDsrFlow = TRUE; else dcb.fOutxDsrFlow = FALSE; // Disable/enable DTR protocol if(arg->dtrdisable) dcb.fDtrControl = DTR_CONTROL_DISABLE; else dcb.fDtrControl = DTR_CONTROL_ENABLE; // Enable/disable software flow control on input if(arg->xinenb) dcb.fInX = TRUE; else dcb.fInX = FALSE; // Enable/disable software flow control on output if(arg->xoutenb) dcb.fOutX = TRUE; else dcb.fOutX = FALSE; // Always set limits unless set to negative to use default. if(arg->xonlim >= 0) dcb.XonLim = static_cast<WORD>(arg->xonlim); if(arg->xofflim >= 0) dcb.XoffLim = static_cast<WORD>(arg->xofflim); dcb.fAbortOnError = FALSE; dcb.fErrorChar = FALSE; dcb.fNull = FALSE; dcb.fBinary = TRUE; if(!::SetCommState (this->get_handle (), &dcb)) { ACE_OS::set_errno_to_last_error (); return -1; } if(arg->readtimeoutmsec < 0) { // Settings for infinite timeout. timeouts.ReadIntervalTimeout = 0; timeouts.ReadTotalTimeoutMultiplier = 0; timeouts.ReadTotalTimeoutConstant = 0; } else if(arg->readtimeoutmsec == 0) { // Return immediately if no data in the input buffer. timeouts.ReadIntervalTimeout = MAXDWORD; timeouts.ReadTotalTimeoutMultiplier = 0; timeouts.ReadTotalTimeoutConstant = 0; } else { // Wait for specified timeout for char to arrive before returning. timeouts.ReadIntervalTimeout = MAXDWORD; timeouts.ReadTotalTimeoutMultiplier = MAXDWORD; timeouts.ReadTotalTimeoutConstant = arg->readtimeoutmsec; } if(!::SetCommTimeouts (this->get_handle (), &timeouts)) { ACE_OS::set_errno_to_last_error (); return -1; } return 0; case GETPARAMS: arg->baudrate = dcb.BaudRate; switch(dcb.ByteSize) { case 4: case 5: case 6: case 7: case 8: arg->databits = dcb.ByteSize; break; default: return -1; } switch(dcb.StopBits) { case ONESTOPBIT: arg->stopbits = 1; break; case TWOSTOPBITS: arg->stopbits = 2; break; default: return -1; } if(!dcb.fParity) { arg->paritymode = ACE_TTY_IO_NONE; } else { switch(dcb.Parity) { case ODDPARITY: arg->paritymode = ACE_TTY_IO_ODD; break; case EVENPARITY: arg->paritymode = ACE_TTY_IO_EVEN; break; case NOPARITY: arg->paritymode = ACE_TTY_IO_NONE; break; case MARKPARITY: arg->paritymode = ACE_TTY_IO_MARK; break; case SPACEPARITY: arg->paritymode = ACE_TTY_IO_SPACE; break; default: return -1; } } // Enable/disable RTS protocol. switch(dcb.fRtsControl) { case RTS_CONTROL_ENABLE: arg->rtsenb = 1; break; case RTS_CONTROL_HANDSHAKE: arg->rtsenb = 2; break; case RTS_CONTROL_TOGGLE: arg->rtsenb = 3; break; case RTS_CONTROL_DISABLE: arg->rtsenb = 0; break; default: return -1; } // Enable/disable CTS protocol. if(dcb.fOutxCtsFlow) arg->ctsenb = true; else arg->ctsenb = false; // Enable/disable DSR protocol. if(dcb.fOutxDsrFlow) arg->dsrenb = true; else arg->dsrenb = false; // Disable/enable DTR protocol // Attention: DTR_CONTROL_HANDSHAKE is not supported. switch(dcb.fDtrControl) { case DTR_CONTROL_DISABLE: arg->dtrdisable = true; break; case DTR_CONTROL_ENABLE: arg->dtrdisable = false; break; default: return -1; } // Enable/disable software flow control on input if(dcb.fInX) arg->xinenb = true; else arg->xinenb = false; // Enable/disable software flow control on output if(dcb.fOutX) arg->xoutenb = true; else arg->xoutenb = false; arg->xonlim = static_cast<int>(dcb.XonLim); arg->xofflim = static_cast<int>(dcb.XoffLim); if(timeouts.ReadIntervalTimeout == 0 && timeouts.ReadTotalTimeoutMultiplier == 0 && timeouts.ReadTotalTimeoutConstant == 0) arg->readtimeoutmsec = -1; else arg->readtimeoutmsec = timeouts.ReadTotalTimeoutConstant; return 0; default: return -1; // Wrong cmd. } // arg switch #else ACE_UNUSED_ARG (cmd); ACE_UNUSED_ARG (arg); ACE_NOTSUP_RETURN (-1); #endif /* ACE_HAS_TERMIOS || ACE_HAS_TERMIO */ }