int Peer_Handler::transmit_stdin (void) { // If return value is -1, then first_time_ must be reset to 1. int result = 0; if (this->connection_id_ != -1) { ACE_Message_Block *mb = 0; ACE_NEW_RETURN (mb, ACE_Message_Block (sizeof (Event)), -1); // Cast the message block payload into an <Event> pointer. Event *event = (Event *) mb->rd_ptr (); ssize_t n = ACE_OS::read (ACE_STDIN, event->data_, sizeof event->data_); switch (n) { case 0: ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("stdin closing down\n"))); // Take stdin out of the ACE_Reactor so we stop trying to // send events. ACE_Reactor::instance ()->remove_handler (ACE_STDIN, ACE_Event_Handler::DONT_CALL | ACE_Event_Handler::READ_MASK); mb->release (); result = 0; // break; /* NOTREACHED */ case -1: mb->release (); ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("read"))); result = 0; // break; /* NOTREACHED */ default: // Do not return directly, save the return value. result = this->transmit (mb, n, ROUTING_EVENT); break; /* NOTREACHED */ } // Do not return at here, but at exit of function. /*return 0;*/ } else { ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Must transmit over an opened channel.\n"))); result = -1; // Save return value at here, return at exit of function. } // If transmit error, the stdin-thread will be cancelled, so should // reset first_time_ to 1, which will register_stdin_handler again. if (result == -1) first_time_ = 1; return result; }
template <class HANDLER> void ACE_Asynch_Connector<HANDLER>::parse_address (const ACE_Asynch_Connect::Result &result, ACE_INET_Addr &remote_address, ACE_INET_Addr &local_address) { #if defined (ACE_HAS_IPV6) // Getting the addresses. sockaddr_in6 local_addr; sockaddr_in6 remote_addr; #else // Getting the addresses. sockaddr_in local_addr; sockaddr_in remote_addr; #endif /* ACE_HAS_IPV6 */ // Get the length. int local_size = sizeof (local_addr); int remote_size = sizeof (remote_addr); // Get the local address. if (ACE_OS::getsockname (result.connect_handle (), reinterpret_cast<sockaddr *> (&local_addr), &local_size) < 0) ACE_ERROR ((LM_ERROR, ACE_TEXT("%p\n"), ACE_TEXT("ACE_Asynch_Connector::<getsockname> failed"))); // Get the remote address. if (ACE_OS::getpeername (result.connect_handle (), reinterpret_cast<sockaddr *> (&remote_addr), &remote_size) < 0) ACE_ERROR ((LM_ERROR, ACE_TEXT("%p\n"), ACE_TEXT("ACE_Asynch_Connector::<getpeername> failed"))); // Set the addresses. local_address.set (reinterpret_cast<sockaddr_in *> (&local_addr), local_size); remote_address.set (reinterpret_cast<sockaddr_in *> (&remote_addr), remote_size); #if 0 // @@ Just debugging. char local_address_buf [BUFSIZ]; char remote_address_buf [BUFSIZ]; if (local_address.addr_to_string (local_address_buf, sizeof local_address_buf) == -1) ACE_ERROR ((LM_ERROR, "Error:%m:can't obtain local_address's address string")); ACE_DEBUG ((LM_DEBUG, "ACE_Asynch_Connector<HANDLER>::parse_address : " "Local address %s\n", local_address_buf)); if (remote_address.addr_to_string (remote_address_buf, sizeof remote_address_buf) == -1) ACE_ERROR ((LM_ERROR, "Error:%m:can't obtain remote_address's address string")); ACE_DEBUG ((LM_DEBUG, "ACE_Asynch_Connector<HANDLER>::parse_address : " "Remote address %s\n", remote_address_buf)); #endif /* 0 */ return; }
static bool timeout_test (void) { bool status = true; SYNCH_QUEUE mq; MyTask task1; task1.create_reactor (); task1.start (1); TestHandler test_handler (task1.get_reactor (), mq); // The reactor of taks1 that uses a hrtimer will trigger a timeout in // 5 seconds which will enqueue a message block in the queue. At the // same moment we calculate a timeout for the dequeue operation for // 3 seconds in the future. Than we set the system time 4 seconds back. // The condition should timeout because the queue is empty and the trigger // only fires after the condition has timed out. // Next we start another dequeue for 3 seconds in the future which should // return before timing out because by then the trigger should have fired. // In case of using regular system time policy for message queue and // dequeue timeouts the first dequeue would not have timed out because // between calculating the timeout and starting the dequeue the system time // shifted back 4 sec causing the trigger to fire before the timeout elapsed. // In case timeshifting does not work because of priority problems or such // the test should succeed. if (!test_handler.trigger_in (ACE_Time_Value (5, 0))) ACE_ERROR_RETURN ((LM_ERROR, "(%P|%t) Unable to schedule trigger.\n"), false); if (!mq.is_empty ()) { ACE_ERROR ((LM_ERROR, ACE_TEXT ("New queue is not empty!\n"))); status = false; } else { ACE_Message_Block *b; ACE_Time_Value_T<ACE_Monotonic_Time_Policy> tv; tv = (tv.now () + ACE_Time_Value (3,0)); // Now (monotonic time) + 3 sec // shift back in time 4 sec set_system_time (ACE_OS::gettimeofday () - ACE_Time_Value (4, 0)); if (mq.dequeue_head (b, &tv) != -1) { ACE_ERROR ((LM_ERROR, ACE_TEXT ("Dequeued before timeout elapsed!\n"))); status = false; } else if (errno != EWOULDBLOCK) { ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("Dequeue timeout should be EWOULDBLOCK, got"))); status = false; } else { ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("First dequeue timed out: OK\n"))); tv = (tv.now () + ACE_Time_Value (3,0)); // Now (monotonic time) + 3 sec if (mq.dequeue_head (b, &tv) != -1) { ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Second dequeue succeeded: OK\n"))); delete b; } else { ACE_ERROR ((LM_ERROR, ACE_TEXT ("Second dequeue timed out!\n"))); status = false; } } // restore time set_system_time (ACE_OS::gettimeofday () + ACE_Time_Value (4, 0)); } ACE_DEBUG((LM_INFO, "(%P|%t) Asking worker thread to finish.\n")); task1.stop (); ACE_Thread_Manager::instance ()->wait (); return status; }
void Worker::setup (void) { // Make sure we have a connection to the server using the test // protocol. this->policy_manager_->set_policy_overrides (this->test_protocol_policy_, CORBA::SET_OVERRIDE); // Since the network maybe unavailable temporarily, make sure to try // for a few times before giving up. for (CORBA::ULong j = 0;;) { try { // Send a message to ensure that the connection is setup. this->test_->oneway_sync (); break; } catch (const CORBA::TRANSIENT &) { ++j; if (j < this->number_of_connection_attempts_) { ACE_OS::sleep (1); continue; } } ACE_ERROR ((LM_ERROR, "Cannot setup test protocol\n")); ACE_OS::exit (-1); } const char *test_protocol = 0; if (this->test_protocol_tag_ == IOP::TAG_INTERNET_IOP) test_protocol = "IIOP"; else if (this->test_protocol_tag_ == TAO_TAG_DIOP_PROFILE) test_protocol = "DIOP"; else if (this->test_protocol_tag_ == TAO_TAG_SCIOP_PROFILE) test_protocol = "SCIOP"; // Use IIOP for setting up the test since the test protocol maybe // unreliable. this->policy_manager_->set_policy_overrides (this->base_protocol_policy_, CORBA::SET_OVERRIDE); // Since the network maybe unavailable temporarily, make sure to try // for a few times before giving up. for (CORBA::ULong k = 0;;) { try { // Let the server know what to expect.. this->test_->start_test (this->session_id_, test_protocol, this->invocation_rate_, this->message_size_, this->iterations_); break; } catch (const CORBA::TRANSIENT &) { ACE_OS::sleep (1); if (k < this->number_of_connection_attempts_) { ACE_OS::sleep (1); continue; } } ACE_ERROR ((LM_ERROR, "Cannot setup base protocol\n")); ACE_OS::exit (-1); } return; }
int ClientApp::run (int argc, ACE_TCHAR* argv[]) { CORBA::ORB_var orb = CORBA::ORB_init (argc, argv); // Parse the command-line args for this application. // * Raises -1 if problems are encountered. // * Returns 1 if the usage statement was explicitly requested. // * Returns 0 otherwise. int result = this->parse_args (argc, argv); if (result != 0) { return result; } CORBA::Object_var obj = orb->string_to_object(this->ior_.c_str()); if (CORBA::is_nil(obj.in())) { ACE_ERROR((LM_ERROR, "(%P|%t) Failed to convert IOR string to obj ref.\n")); throw TestException(); } Foo_var foo = Foo::_narrow(obj.in()); if (CORBA::is_nil(foo.in())) { ACE_ERROR((LM_ERROR, "(%P|%t) Failed to narrow obj ref to Foo interface.\n")); throw TestException(); } // Create the callback object using the child poa with the custom // strategy. obj = orb->resolve_initial_references("RootPOA"); if (CORBA::is_nil(obj.in())) { ACE_ERROR((LM_ERROR, "(%P|%t) Failed to resolve initial ref for 'RootPOA'.\n")); throw TestException(); } PortableServer::POA_var root_poa = PortableServer::POA::_narrow(obj.in()); if (CORBA::is_nil(root_poa.in())) { ACE_ERROR((LM_ERROR, "(%P|%t) Failed to narrow obj ref to POA interface.\n")); throw TestException(); } PortableServer::POAManager_var poa_manager = root_poa->the_POAManager(); // Create the child POA. CORBA::PolicyList policies(0); policies.length(0); PortableServer::POA_var child_poa = root_poa->create_POA("ChildPoa", poa_manager.in(), policies); if (CORBA::is_nil(child_poa.in())) { ACE_ERROR((LM_ERROR, "(%P|%t) ERROR [ServerApp::run()]: " "Failed to create the child POA.\n")); throw TestException(); } // Create the thread pool servant dispatching strategy object, and // hold it in a (local) smart pointer variable. TAO_Intrusive_Ref_Count_Handle<TAO::CSD::TP_Strategy> csd_tp_strategy = new TAO::CSD::TP_Strategy(); csd_tp_strategy->set_num_threads(1); // Tell the strategy to apply itself to the child poa. if (csd_tp_strategy->apply_to(child_poa.in()) == false) { ACE_ERROR((LM_ERROR, "(%P|%t) ERROR [ServerApp::run()]: " "Failed to apply custom dispatching strategy to child poa.\n")); throw TestException(); } // Create the servant object. Callback_i* servant = new Callback_i (); // local smart pointer variable to deal with releasing the reference // to the servant object when the smart pointer object falls out of scope. PortableServer::ServantBase_var owner_transfer(servant); // Activate the servant using the Child POA. PortableServer::ObjectId_var oid = child_poa->activate_object(servant); // Obtain the object reference. obj = child_poa->servant_to_reference(servant); if (CORBA::is_nil(obj.in())) { ACE_ERROR((LM_ERROR, "(%P|%t) Failed to activate servant (Callback_i).\n")); throw TestException(); } Callback_var callback = Callback::_narrow (obj.in ()); ClientTask client_task(orb.in (), foo.in (), callback.in ()); if (client_task.open () != 0) { throw TestException(); } // Activate the POA Manager poa_manager->activate(); ACE_DEBUG((LM_DEBUG, "(%P|%t) ClientApp is ready.\n")); orb->run(); client_task.wait (); ACE_DEBUG((LM_DEBUG, "(%P|%t) ClientApp is destroying the Root POA.\n")); // Tear-down the root poa and orb. root_poa->destroy(1, 1); ACE_DEBUG((LM_DEBUG, "(%P|%t) ClientApp is destroying the ORB.\n")); orb->destroy(); ACE_DEBUG((LM_DEBUG, "(%P|%t) ClientApp has completed running successfully.\n")); return 0; }
void Receiver::open (ACE_HANDLE handle, ACE_Message_Block &message_block) { ACE_DEBUG ((LM_DEBUG, "%N:%l:Receiver::open called\n")); // New connection, so initiate stuff. // Cache the new connection this->handle_ = handle; // File offset starts at zero this->file_offset_ = 0; // Open dump file (in OVERLAPPED mode) this->dump_file_ = ACE_OS::open (dump_file, O_CREAT | O_RDWR | O_TRUNC | \ FILE_FLAG_OVERLAPPED); if (this->dump_file_ == ACE_INVALID_HANDLE) { ACE_ERROR ((LM_ERROR, "%p\n", "ACE_OS::open")); return; } // Initiate <ACE_Asynch_Write_File>. if (this->wf_.open (*this, this->dump_file_) == -1) { ACE_ERROR ((LM_ERROR, "%p\n", "ACE_Asynch_Write_File::open")); return; } // Initiate <ACE_Asynch_Read_Stream>. if (this->rs_.open (*this, this->handle_) == -1) { ACE_ERROR ((LM_ERROR, "%p\n", "ACE_Asynch_Read_Stream::open")); return; } // Fake the result and make the <handle_read_stream> get // called. But, not, if there is '0' is transferred. if (message_block.length () != 0) { // Duplicate the message block so that we can keep it around. ACE_Message_Block &duplicate = *message_block.duplicate (); // Fake the result so that we will get called back. ACE_Asynch_Read_Stream_Result_Impl *fake_result = ACE_Proactor::instance ()->create_asynch_read_stream_result (this->proxy (), this->handle_, duplicate, initial_read_size, 0, ACE_INVALID_HANDLE, 0, 0); size_t bytes_transferred = message_block.length (); // <complete> for Accept would have already moved the <wr_ptr> // forward. Update it to the beginning position. duplicate.wr_ptr (duplicate.wr_ptr () - bytes_transferred); // This will call the callback. fake_result->complete (message_block.length (), 1, 0); // Zap the fake result. delete fake_result; } else // Otherwise, make sure we proceed. Initiate reading the socket // stream. if (this->initiate_read_stream () == -1) return; }
int ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { try { const char *location1 = "MyLocation 1"; const char *location2 = "MyLocation 2"; const char *location3 = "MyLocation 3"; const char *location4 = "MyLocation 4"; const char *location5 = "MyLocation 5"; const char *location6 = "MyLocation 6"; LB_server lb_server (argc, argv); if (lb_server.start_orb_and_poa () == -1) return 1; if (parse_args (argc, argv) == -1) return 1; if (server_id == 1 && lb_server.create_object_group () == -1) return 1; else if (lb_server.get_object_group () == -1) return 1; const char ** location = 0; switch (server_id) { case 1: location = &location1; break; case 2: location = &location2; break; case 3: location = &location3; break; case 4: location = &location4; break; case 5: location = &location5; break; case 6: location = &location6; break; } Basic *basic_servant; ACE_NEW_RETURN (basic_servant, Basic (lb_server.object_group (), lb_server.load_manager (), lb_server.orb (), *location, server_id), 1); PortableServer::ServantBase_var owner_transfer(basic_servant); if (lb_server.register_servant (basic_servant, *location) == -1) { (void) lb_server.destroy (); return 1; } if (server_id == 2) { Basic *direct_basic_servant = 0; ACE_NEW_RETURN (direct_basic_servant, Basic (server_id), 1); PortableServer::ServantBase_var owner_transfer(direct_basic_servant); Test::Basic_var direct_basic = direct_basic_servant->_this (); CORBA::String_var ior = lb_server.orb ()->object_to_string (direct_basic.in ()); FILE *output_file = ACE_OS::fopen (direct_obj_file, "w"); if (output_file == 0) { ACE_ERROR ((LM_ERROR, "Cannot open output file(%s) for writing IOR:", direct_obj_file)); if (lb_server.destroy () == -1) return 1; } ACE_OS::fprintf (output_file, "%s", ior.in()); ACE_OS::fclose (output_file); } // ACE_OS::sleep (1000); lb_server.orb ()->run (); ACE_DEBUG ((LM_DEBUG, "(%P|%t)%T server - event loop finished\n")); if (lb_server.destroy () == -1) return 1; } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("lb_server exception"); return 1; } return 0; }
int run_main (int, ACE_TCHAR *[]) { ACE_START_TEST (ACE_TEXT("Compiler_Features_33_Test")); int retval = 1; char _tao_discriminant = '\x0'; switch (_tao_discriminant) { case '\x0': case '\x1': case '\x2': case '\x3': case '\x4': case '\x5': case '\x6': case '\a': case '\b': case '\t': case '\n': case '\v': case '\f': case '\r': case '\xe': case '\xf': case '\x10': case '\x11': case '\x12': case '\x13': case '\x14': case '\x15': case '\x16': case '\x17': case '\x18': case '\x19': case '\x1a': case '\x1b': case '\x1c': case '\x1d': case '\x1e': case '\x1f': case ' ': case '!': case '"': case '#': case '$': case '%': case '&': case '\'': case '(': case ')': case '*': case '+': case ',': case '-': case '.': case '/': case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case ':': case ';': case '<': case '=': case '>': case '?': case '@': case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': case 'Y': case 'Z': case '[': case '\\': case ']': case '^': case '_': case '`': case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u': case 'v': case 'w': case 'x': case 'y': case 'z': case '{': case '|': case '}': case '~': case '\x7f': case '\x80': case '\x81': case '\x82': case '\x83': case '\x84': case '\x85': case '\x86': case '\x87': case '\x88': case '\x89': case '\x8a': case '\x8b': case '\x8c': case '\x8d': case '\x8e': case '\x8f': case '\x90': case '\x91': case '\x92': case '\x93': case '\x94': case '\x95': case '\x96': case '\x97': case '\x98': case '\x99': case '\x9a': case '\x9b': case '\x9c': case '\x9d': case '\x9e': case '\x9f': case '\xa0': case '\xa1': case '\xa2': case '\xa3': case '\xa4': case '\xa5': case '\xa6': case '\xa7': case '\xa8': case '\xa9': case '\xaa': case '\xab': case '\xac': case '\xad': case '\xae': case '\xaf': case '\xb0': case '\xb1': case '\xb2': case '\xb3': case '\xb4': case '\xb5': case '\xb6': case '\xb7': case '\xb8': case '\xb9': case '\xba': case '\xbb': case '\xbc': case '\xbd': case '\xbe': case '\xbf': case '\xc0': case '\xc1': case '\xc2': case '\xc3': case '\xc4': case '\xc5': case '\xc6': case '\xc7': case '\xc8': case '\xc9': case '\xca': case '\xcb': case '\xcc': case '\xcd': case '\xce': case '\xcf': case '\xd0': case '\xd1': case '\xd2': case '\xd3': case '\xd4': case '\xd5': case '\xd6': case '\xd7': case '\xd8': case '\xd9': case '\xda': case '\xdb': case '\xdc': case '\xdd': case '\xde': case '\xdf': case '\xe0': case '\xe1': case '\xe2': case '\xe3': case '\xe4': case '\xe5': case '\xe6': case '\xe7': case '\xe8': case '\xe9': case '\xea': case '\xeb': case '\xec': case '\xed': case '\xee': case '\xef': case '\xf0': case '\xf1': case '\xf2': case '\xf3': case '\xf4': case '\xf5': case '\xf6': case '\xf7': case '\xf8': case '\xf9': case '\xfa': case '\xfb': case '\xfc': case '\xfd': case '\xfe': case '\xff': { // Test works retval = 0; } break; } if (retval != 0) { ACE_ERROR ((LM_ERROR, ACE_TEXT ("ERROR: Switch doesn't worked as expected\n"))); } else { ACE_DEBUG ((LM_INFO, ACE_TEXT ("Switch worked as expected\n"))); } ACE_END_TEST; return retval; }
int run_main (int, ACE_TCHAR *[]) { ACE_START_TEST (ACE_TEXT ("Future_Set_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); ACE_Future<u_long> fresulta; ACE_Future<u_long> fresultb; ACE_Future<u_long> fresultc; ACE_Future<u_long> fresultd; ACE_Future<const ACE_TCHAR *> fname; ACE_Future_Set<u_long> fseta; ACE_Future_Set<u_long> fsetb; ACE_Future_Set<u_long> fsetc; ACE_Future_Set<u_long> fsetd; ACE_Future_Set<const ACE_TCHAR *> fsetname; ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%t) initializing future sets with non-blocking call\n"))); for (int i = 0; i < n_loops; i++) { // 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 (); fsetname.insert (fname); fname = peter->name (); fsetname.insert (fname); fname = helmut->name (); fseta.insert (fresulta); fsetb.insert (fresultb); fsetc.insert (fresultc); fsetd.insert (fresultd); fsetname.insert (fname); } // See if the result is available... if (!fseta.is_empty ()) ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%t) wow.. set a is not empty.....\n"))); if (!fsetb.is_empty ()) ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%t) wow.. set b is not empty.....\n"))); if (!fsetc.is_empty ()) ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%t) wow.. set c is not empty.....\n"))); if (!fsetd.is_empty ()) ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%t) wow.. set d is not empty.....\n"))); if (!fsetname.is_empty ()) ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%t) wow.. set name is not empty.....\n"))); ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%t) non-blocking calls done... now blocking...\n"))); // Save the result of fresulta. u_long resulta = 0; u_long resultb = 0; u_long resultc = 0; u_long resultd = 0; u_int count = 0; while (fseta.next_readable (fresulta)) { fresulta.get (resulta); ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%t) result(%u) a %u\n"), count, (u_int) resulta)); } count = 0; while (fsetb.next_readable (fresultb)) { fresultb.get (resultb); ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%t) result(%u) b %u\n"), count, (u_int) resultb)); } count = 0; while (fsetc.next_readable (fresultc)) { fresultc.get (resultc); ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%t) result(%u) c %u\n"), count, (u_int) resultc)); } count = 0; while (fsetd.next_readable (fresultd)) { fresultd.get (resultd); ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%t) result(%u) d %u\n"), count, (u_int) resultd)); } const ACE_TCHAR *name = 0; count = 0; while (fsetname.next_readable (fname)) { fname.get (name); ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%t) result(%u) name %s\n"), count, name)); } if (fseta.is_empty ()) ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%t) wow.. set a is empty.....\n"))); if (fsetb.is_empty ()) ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%t) wow.. set b is empty.....\n"))); if (fsetc.is_empty ()) ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%t) wow.. set c is empty.....\n"))); if (fsetd.is_empty ()) ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%t) wow.. set d is empty.....\n"))); if (fsetname.is_empty ()) ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%t) wow.. set name is empty.....\n"))); ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%t) task_count %d\n"), task_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\n"), task_count.value () )); 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; }
int Logging_Handler::handle_input (ACE_HANDLE) { ACE_Log_Record log_record; // We need to use the old two-read trick here since TCP sockets // don't support framing natively. Allocate a message block for the // payload; initially at least large enough to hold the header, but // needs some room for alignment. ACE_Message_Block *payload_p = 0; ACE_Message_Block *header_p = 0; ACE_NEW_RETURN (header_p, ACE_Message_Block (ACE_DEFAULT_CDR_BUFSIZE), -1); auto_ptr <ACE_Message_Block> header (header_p); // Align the Message Block for a CDR stream ACE_CDR::mb_align (header.get ()); ACE_CDR::Boolean byte_order; ACE_CDR::ULong length; ssize_t count = ACE::recv_n (this->peer ().get_handle (), header->wr_ptr (), 8); switch (count) { // Handle shutdown and error cases. default: case -1: case 0: ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("server logging daemon closing down\n"))); return -1; /* NOTREACHED */ case 8: // Just fall through in this case.. break; } header->wr_ptr (8); // Reflect addition of 8 bytes. // Create a CDR stream to parse the 8-byte header. ACE_InputCDR header_cdr (header.get ()); // Extract the byte-order and use helper methods to disambiguate // octet, booleans, and chars. header_cdr >> ACE_InputCDR::to_boolean (byte_order); // Set the byte-order on the stream... header_cdr.reset_byte_order (byte_order); // Extract the length header_cdr >> length; ACE_NEW_RETURN (payload_p, ACE_Message_Block (length), -1); auto_ptr <ACE_Message_Block> payload (payload_p); // Ensure there's sufficient room for log record payload. ACE_CDR::grow (payload.get (), 8 + ACE_CDR::MAX_ALIGNMENT + length); // Use <recv_n> to obtain the contents. if (ACE::recv_n (this->peer ().get_handle (), payload->wr_ptr (), length) <= 0) { ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("recv_n()"))); return -1; } payload->wr_ptr (length); // Reflect additional bytes ACE_InputCDR payload_cdr (payload.get ()); payload_cdr.reset_byte_order (byte_order); payload_cdr >> log_record; // Finally extract the <ACE_log_record>. log_record.length (length); log_record.print (ACE_TEXT_CHAR_TO_TCHAR (this->peer_name_), 1, stderr); return 0; }
int Twoway_Handler::run (void) { // Read data from client (terminate on error). char *request = 0; for (;;) { ACE_INT32 len = 0; if (parse_header_and_allocate_buffer (request, &len) == -1) return -1; // Subtract off the sizeof the length prefix. ssize_t r_bytes = this->ssl_stream_ -> recv_n (request, len - sizeof (ACE_UINT32)); if (r_bytes == -1) { ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("recv"))); break; } else if (r_bytes == 0) { ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) reached end of input, connection ") ACE_TEXT ("closed by client\n"))); break; } else if (OPTIONS::instance ()->verbose () && ACE::write_n (ACE_STDOUT, request, r_bytes) != r_bytes) ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("ACE::write_n"))); else { ssize_t s_bytes = (ssize_t) OPTIONS::instance ()->reply_message_len (); // Don't try to send more than is in the request buffer! if (s_bytes > r_bytes) s_bytes = r_bytes; if (this->ssl_stream_ -> send_n (request, s_bytes) != s_bytes) ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("send_n"))); } this->total_bytes_ += size_t (r_bytes); this->message_count_++; delete [] request; request = 0; } delete [] request; return 0; }
int run_main (int , ACE_TCHAR *[]) { ACE_START_TEST (ACE_TEXT ("Monotonic_Task_Test")); int status = 0; # if defined (ACE_HAS_THREADS) MyTask my_task; if (my_task.start () == 0) { // shift back in time 4 sec; this would mess up timeouts if // monotonic timer was not used ACE_Time_Value tv_shift (4, 0); set_system_time (ACE_OS::gettimeofday () - tv_shift); if (my_task.put_message () == 0) { // task should now have finished dequeueing and started waiting for stop signal // wait (2sec) on thread manager should timeout // use the time policy aware gettimeofday() // method of the task to get current time ACE_Time_Value_T<ACE_Monotonic_Time_Policy> tv (my_task.gettimeofday ()); tv += ACE_Time_Value (2, 0); // shift another 3 sec back in time; without monotonic timer support in // thread manager this would mess up the timed wait tv_shift += ACE_Time_Value (3, 0); set_system_time (ACE_OS::gettimeofday () - ACE_Time_Value (3,0)); if (my_task.thr_mgr ()->wait (&tv) == 0) { ACE_ERROR ((LM_ERROR, ACE_TEXT ("Thread manager did not time out\n"))); status = 1; } else { ACE_Time_Value_T<ACE_Monotonic_Time_Policy> tv_now (my_task.gettimeofday ()); ACE_DEBUG ((LM_INFO, ACE_TEXT ("Thread manager timed out at %#T\n"), &tv_now)); } } else status = 1; // ok, now stop task if (my_task.stop () != 0) { ACE_ERROR ((LM_ERROR, ACE_TEXT ("Failed to stop task\n"))); status = 1; } // restore time set_system_time (ACE_OS::gettimeofday () + tv_shift); } else status = 1; # endif /* ACE_HAS_THREADS */ ACE_END_TEST; return status; }
int MyTask::svc (void) { ACE_DEBUG ((LM_DEBUG, ACE_TEXT (" (%P|%t) MyTask::svc started\n"))); // Now (according to task time policy = monotonic time) ACE_Time_Value_T<ACE_Monotonic_Time_Policy> tv (this->gettimeofday ()); { ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1); ACE_DEBUG ((LM_DEBUG, ACE_TEXT (" (%P|%t) MyTask::svc - signalling waiter\n"))); this->cond_.signal (); // signal waiter we have started // waiter will shift system time back 4 sec after this which would mess // up the first wait for a message if we were not using monotonic time } if (!this->msg_queue ()->is_empty ()) { ACE_ERROR ((LM_ERROR, ACE_TEXT ("New task queue is not empty!\n"))); this->status_ = -1; } else { ACE_Message_Block *b; tv += ACE_Time_Value (3,0); // Now + 3 sec if (this->getq (b, &tv) != -1) { ACE_ERROR ((LM_ERROR, ACE_TEXT ("Dequeued before timeout elapsed!\n"))); this->status_ = -1; } else if (errno != EWOULDBLOCK) { ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("Dequeue timeout should be EWOULDBLOCK, got"))); this->status_ = -1; } else { ACE_Time_Value_T<ACE_Monotonic_Time_Policy> tv_now (this->gettimeofday ()); ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("First getq timed out at %#T (timeout was %#T)\n"), &tv_now, &tv)); tv = this->gettimeofday () + ACE_Time_Value (4,0); // Now (monotonic time) + 3 sec if (this->getq (b, &tv) != -1) { tv_now = tv.now (); ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Second getq succeeded at %#T\n"), &tv_now)); delete b; } else { ACE_ERROR ((LM_ERROR, ACE_TEXT ("Second getq timed out!\n"))); this->status_ = -1; } } } { ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1); ACE_DEBUG ((LM_DEBUG, ACE_TEXT (" (%P|%t) MyTask::svc - waiting for stop\n"))); if (!this->stop_) this->cond_.wait (); } ACE_DEBUG ((LM_DEBUG, ACE_TEXT (" (%t) MyTask finished\n"))); return 0; }
int Peer_Handler::recv (ACE_Message_Block *&mb) { if (this->msg_frag_ == 0) // No existing fragment... ACE_NEW_RETURN (this->msg_frag_, ACE_Message_Block (sizeof (Event)), -1); Event *event = (Event *) this->msg_frag_->rd_ptr (); ssize_t header_received = 0; const size_t HEADER_SIZE = sizeof (Event_Header); ssize_t header_bytes_left_to_read = HEADER_SIZE - this->msg_frag_->length (); if (header_bytes_left_to_read > 0) { header_received = this->peer ().recv (this->msg_frag_->wr_ptr (), header_bytes_left_to_read); if (header_received == -1 /* error */ || header_received == 0 /* EOF */) { ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("Recv error during header read"))); ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("attempted to read %d bytes\n"), header_bytes_left_to_read)); this->msg_frag_ = this->msg_frag_->release (); return header_received; } // Bump the write pointer by the amount read. this->msg_frag_->wr_ptr (header_received); // At this point we may or may not have the ENTIRE header. if (this->msg_frag_->length () < HEADER_SIZE) { ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Partial header received: only %d bytes\n"), this->msg_frag_->length ())); // Notify the caller that we didn't get an entire event. errno = EWOULDBLOCK; return -1; } // Convert the header into host byte order so that we can access // it directly without having to repeatedly muck with it... event->header_.decode (); if (event->header_.len_ > ACE_INT32 (sizeof event->data_)) { // This data_ payload is too big! errno = EINVAL; ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Data payload is too big (%d bytes)\n"), event->header_.len_)); return -1; } } // At this point there is a complete, valid header in Event. Now we // need to get the event payload. Due to incomplete reads this may // not be the first time we've read in a fragment for this message. // We account for this here. Note that the first time in here // <msg_frag_->wr_ptr> will point to <event->data_>. Every time we // do a successful fragment read, we advance <wr_ptr>. Therefore, // by subtracting how much we've already read from the // <event->header_.len_> we complete the // <data_bytes_left_to_read>... ssize_t data_bytes_left_to_read = ssize_t (event->header_.len_ - (msg_frag_->wr_ptr () - event->data_)); // peer().recv() should not be called when data_bytes_left_to_read is 0. ssize_t data_received = !data_bytes_left_to_read ? 0 : this->peer ().recv (this->msg_frag_->wr_ptr (), data_bytes_left_to_read); // Try to receive the remainder of the event. switch (data_received) { case -1: if (errno == EWOULDBLOCK) // This might happen if only the header came through. return -1; /* FALLTHROUGH */; case 0: // Premature EOF. if (data_bytes_left_to_read) { this->msg_frag_ = this->msg_frag_->release (); return 0; } /* FALLTHROUGH */; default: // Set the write pointer at 1 past the end of the event. this->msg_frag_->wr_ptr (data_received); if (data_received != data_bytes_left_to_read) { errno = EWOULDBLOCK; // Inform caller that we didn't get the whole event. return -1; } else { // Set the read pointer to the beginning of the event. this->msg_frag_->rd_ptr (this->msg_frag_->base ()); mb = this->msg_frag_; // Reset the pointer to indicate we've got an entire event. this->msg_frag_ = 0; } ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%t) connection id = %d, cur len = %d, total bytes read = %d\n"), event->header_.connection_id_, event->header_.len_, data_received + header_received)); if (Options::instance ()->enabled (Options::VERBOSE)) ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("data_ = %*s\n"), event->header_.len_ - 2, event->data_)); return data_received + header_received; } }
int run_main (int, ACE_TCHAR *[]) { ACE_START_TEST (ACE_TEXT("Compiler_Features_13_Test")); // As usual, the exit status from the test is 0 on success, 1 on // failure int status = 0; { // Make sure const cast works. Compilation is interesting, the // functionality test here is just to make sure the compiler does // not optimize things away ... int x = 5; int const & y = x; const_cast<int&>(y) = 3; if (x != 3) { status = 1; ACE_ERROR((LM_ERROR, ACE_TEXT("Wrong value after const_cast,") ACE_TEXT(" expected %d, got %d\n"), 3, x)); } } // Make sure dynamic cast through pointers work ... Derived d; d.value = 24; Base * b1 = &d; Derived * d1 = dynamic_cast<Derived*>(b1); if (d1 == 0) { status = 1; ACE_ERROR((LM_ERROR, ACE_TEXT("dynamic_cast returns null, expected value\n"))); } d1->value = 42; if (d.value != 42) { ACE_ERROR((LM_ERROR, ACE_TEXT("Wrong value after dynamic_cast, expected %d, got %d\n"), 42, d.value)); } // Make sure dynamic cast detects invalid casts Another a; Base * b2 = &a; Derived * d2 = dynamic_cast<Derived*>(b2); if (d2 != 0) { status = 1; ACE_ERROR((LM_ERROR, ACE_TEXT("dynamic_cast should return null\n"))); } // Make sure dynamic cast raises an exception Base & b3 = a; try { (void) dynamic_cast<Derived&>(b3); status = 1; ACE_ERROR((LM_ERROR, ACE_TEXT("dynamic_cast should have raised exception\n"))); } catch(std::exception const &) { } catch(...) { status = 1; ACE_ERROR((LM_ERROR, ACE_TEXT("dynamic_cast should have raised std::exception\n"))); } { // Just test these compile ... double x = 42.0; int y = static_cast<int>(x); void * z = reinterpret_cast<void*>(y); if (z == 0) { ACE_ERROR((LM_ERROR, ACE_TEXT("My hack to make sure the code is not ") ACE_TEXT("optimized away backfired!\n"))); } } ACE_END_TEST; return status; }
int TestTask::svc() { try { // Get reference to Root POA CORBA::Object_var obj = orb_->resolve_initial_references("RootPOA"); PortableServer::POA_var poa = PortableServer::POA::_narrow(obj.in()); // Activate POA Manager PortableServer::POAManager_var mgr = poa->the_POAManager(); mgr->activate(); // Find the Naming Service obj = orb_->string_to_object ("corbaloc:iiop:1.2@localhost:9932/NameService"); CosNaming::NamingContext_var root = CosNaming::NamingContext::_narrow(obj.in()); if (CORBA::is_nil(root.in())) { ACE_ERROR ((LM_ERROR, "Error, Nil Naming Context reference\n")); return 1; } // Bind the example Naming Context, if necessary CosNaming::NamingContext_var example_nc; CosNaming::Name name; name.length(1); name[0].id = CORBA::string_dup("example"); try { obj = root->resolve(name); example_nc = CosNaming::NamingContext::_narrow(obj.in()); } catch (const CosNaming::NamingContext::NotFound&) { example_nc = root->bind_new_context(name); } // Bind the Test object name.length(2); name[1].id = CORBA::string_dup("Hello"); // Create an object Hello servant(orb_.in ()); PortableServer::ObjectId_var oid = poa->activate_object(&servant); obj = poa->id_to_reference(oid.in()); root->rebind(name, obj.in()); ACE_DEBUG ((LM_INFO, "Hello object bound in Naming Service B\n")); name.length(1); obj = orb_->string_to_object ("corbaloc:iiop:1.2@localhost:9931/NameService"); root = CosNaming::NamingContext::_narrow(obj.in()); root->bind_context (name, example_nc.in ()); ACE_DEBUG ((LM_INFO, "'example' context of NS B bound in Naming Service A\n")); CORBA::String_var ior = orb_->object_to_string (obj.in ()); // Output the IOR to the <ior_output_file> FILE *output_file= ACE_OS::fopen (ior_output_file, "w"); if (output_file == 0) ACE_ERROR_RETURN ((LM_ERROR, "Cannot open output file %s for writing IOR: %C\n", ior_output_file, ior.in ()), 1); ACE_OS::fprintf (output_file, "%s", ior.in ()); ACE_OS::fclose (output_file); ACE_DEBUG ((LM_INFO, "Wrote IOR file\n")); // Normally we run the orb and the orb is shutdown by // calling TestTask::end(). // Accept requests orb_->run(); orb_->destroy(); return 0; } catch (CORBA::Exception& ex) { ex._tao_print_exception ("CORBA exception: "); } return -1; }
int main (int argc, char * argv[]) { ACE_DEBUG ((LM_DEBUG, "Sender\n")); QoS_Util qos_util(argc, argv); if (qos_util.parse_args () == -1) ACE_ERROR_RETURN ((LM_ERROR, "Error in parsing args\n"), -1); // This is a multicast application. if (qos_util.multicast_flag ()) { Fill_ACE_QoS fill_ace_qos; // The application adds the flow specs that it wants into the // Fill_ACE_QoS. The Fill_ACE_QoS indexes the flow specs by the flow // spec names. Here the new flowspec being added is g_711. ACE_CString g_711 ("g_711"); switch (fill_ace_qos.map ().bind (g_711, new ACE_Flow_Spec (9200, 708, 18400, 0, 0, ACE_SERVICETYPE_CONTROLLEDLOAD, 368, 368, 25, 1))) { case 1 : ACE_ERROR_RETURN ((LM_ERROR, "Unable to bind the new flow spec\n" "The Flow Spec name already exists\n"), -1); break; case -1 : ACE_ERROR_RETURN ((LM_ERROR, "Unable to bind the new flow spec\n"), -1); break; } ACE_DEBUG ((LM_DEBUG, "g_711 Flow Spec bound successfully\n")); // This is a sender. So we fill in the sending QoS parameters. ACE_QoS ace_qos_sender; if (fill_ace_qos.fill_simplex_sender_qos (ace_qos_sender, g_711) !=0) ACE_ERROR_RETURN ((LM_ERROR, "Unable to fill simplex sender qos\n"), -1); else ACE_DEBUG ((LM_DEBUG, "Filled up the Sender QoS parameters\n")); // Opening a new Multicast Datagram. It is absolutely necessary that // the sender and the receiver subscribe to the same multicast // addresses to make sure the "multicast sessions" for the two are // the same. This is used to match the RESV<->PATH states. ACE_SOCK_Dgram_Mcast_QoS dgram_mcast_qos; // Multicast Session Address specified by user at command line. // If this address is not specified, // <localhost:ACE_DEFAULT_MULTICAST_PORT> is assumed. ACE_INET_Addr mult_addr (*(qos_util.mult_session_addr ())); // Fill the ACE_QoS_Params to be passed to the <ACE_OS::join_leaf> // through subscribe. ACE_QoS_Params qos_params; FillQoSParams (qos_params, 0, &ace_qos_sender); // Create a QoS Session Factory. ACE_QoS_Session_Factory session_factory; // Ask the factory to create a QoS session. This could be RAPI or // GQoS based on the parameter passed. ACE_QoS_Session *qos_session = session_factory.create_session (ACE_QoS_Session_Factory::ACE_RAPI_SESSION); // Create a destination address for the QoS session. The same // address should be used for the subscribe call later. A copy is // made below only to distinguish the two usages of the dest // address. ACE_INET_Addr dest_addr (mult_addr); // A QoS session is defined by the 3-tuple [DestAddr, DestPort, // Protocol]. Initialize the QoS session. if (qos_session->open (mult_addr, IPPROTO_UDP) == -1) ACE_ERROR_RETURN ((LM_ERROR, "Error in opening the QoS session\n"), -1); else ACE_DEBUG ((LM_DEBUG, "QoS session opened successfully\n")); // The following call opens the Dgram_Mcast and calls the // <ACE_OS::join_leaf> with the qos_params supplied here. Note the // QoS session object is passed into this call. This subscribes the // underlying socket to the passed in QoS session. For joining // multiple multicast sessions, the following subscribe call should // be made with different multicast addresses and a new QoS session // object should be passed in for each such call. The QoS session // objects can be created only through the session factory. Care // should be taken that the mult_addr for the subscribe() call // matches the dest_addr of the QoS session object. If this is not // done, the subscribe call will fail. A more abstract version of // subscribe will be added that constrains the various features of // GQoS like different flags etc. if (dgram_mcast_qos.subscribe (mult_addr, qos_params, 1, 0, AF_INET, // ACE_FROM_PROTOCOL_INFO, 0, 0, // ACE_Protocol_Info, 0, ACE_OVERLAPPED_SOCKET_FLAG | ACE_FLAG_MULTIPOINT_C_LEAF | ACE_FLAG_MULTIPOINT_D_LEAF, qos_session) == -1) ACE_ERROR_RETURN ((LM_ERROR, "Error in subscribe\n"), -1); else ACE_DEBUG ((LM_DEBUG, "Dgram_Mcast subscribe succeeds \n")); int nIP_TTL = 25; char achInBuf [BUFSIZ]; u_long dwBytes; // Should this be abstracted into QoS objects ?? Doesnt seem to have // to do anything directly with QoS. if (ACE_OS::ioctl (dgram_mcast_qos.get_handle (), // Socket. ACE_SIO_MULTICAST_SCOPE, // IO control code. &nIP_TTL, // In buffer. sizeof (nIP_TTL), // Length of in buffer. achInBuf, // Out buffer. BUFSIZ, // Length of Out buffer. &dwBytes, // bytes returned. 0, // Overlapped. 0) == -1) // Func. ACE_ERROR ((LM_ERROR, "Error in Multicast scope ACE_OS::ioctl() \n")); else ACE_DEBUG ((LM_DEBUG, "Setting TTL with Multicast scope ACE_OS::ioctl call succeeds \n")); int bFlag = 0; // Should this be abstracted into QoS objects ?? Doesnt seem to have // to do anything directly with QoS. if (ACE_OS::ioctl (dgram_mcast_qos.get_handle (), // Socket. ACE_SIO_MULTIPOINT_LOOPBACK, // IO control code. &bFlag, // In buffer. sizeof (bFlag), // Length of in buffer. achInBuf, // Out buffer. BUFSIZ, // Length of Out buffer. &dwBytes, // bytes returned. 0, // Overlapped. 0) == -1) // Func. ACE_ERROR ((LM_ERROR, "Error in Loopback ACE_OS::ioctl() \n")); else ACE_DEBUG ((LM_DEBUG, "Disable Loopback with ACE_OS::ioctl call succeeds \n")); // This is a sender. qos_session->flags (ACE_QoS_Session::ACE_QOS_SENDER); ACE_QoS_Manager qos_manager = dgram_mcast_qos.qos_manager (); // Since we are using RSVP, it is imperative that the client // application have the option of supplying the source sender // port for the RSVP messages. A default will be chosen by the // ACE API if this is not done. qos_session->source_port (qos_util.source_port ()); // Set the QoS for the session. Replaces the ioctl () call that // was being made previously. if (qos_session->qos (&dgram_mcast_qos, &qos_manager, ace_qos_sender) == -1) ACE_ERROR_RETURN ((LM_ERROR, "Unable to set QoS\n"), -1); else ACE_DEBUG ((LM_DEBUG, "Setting QOS succeeds.\n")); // Register a signal handler that helps to gracefully close the open // QoS sessions. QoS_Signal_Handler qos_signal_handler (qos_session); // Register the usual SIGINT signal handler with the Reactor for // the application to gracefully release the QoS session and // shutdown. if (ACE_Reactor::instance ()->register_handler (SIGINT, &qos_signal_handler) == -1) ACE_ERROR_RETURN ((LM_ERROR, "Error in registering the Signal Handler.\n"), -1); // Handler to process QoS and Data events for the reciever. Sender_QoS_Event_Handler qos_event_handler (dgram_mcast_qos, qos_session); // Decorate the above handler with QoS functionality. ACE_QoS_Decorator qos_decorator (&qos_event_handler, qos_session); // Initialize the Decorator. if (qos_decorator.init () != 0) ACE_ERROR_RETURN ((LM_ERROR, "QoS Decorator init () failed.\n"), -1); // Register the decorated Event Handler with the Reactor. if (ACE_Reactor::instance ()->register_handler (&qos_decorator, ACE_Event_Handler::QOS_MASK | ACE_Event_Handler::READ_MASK) == -1) ACE_ERROR_RETURN ((LM_ERROR, "Error in registering the Decorator with the Reactor\n"), -1); // // Instantiate a QOS Event Handler and pass the Dgram_Mcast and QoS // // session object into it. // ACE_QOS_Event_Handler qos_event_handler (dgram_mcast_qos, // qos_session); // ACE_RAPI_Event_Handler rapi_event_handler (qos_session); // // Register the RAPI Event Handler with the Reactor. This // // handles the QoS events. // if (ACE_Reactor::instance ()->register_handler // (&rapi_event_handler, // ACE_Event_Handler::QOS_MASK | ACE_Event_Handler::READ_MASK) == -1) // ACE_ERROR_RETURN ((LM_ERROR, // "Error in registering the RAPI Event Handler\n"), // -1); // Start the event loop. ACE_DEBUG ((LM_DEBUG, "Running the Event Loop ... \n")); ACE_Reactor::instance ()->run_event_loop (); ACE_DEBUG ((LM_DEBUG, "(%P|%t) shutting down server logging daemon\n")); } else ACE_DEBUG ((LM_DEBUG, "Specify a -m option for multicast application\n")); return 0; }
// Parse arguments on command line void DRV_parse_args (long ac, char **av) { ACE_CString buffer; char *s = 0; long i; bool has_space = false; FE_store_env_include_paths (); DRV_cpp_init (); idl_global->set_prog_name (av[0]); for (i = 1; i < ac; i++) { if (av[i][0] == '-') { idl_global->append_idl_flag (av[i]); switch (av[i][1]) { case 0: // One or more letters expected after the dash. ACE_ERROR (( LM_ERROR, ACE_TEXT ("IDL: Space between dash and option ") ACE_TEXT ("letters not allowed\n") )); ++i; idl_global->set_err_count (idl_global->err_count () + 1); break; case 'A': if (av[i][2] == '\0') { if (i < ac - 1) { s = av[i + 1]; ++i; } else { ACE_ERROR (( LM_ERROR, ACE_TEXT ("IDL: incorrect use of ") ACE_TEXT ("the -A option\n") )); idl_global->set_compile_flags ( idl_global->compile_flags () | IDL_CF_ONLY_USAGE ); break; } } else { s = av[i] + 2; } ACE_OS::strcat (idl_global->local_escapes (), s); ACE_OS::strcat (idl_global->local_escapes (), " "); break; case 'a': if (av[i][2] == 'e') { idl_global->anon_type_diagnostic ( IDL_GlobalData::ANON_TYPE_ERROR); } else if (av[i][2] == 'w') { idl_global->anon_type_diagnostic ( IDL_GlobalData::ANON_TYPE_WARNING); } else if (av[i][2] == 's') { idl_global->anon_type_diagnostic ( IDL_GlobalData::ANON_TYPE_SILENT); } else { ACE_ERROR (( LM_ERROR, ACE_TEXT ("IDL: I don't understand") ACE_TEXT (" the '%s' option\n"), ACE_TEXT_CHAR_TO_TCHAR (av[i]) )); } break; // Temp directory for the IDL compiler to keep its files. case 't': if ((av[i][2] == '\0') && (i < ac - 1)) { idl_global->append_idl_flag (av[i + 1]); idl_global->temp_dir (av[i + 1]); ++i; } else { ACE_ERROR (( LM_ERROR, ACE_TEXT ("IDL: I don't understand") ACE_TEXT (" the '%s' option\n"), ACE_TEXT_CHAR_TO_TCHAR (av[i]) )); idl_global->set_compile_flags ( idl_global->compile_flags () | IDL_CF_ONLY_USAGE ); } break; case 'D': case 'U': case 'I': if (av[i][2] == '\0') { if (i < ac - 1) { idl_global->append_idl_flag (av[i + 1]); has_space = FE_Utils::hasspace (av[i + 1]); // If the include path has a space, we need to // add literal "s. ACE_CString arg = av[i]; arg += (has_space ? "\"" : ""); arg += av[i + 1]; arg += (has_space ? "\"" : ""); DRV_cpp_putarg (arg.c_str ()); idl_global->add_include_path (arg.substr (2).c_str (), false); ++i; } else { ACE_ERROR (( LM_ERROR, ACE_TEXT ("IDL: I don't understand") ACE_TEXT (" the '%s' option\n"), ACE_TEXT_CHAR_TO_TCHAR (av[i]) )); idl_global->set_compile_flags ( idl_global->compile_flags () | IDL_CF_ONLY_USAGE ); break; } } else { has_space = FE_Utils::hasspace (av[i]); // If the include path has a space, we need to // add literal "s. ACE_CString arg (av[i], 2); arg += (has_space ? "\"" : ""); arg += av[i] + 2; arg += (has_space? "\"" : ""); idl_global->add_include_path (arg.substr (2).c_str (), false); DRV_cpp_putarg (arg.c_str ()); } break; case 'E': idl_global->set_compile_flags (idl_global->compile_flags () | IDL_CF_ONLY_PREPROC); break; case 'V': idl_global->set_compile_flags (idl_global->compile_flags () | IDL_CF_VERSION); break; case 'W': if (av[i][2] == '\0') { if (i < ac - 1) { s = av[i + 1]; ++i; } else { ACE_ERROR (( LM_ERROR, ACE_TEXT ("IDL: I don't understand") ACE_TEXT (" the '%s' option\n"), ACE_TEXT_CHAR_TO_TCHAR (av[i]) )); idl_global->set_compile_flags ( idl_global->compile_flags () | IDL_CF_ONLY_USAGE ); break; } } else { s = av[i] + 2; } switch (*s) { default: ACE_ERROR (( LM_ERROR, ACE_TEXT ("IDL: Incorrect use of -W option\n") )); idl_global->set_compile_flags ( idl_global->compile_flags () | IDL_CF_ONLY_USAGE ); break; case 'p': if (*(s + 1) == ',') { DRV_prep_cpp_arg (s + 2); } break; case 'b': if (*(s + 1) == ',') { be_util::prep_be_arg (s + 2); } break; } break; case 'Y': if (av[i][2] == '\0') { if (i < ac - 1) { s = av[i + 1]; ++i; } else { ACE_ERROR (( LM_ERROR, ACE_TEXT ("IDL: I don't understand") ACE_TEXT (" the '%s' option\n"), ACE_TEXT_CHAR_TO_TCHAR (av[i]) )); idl_global->set_compile_flags ( idl_global->compile_flags () | IDL_CF_ONLY_USAGE ); break; } } else { s = av[i] + 2; } switch (*s) { case 'p': if (*(s + 1) == ',') { idl_global->set_cpp_location (s + 2); DRV_cpp_new_location (s + 2); } else { ACE_ERROR (( LM_ERROR, ACE_TEXT ("IDL: I don't understand") ACE_TEXT (" the '-Y' option\n") )); idl_global->set_compile_flags ( idl_global->compile_flags () | IDL_CF_ONLY_USAGE ); } break; default: ACE_ERROR (( LM_ERROR, ACE_TEXT ("IDL: I dont' understand the use of") ACE_TEXT (" %s with the '-Y' option\n"), ACE_TEXT_CHAR_TO_TCHAR (s) )); idl_global->set_compile_flags ( idl_global->compile_flags () | IDL_CF_ONLY_USAGE ); break; } break; case 'd': idl_global->set_compile_flags (idl_global->compile_flags () | IDL_CF_DUMP_AST); break; case 'u': idl_global->set_compile_flags (idl_global->compile_flags () | IDL_CF_ONLY_USAGE); break; case 'v': idl_global->set_compile_flags (idl_global->compile_flags () | IDL_CF_INFORMATIVE); break; case 'w': idl_global->set_compile_flags (idl_global->compile_flags () | IDL_CF_NOWARNINGS); break; case 'C': // If identifiers in the same scope differ only by case... if (av[i][2] == 'e') { // ...report an error. idl_global->case_diff_error (true); } else if (av[i][2] == 'w') { // ...report a warning (default for now) idl_global->case_diff_error (false); } else { ACE_ERROR (( LM_ERROR, ACE_TEXT ("IDL: I don't understand the '%s' option\n"), ACE_TEXT_CHAR_TO_TCHAR (av[i]) )); idl_global->set_compile_flags ( idl_global->compile_flags () | IDL_CF_ONLY_USAGE ); } break; default: be_global->parse_args (i, av); break; } // End of switch (av[i][1]) } // End of IF (av[i][0] == '-') else { DRV_push_file (av[i]); } } // End of FOR (i = 1; i < ac; i++) be_util::arg_post_proc (); // Make sure the output directory is valid. if (idl_global->temp_dir () == 0) { ACE_TCHAR tmpdir[MAXPATHLEN + 1]; if (ACE::get_temp_dir (tmpdir, MAXPATHLEN) == -1) { ACE_ERROR ((LM_ERROR, ACE_TEXT ("Temporary path too long, ") ACE_TEXT ("defaulting to current directory\n"))); ACE_OS::strcpy (tmpdir, ACE_TEXT (".")); } #if defined(ACE_MVS) if (ACE_OS::access (tmpdir, F_OK) == -1 || ACE_OS::access (tmpdir, R_OK) == -1 || ACE_OS::access (tmpdir, W_OK) == -1) #else if (ACE_OS::access (tmpdir, F_OK | R_OK | W_OK) == -1) #endif /* ACE_MVS */ { ACE_ERROR (( LM_ERROR, ACE_TEXT ("Can't access temporary directory (%s),") ACE_TEXT (" using current directory for temp files.\n"), tmpdir )); ACE_OS::strcpy (tmpdir, ACE_TEXT (".")); #if defined(ACE_MVS) if (ACE_OS::access (tmpdir, F_OK) == -1 || ACE_OS::access (tmpdir, R_OK) == -1 || ACE_OS::access (tmpdir, W_OK) == -1) #else if (ACE_OS::access (tmpdir, F_OK | R_OK | W_OK) == -1) #endif /* ACE_MVS */ { ACE_ERROR ((LM_ERROR, "Error: Can't access temporary directory %s\n", tmpdir)); throw Bailout (); } } idl_global->temp_dir (ACE_TEXT_ALWAYS_CHAR (tmpdir)); } DRV_cpp_post_init (); }
int ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { int priority = (ACE_Sched_Params::priority_min (ACE_SCHED_FIFO) + ACE_Sched_Params::priority_max (ACE_SCHED_FIFO)) / 2; // Enable FIFO scheduling, e.g., RT scheduling class on Solaris. if (ACE_OS::sched_params (ACE_Sched_Params (ACE_SCHED_FIFO, priority, ACE_SCOPE_PROCESS)) != 0) { if (ACE_OS::last_error () == EPERM) { ACE_DEBUG ((LM_DEBUG, "client (%P|%t): user is not superuser, " "test runs in time-shared class\n")); } else ACE_ERROR ((LM_ERROR, "client (%P|%t): sched_params failed\n")); } int interceptor_type; get_interceptor_type (argc, argv, interceptor_type); try { PortableInterceptor::ORBInitializer_ptr temp_initializer; ACE_NEW_RETURN (temp_initializer, Client_ORBInitializer (interceptor_type), -1); // No exceptions yet! PortableInterceptor::ORBInitializer_var initializer = temp_initializer; PortableInterceptor::register_orb_initializer (initializer.in ()); 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); Test_Interceptors::Secure_Vault_var server = Test_Interceptors::Secure_Vault::_narrow (object.in ()); if (CORBA::is_nil (server.in ())) { ACE_ERROR_RETURN ((LM_ERROR, "Object reference <%s> is nil.\n", ior), 1); } ACE_DEBUG ((LM_DEBUG, "\nFunctionality test begins now...\n")); // This test is useful for benchmarking the differences when // the same method is intercepted by different interceptors // wanting to achieve different functionality. run_test (server.in ()); server->shutdown (); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Caught exception:"); return 1; } return 0; }
int asynch_foo_generator::svc () { // multiple ::UsesSM::Sender::sendc_run_my_um_oneConnections_var my_one_ami_ = context_->get_connections_sendc_run_my_um_one(); // simplex ::UsesSM::AMI4CCM_Two_var my_two_ami_ = context_->get_connection_sendc_run_my_two(); if (my_one_ami_->length () == 0) { ACE_ERROR ((LM_ERROR, "ERROR Sender (ASYNCH) :my_one_ami_ is NIL !\n")); return 1; } if (CORBA::is_nil (my_two_ami_)) { ACE_ERROR ((LM_ERROR, "ERROR Sender (ASYNCH) :my_two_ami_ is NIL !\n")); return 1; } // Invoke Asynchronous calls to test for (CORBA::ULong i = 0; i < my_one_ami_->length (); ++i) { ::UsesSM::AMI4CCM_OneReplyHandler_var cb_one = new AMI4CCM_OneReplyHandler_run_my_um_one_i ( this->nr_of_received_, this->nr_of_sent_); CORBA::String_var test; switch (i) { case 0: test = CORBA::string_dup ("Asynch. foo call one"); break; case 1: test = CORBA::string_dup ("Asynch. foo call two"); break; case 2: test = CORBA::string_dup ("Asynch. foo call three"); break; default: break; } ++this->nr_of_sent_; my_one_ami_[i].objref->sendc_foo (cb_one.in (), test.in (), i); ACE_DEBUG ((LM_DEBUG, "Sender (ASYNCH) : send <%C> !\n", test.in ())); // There is more than 1 message sent, without receiving callbacks, // so it is asynchronous if (this->nr_of_sent_.value() > 1) { asynch = true; } ACE_DEBUG ((LM_DEBUG, "Sender (ASYNCH) : send asynch call bar <%u>!\n", i)); ::UsesSM::AMI4CCM_TwoReplyHandler_var cb_two = new AMI4CCM_TwoReplyHandler_run_my_two_i ( this->nr_of_received_); my_two_ami_->sendc_bar ( cb_two.in (), i); } return 0; }
void DataReaderListenerImpl::on_data_available(DDS::DataReader_ptr reader) throw(CORBA::SystemException) { ++num_reads_; try { Messenger::MessageDataReader_var message_dr = Messenger::MessageDataReader::_narrow(reader); if (CORBA::is_nil(message_dr.in())) { ACE_ERROR((LM_ERROR, ACE_TEXT("%N:%l: on_data_available()") ACE_TEXT(" ERROR: _narrow failed!\n"))); ACE_OS::exit(-1); } Messenger::Message message; DDS::SampleInfo si; DDS::ReturnCode_t status = message_dr->take_next_sample(message, si) ; if (status == DDS::RETCODE_OK) { std::cout << "SampleInfo.sample_rank = " << si.sample_rank << std::endl; std::cout << "SampleInfo.instance_state = " << si.instance_state << std::endl; if (si.valid_data) { if (!counts_.insert(message.count).second) { std::cout << "ERROR: Repeat "; valid_ = false; } phases_.insert(message.phase_number); std::cout << "Message: subject = " << message.subject.in() << std::endl << " subject_id = " << message.subject_id << std::endl << " from = " << message.from.in() << std::endl << " count = " << message.count << std::endl << " phase = " << message.phase_number << std::endl << " text = " << message.text.in() << std::endl; if (std::string("Comic Book Guy") != message.from.in() && std::string("OpenDDS-Java") != message.from.in()) { std::cout << "ERROR: Invalid message.from" << std::endl; valid_ = false; } if (std::string("Review") != message.subject.in()) { std::cout << "ERROR: Invalid message.subject" << std::endl; valid_ = false; } if (std::string("Worst. Movie. Ever.") != message.text.in()) { std::cout << "ERROR: Invalid message.text" << std::endl; valid_ = false; } if (message.subject_id != 99) { std::cout << "ERROR: Invalid message.subject_id" << std::endl; valid_ = false; } } else if (si.instance_state == DDS::NOT_ALIVE_DISPOSED_INSTANCE_STATE) { ACE_DEBUG((LM_DEBUG, ACE_TEXT("%N:%l: INFO: instance is disposed\n"))); } else if (si.instance_state == DDS::NOT_ALIVE_NO_WRITERS_INSTANCE_STATE) { ACE_DEBUG((LM_DEBUG, ACE_TEXT("%N:%l: INFO: instance is unregistered\n"))); } else { ACE_ERROR((LM_ERROR, ACE_TEXT("%N:%l: on_data_available()") ACE_TEXT(" ERROR: unknown instance state: %d\n"), si.instance_state)); valid_ = false; } } else { ACE_ERROR((LM_ERROR, ACE_TEXT("%N:%l: on_data_available()") ACE_TEXT(" ERROR: unexpected status: %d\n"), status)); valid_ = false; } } catch (const CORBA::Exception& e) { e._tao_print_exception("Exception caught in on_data_available():"); ACE_OS::exit(-1); } }
template<class T, class H> void CDR_Test<T, H>::do_test (int total, int niter, int use_array, char* srcbuf, char* dstbuf, int src_offset, int dst_offset) { if (!use_array) { dst_offset = src_offset = 0; } ACE_DEBUG((LM_DEBUG, ACE_TEXT( "Starting Test for %s: %d elements " ) ACE_TEXT( "%susing arrays.\n" ), H::name (), total, ((use_array) ? ACE_TEXT( "" ) : ACE_TEXT( "not " )))); if (!use_array && (total % 4) != 0) { int lasttotal = total; total -= (total % 4); ACE_DEBUG((LM_DEBUG, ACE_TEXT( "Rounding from %d to %d elements.\n" ), lasttotal, total)); } char* src = ACE_ptr_align_binary(srcbuf, H::size ()); T* idata = reinterpret_cast<T*> (src); idata += src_offset; src = reinterpret_cast<char*> (idata); { int i; for (i = 0; i < total; i++) { idata[i] = CDR_Test<T, H>::checkval (i); } } ACE_DEBUG((LM_DEBUG, ACE_TEXT( "Writing data...\n" ))); char* toread = 0; { ACE_TEST_ASSERT(use_array || total % 4 == 0); double totalsecs = 0.0; int n; for (n = 0; n < niter; n++) { size_t size = H::size () * (dst_offset + total) + ACE_CDR::MAX_ALIGNMENT; ACE_OutputCDR os (dstbuf, size); // This is intrusive... char* const end = os.begin ()->wr_ptr() + size; do_seal (end); double secs = 0.0; if (use_array) { { int i; for (i = 0; i < dst_offset; i++) { os << T(0); } } if (n == 0) { ACE_DEBUG((LM_DEBUG, ACE_TEXT ("* src align = %d, dst align = %d\n"), tellalign (src), tellalign (os.begin ()->wr_ptr ()))); } Crono crono; crono.start (); H::write_array (os, idata, total); crono.stop (); secs = crono.read_seconds (); } else { int i = 0; for (; i < dst_offset; i++) { os << T(0); } i = 0; Crono crono; crono.start(); while (i < total) { os << idata[i++]; os << idata[i++]; os << idata[i++]; os << idata[i++]; // static char rs[32 + 1]; // CDR_Test<T,H>::ttoh (idata[i], rs); // ACE_DEBUG ((LM_DEBUG, "Write idata[%d] = %s\n", i, rs)); // os << idata[i]; // i++; } crono.stop (); secs = crono.read_seconds (); } if (!check_seal(end)) { ACE_ERROR((LM_ERROR, ACE_TEXT( "Broken seal, aborting.\n" ))); ACE_OS::exit(1); } totalsecs += secs; if (n == niter - 1) { toread = os.begin ()->rd_ptr (); } } totalsecs = totalsecs / niter; ACE_DEBUG((LM_DEBUG, ACE_TEXT ("Writing to stream %d %s values: %f seconds.\n"), total, H::name (), totalsecs)); } { int i; for (i = 0; i < total; i++) { idata[i] = 0; } } ACE_DEBUG((LM_DEBUG, ACE_TEXT( "Reading them back in opposing byte order...\n" ))); const int opposite_byte_order = 1 - ACE_CDR_BYTE_ORDER; { double totalsecs = 0.0; int n; for (n = 0; n < niter; n++) { ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("====== Read iteration %d\n"), n)); size_t size = (total + dst_offset) * H::size (); ACE_InputCDR is (toread, size, opposite_byte_order); // This is intrusive... char* const end = is.rd_ptr () + size; do_seal (end); double secs = 0.0; if (use_array) { { int i; for (i = 0; i < dst_offset; i++) { T v; is >> v; } } if (n == 0) { ACE_DEBUG((LM_DEBUG, ACE_TEXT ("* src align = %d, dst align = %d\n"), tellalign (is.rd_ptr ()), tellalign (src))); } Crono crono; crono.start (); H::read_array (is, idata, total); crono.stop (); secs = crono.read_seconds (); // Testing for good bit value. Try reading atleast 10 // times the size of total. It should fail with good bit // set to 0. H::read_array (is, idata, 10 * total); if (is.good_bit () != 0) { ACE_ERROR ((LM_ERROR, ACE_TEXT ("Test for good bit failed in %s Array_test\n"), H::name ())); } } else { int i = 0; Crono crono; crono.start (); while (i < total) { #if 0 T v; is >> v; static char rs[32 + 1]; CDR_Test<T,H>::ttoh (v, rs); ACE_DEBUG ((LM_DEBUG, "Read idata[%d] = %s\n", i, rs)); idata[i] = v; i++; #else is >> idata[i++]; is >> idata[i++]; is >> idata[i++]; is >> idata[i++]; #endif /* 0 */ } crono.stop (); secs = crono.read_seconds (); } totalsecs += secs; if (!check_seal (end)) { ACE_ERROR((LM_ERROR, ACE_TEXT( "Broken seal, aborting.\n" ))); ACE_OS::exit(1); } } totalsecs = totalsecs / niter; ACE_DEBUG((LM_DEBUG, ACE_TEXT ("Reading from stream %d %s values") ACE_TEXT (" (byte swapping): %f seconds.\n"), total, H::name (), totalsecs)); }
int ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { try { // create a domain manager, containing DomainParticipant configuration Domain_Manager domain_manager (argc, argv, QUOTER_DOMAIN_ID); // create a topic manager, related to the quote topic Topic_Manager quoter_topic_manager ( new Topic_Manager_T <StockQuoter::QuoteTypeSupport, StockQuoter::QuoteTypeSupportImpl> ( QUOTER_QUOTE_TOPIC)); // create a topic manager, related to the exchange topic Topic_Manager exchange_topic_manager ( new Topic_Manager_T <StockQuoter::ExchangeEventTypeSupport, StockQuoter::ExchangeEventTypeSupportImpl> ( QUOTER_EXCHANGE_EVENT_TOPIC)); // get a publication manager Publication_Manager publication_manager = domain_manager.publication_manager (); // create a quoter topic and an according data writer DDS::DataWriter_var quote_base_dw = publication_manager.access_topic (quoter_topic_manager); // narrow the received data writer StockQuoter::QuoteDataWriter_var quote_dw = StockQuoter::QuoteDataWriter::_narrow(quote_base_dw.in()); if (CORBA::is_nil (quote_dw.in ())) { cerr << "QuoteDataWriter could not be narrowed"<< endl; ACE_OS::exit(1); } // create an exchange topic and an according data writer DDS::DataWriter_var exchange_evt_base_dw = publication_manager.access_topic (exchange_topic_manager); // narrow the received data writer StockQuoter::ExchangeEventDataWriter_var exchange_evt_dw = StockQuoter::ExchangeEventDataWriter::_narrow(exchange_evt_base_dw.in()); if (CORBA::is_nil (exchange_evt_dw.in ())) { cerr << "ExchangeEventDataWriter could not be narrowed"<< endl; ACE_OS::exit(1); } // Register the Exchange Event and the two Quoted securities (SPY and MDY) StockQuoter::ExchangeEvent ex_evt; ex_evt.exchange = STOCK_EXCHANGE_NAME; DDS::InstanceHandle_t exchange_handle = exchange_evt_dw->register_instance(ex_evt); StockQuoter::Quote spy; spy.ticker = CORBA::string_dup("SPY"); DDS::InstanceHandle_t spy_handle = quote_dw->register_instance(spy); StockQuoter::Quote mdy; mdy.ticker = CORBA::string_dup("MDY"); DDS::InstanceHandle_t mdy_handle = quote_dw->register_instance(mdy); // Publish... StockQuoter::ExchangeEvent opened; opened.exchange = STOCK_EXCHANGE_NAME; opened.event = StockQuoter::TRADING_OPENED; opened.timestamp = get_timestamp(); cout << "Publishing TRADING_OPENED" << endl; DDS::ReturnCode_t ret = exchange_evt_dw->write(opened, exchange_handle); if (ret != DDS::RETCODE_OK) { ACE_ERROR ((LM_ERROR, ACE_TEXT("(%P|%t)ERROR: OPEN write returned %d.\n"), ret)); } ACE_Time_Value quarterSecond( 0, 250000 ); for ( int i = 0; i < 20; ++i ) { StockQuoter::Quote spy_quote; spy_quote.exchange = STOCK_EXCHANGE_NAME; spy_quote.ticker = CORBA::string_dup("SPY"); spy_quote.full_name = CORBA::string_dup("S&P Depository Receipts"); spy_quote.value = 1200.0 + 10.0*i; spy_quote.timestamp = get_timestamp(); cout << "Publishing SPY Quote: " << spy_quote.value << endl; ret = quote_dw->write(spy_quote, spy_handle); if (ret != DDS::RETCODE_OK) { ACE_ERROR ((LM_ERROR, ACE_TEXT("(%P|%t)ERROR: SPY write returned %d.\n"), ret)); } ACE_OS::sleep( quarterSecond ); StockQuoter::Quote mdy_quote; mdy_quote.exchange = STOCK_EXCHANGE_NAME; mdy_quote.ticker = CORBA::string_dup("MDY"); mdy_quote.full_name = CORBA::string_dup("S&P Midcap Depository Receipts"); mdy_quote.value = 1400.0 + 10.0*i; mdy_quote.timestamp = get_timestamp(); cout << "Publishing MDY Quote: " << mdy_quote.value <<endl; ret = quote_dw->write(mdy_quote, mdy_handle); if (ret != DDS::RETCODE_OK) { ACE_ERROR ((LM_ERROR, ACE_TEXT("(%P|%t)ERROR: MDY write returned %d.\n"), ret)); } ACE_OS::sleep( quarterSecond ); } StockQuoter::ExchangeEvent closed; closed.exchange = STOCK_EXCHANGE_NAME; closed.event = StockQuoter::TRADING_CLOSED; closed.timestamp = get_timestamp(); cout << "Publishing TRADING_CLOSED" << endl; ret = exchange_evt_dw->write(closed, exchange_handle); if (ret != DDS::RETCODE_OK) { ACE_ERROR ((LM_ERROR, ACE_TEXT("(%P|%t)ERROR: CLOSED write returned %d.\n"), ret)); } cout << "Exiting..." << endl; } catch (Manager_Exception& e) { cerr << "Manager_Exception caught in main.cpp:" << endl << e.reason () << endl; ACE_OS::exit(1); } catch (CORBA::Exception& e) { cerr << "Exception caught in main.cpp:" << endl << e << endl; ACE_OS::exit(1); } return 0; }
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"))); #if !defined(_UNICOS) 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); #else /* ! _UNICOS */ else if (!(siginfo->si_code == SEGV_MEMERR && siginfo->si_addr < (((unsigned long) this->base_addr_) + offset) && siginfo->si_addr >= ((unsigned long) this->base_addr_))) ACE_ERROR_RETURN ((LM_ERROR, "(%P|%t) address %u out of range\n", siginfo->si_addr), -1); #endif /* ! _UNICOS */ } // 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 !defined(_UNICOS) if (this->find_seg (siginfo->si_addr, offset, counter) == -1) #else /* ! _UNICOS */ if (this->find_seg ((const void *)siginfo->si_addr, offset, counter) == -1) #endif /* ! _UNICOS */ 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, "(%P|%t) %p, shmem = %u, address = %u\n", "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; }
void do_primary_test (CORBA::ORB_var &orb, Simple_Server_var &server) { try { CORBA::Object_var nilobj = CORBA::Object::_nil(); CORBA::Object_var object = orb->string_to_object (ior); server = Simple_Server::_narrow (object.in ()); if (CORBA::is_nil (server.in ())) { ACE_ERROR ((LM_ERROR, "Object reference <%s> is nil\n", ior)); return; } CORBA::Short x = server->s(); ACE_ERROR ((LM_ERROR,"Server->s() returned %d\n", x)); server->s(510); Structure the_in_structure; the_in_structure.i = x; the_in_structure.seq.length (10); the_in_structure.obj = CORBA::Object::_duplicate(server.in()); Structure_var out_struct; CORBA::String_var name = CORBA::string_dup ("test"); server->struct_test (12345, the_in_structure, out_struct.out(), name.inout()); CORBA::String_var outior = orb->object_to_string(out_struct->obj); ACE_DEBUG ((LM_DEBUG,"Got outior:\n%s\n", outior.in())); if (test_user_exception == 1) { server->raise_user_exception (); } else if (test_system_exception == 1) { server->raise_system_exception (); } if (test_user_exception != 0 || test_system_exception != 0) { ACE_DEBUG ((LM_DEBUG,"Expected exception not caught!\n")); return; } ACE_DEBUG ((LM_DEBUG,"Sending main ref\n")); CORBA::Object_var echo = server->echo_object (server.in()); ACE_DEBUG ((LM_DEBUG,"Sending nil ref\n")); echo = server->echo_object (nilobj.in()); CORBA::Any a; a <<= "String through Any"; CORBA::Boolean success = server->any_test (a); ACE_DEBUG ((LM_DEBUG,"any_test(string) returned %d\n",success)); a <<= server.in(); success = server->any_test (a); ACE_DEBUG ((LM_DEBUG,"any_test(objref) returned %d\n",success)); for (int i = 0; i != niterations; ++i) { the_in_structure.i = i; CORBA::String_var name = CORBA::string_dup ("the name"); Structure_var the_out_structure; CORBA::Long r = server->struct_test (i, the_in_structure, the_out_structure.out (), name.inout ()); ACE_DEBUG ((LM_DEBUG, "DSI_Simpler_Server ====\n" " x = %d\n" " i = %d\n" " length = %d\n" " name = <%s>\n", r, the_out_structure->i, the_out_structure->seq.length (), name.in ())); if (r != i) { ACE_DEBUG ((LM_DEBUG, "(%P|%t) unexpected result = %d for %d", r, i)); } } } catch (const test_exception& ex) { ex._tao_print_exception ("Client: exception caught - "); ACE_DEBUG ((LM_DEBUG, "error code: %d\n" "error info: %s\n" "status: %s\n", ex.error_code, ex.error_message.in (), ex.status_message.in ())); } catch (const CORBA::NO_PERMISSION& ex) { ex._tao_print_exception ("Client: exception caught - "); } catch (const CORBA::SystemException& sysEx) { sysEx._tao_print_system_exception (); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Client: exception caught - "); } }
ACE_Message_Block::ACE_Message_Block (const ACE_Message_Block &mb, size_t align) :flags_ (0), data_block_ (0) { ACE_TRACE ("ACE_Message_Block::ACE_Message_Block"); if(ACE_BIT_DISABLED (mb.flags_, ACE_Message_Block::DONT_DELETE)) { if(this->init_i (0, // size MB_NORMAL, // type 0, // cont 0, // data 0, // allocator 0, // locking strategy 0, // flags 0, // priority ACE_Time_Value::zero, // execution time ACE_Time_Value::max_time, // absolute time of deadline mb.data_block ()->duplicate (), // data block mb.data_block ()->data_block_allocator (), mb.message_block_allocator_) == -1) ACE_ERROR ((LM_ERROR, ACE_TEXT ("ACE_Message_Block"))); #if !defined (ACE_LACKS_CDR_ALIGNMENT) // Align ourselves char *start = ACE_ptr_align_binary (this->base (), align); #else char *start = this->base (); #endif /* ACE_LACKS_CDR_ALIGNMENT */ // Set our rd & wr pointers this->rd_ptr (start); this->wr_ptr (start); } else { if(this->init_i (0, // size MB_NORMAL, // type 0, // cont 0, // data 0, // allocator 0, // locking strategy 0, // flags 0, // priority ACE_Time_Value::zero, // execution time ACE_Time_Value::max_time, // absolute time of deadline mb.data_block ()->clone_nocopy (),// data block mb.data_block ()->data_block_allocator (), mb.message_block_allocator_) == -1) ACE_ERROR ((LM_ERROR, ACE_TEXT ("ACE_Message_Block"))); #if !defined (ACE_LACKS_CDR_ALIGNMENT) // Align ourselves char *start = ACE_ptr_align_binary (this->base (), align); #else char *start = this->base (); #endif /* ACE_LACKS_CDR_ALIGNMENT */ // Set our rd & wr pointers this->rd_ptr (start); this->wr_ptr (start); #if !defined (ACE_LACKS_CDR_ALIGNMENT) // Get the alignment offset of the incoming ACE_Message_Block start = ACE_ptr_align_binary (mb.base (), align); #else start = mb.base (); #endif /* ACE_LACKS_CDR_ALIGNMENT */ // Actual offset for the incoming message block assuming that it // is also aligned to the same "align" byte size_t const wr_offset = mb.wr_ptr_ - (start - mb.base ()); // Copy wr_offset amount of data in to <this->data_block> (void) ACE_OS::memcpy (this->wr_ptr (), start, wr_offset); // Dont move the write pointer, just leave it to the application // to do what it wants } #if defined (ACE_LACKS_CDR_ALIGNMENT) ACE_UNUSED_ARG (align); #endif /* ACE_LACKS_CDR_ALIGNMENT */ }
template <class HANDLER> void ACE_Asynch_Connector<HANDLER>::handle_connect (const ACE_Asynch_Connect::Result &result) { // Variable for error tracking int error = 0; // If the asynchronous connect fails. if (!result.success () || result.connect_handle () == ACE_INVALID_HANDLE) { error = 1; } if (result.error () != 0) { error = 1; } // set blocking mode if (!error && ACE::clr_flags (result.connect_handle (), ACE_NONBLOCK) != 0) { error = 1; ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("ACE_Asynch_Connector::handle_connect : Set blocking mode"))); } // Parse the addresses. ACE_INET_Addr local_address; ACE_INET_Addr remote_address; if (!error && (this->validate_new_connection_ || this->pass_addresses_)) this->parse_address (result, remote_address, local_address); // Call validate_connection even if there was an error - it's the only // way the application can learn the connect disposition. if (this->validate_new_connection_ && this->validate_connection (result, remote_address, local_address) == -1) { error = 1; } HANDLER *new_handler = 0; if (!error) { // The Template method new_handler = this->make_handler (); if (new_handler == 0) { error = 1; ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("ACE_Asynch_Connector::handle_connect : Making of new handler failed"))); } } // If no errors if (!error) { // Update the Proactor. new_handler->proactor (this->proactor ()); // Pass the addresses if (this->pass_addresses_) new_handler->addresses (remote_address, local_address); // Pass the ACT if (result.act () != 0) new_handler->act (result.act ()); // Set up the handler's new handle value new_handler->handle (result.connect_handle ()); ACE_Message_Block mb; // Initiate the handler with empty message block; new_handler->open (result.connect_handle (), mb); } // On failure, no choice but to close the socket if (error && result.connect_handle() != ACE_INVALID_HANDLE) ACE_OS::closesocket (result.connect_handle ()); }
int ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { int priority = (ACE_Sched_Params::priority_min (ACE_SCHED_FIFO) + ACE_Sched_Params::priority_max (ACE_SCHED_FIFO)) / 2; // Enable FIFO scheduling, e.g., RT scheduling class on Solaris. if (ACE_OS::sched_params (ACE_Sched_Params (ACE_SCHED_FIFO, priority, ACE_SCOPE_PROCESS)) != 0) { if (ACE_OS::last_error () == EPERM) { ACE_DEBUG ((LM_DEBUG, "client (%P|%t): user is not superuser, " "test runs in time-shared class\n")); } else ACE_ERROR ((LM_ERROR, "client (%P|%t): sched_params failed\n")); } 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); if (CORBA::is_nil (object.in ())) { ACE_ERROR_RETURN ((LM_ERROR, "Nil CORBA::Object reference <%s>\n", ior), 1); } Test::octet_load oc; for (int j = 0; j < 100; ++j) { CORBA::Request_var request = object->_request ("test_octet_method"); Test::Timestamp dummy = 0; request->add_in_arg("octet_load") <<= oc; request->add_in_arg("send_time") <<= dummy; request->set_return_type (CORBA::_tc_ulonglong); request->invoke (); } // Test various sequence types if (ACE_OS::strcmp (data_type, ACE_TEXT("octet")) == 0 ) { test_octet_seq (object); } else if (ACE_OS::strcmp (data_type, ACE_TEXT("char")) == 0) { test_char_seq (object); } else if (ACE_OS::strcmp (data_type, ACE_TEXT("long")) == 0) { test_long_seq (object); } else if (ACE_OS::strcmp (data_type, ACE_TEXT("short")) == 0) { test_short_seq (object); } else if (ACE_OS::strcmp (data_type, ACE_TEXT("double")) == 0) { test_double_seq (object); } else if (ACE_OS::strcmp (data_type, ACE_TEXT("longlong")) == 0) { test_longlong_seq (object); } if (do_shutdown) { CORBA::Request_var request = object->_request ("shutdown"); request->invoke (); } } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Exception caught:"); return 1; } return 0; }
int ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { try { CORBA::ORB_var orb = CORBA::ORB_init (argc, argv); CORBA::Object_var poa_object = orb->resolve_initial_references("RootPOA"); PortableServer::POA_var root_poa = PortableServer::POA::_narrow (poa_object.in ()); if (CORBA::is_nil (root_poa.in ())) ACE_ERROR_RETURN ((LM_ERROR, " (%P|%t) Panic: nil RootPOA\n"), 1); PortableServer::POAManager_var poa_manager = root_poa->the_POAManager (); if (parse_args (argc, argv) != 0) return 1; Hello *hello_impl = 0; ACE_NEW_RETURN (hello_impl, Hello (orb.in ()), 1); PortableServer::ServantBase_var owner_transfer(hello_impl); PortableServer::ObjectId_var id = root_poa->activate_object (hello_impl); CORBA::Object_var object = root_poa->id_to_reference (id.in ()); Test::Hello_var hello = Test::Hello::_narrow (object.in ()); CORBA::String_var ior = orb->object_to_string (hello.in ()); CORBA::Object_var tmp = orb->resolve_initial_references("IORTable"); IORTable::Table_var iorTable = IORTable::Table::_narrow(tmp.in ()); if (CORBA::is_nil(iorTable.in ())) { ACE_ERROR ((LM_ERROR, "could not get the IORTable, will not register\n")); } else { iorTable->rebind("Hello", ior.in()); } // try and access the object with its friendly name ACE_CString full_corbaloc (ior.in (), 0, 1); CORBA::ULong first_slash = full_corbaloc.find ("/", 0); ACE_CString friendly_corbaloc = full_corbaloc.substring (0, first_slash); friendly_corbaloc += "/Hello"; // Output the IOR to the <ior_output_file> FILE *output_file= ACE_OS::fopen (ior_output_file, "w"); if (output_file == 0) ACE_ERROR_RETURN ((LM_ERROR, "Cannot open output file for writing IOR: %s\n", ior_output_file), 1); ACE_OS::fprintf (output_file, "%s", friendly_corbaloc.c_str ()); ACE_OS::fclose (output_file); poa_manager->activate (); orb->run (); ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - event loop finished\n")); root_poa->destroy (1, 1); orb->destroy (); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Exception caught:"); return 1; } return 0; }
int ACE_Logging_Strategy::handle_timeout (const ACE_Time_Value &, const void *) { #if defined (ACE_LACKS_IOSTREAM_TOTALLY) if ((size_t) ACE_OS::fseek (this->log_msg_->msg_ostream (), 0, SEEK_CUR) > this->max_size_) #else if ((size_t) this->log_msg_->msg_ostream ()->tellp () > this->max_size_) #endif /* ACE_LACKS_IOSTREAM_TOTALLY */ { // Lock out any other logging. if (this->log_msg_->acquire ()) ACE_ERROR_RETURN ((LM_ERROR, ACE_LIB_TEXT ("Cannot acquire lock!\n")), -1); // Close the current ostream. #if defined (ACE_LACKS_IOSTREAM_TOTALLY) FILE *output_file = (FILE *) this->log_msg_->msg_ostream (); ACE_OS::fclose (output_file); // We'll call msg_ostream() modifier later. #else ofstream *output_file = (ofstream *) this->log_msg_->msg_ostream (); output_file->close (); #endif /* ACE_LACKS_IOSTREAM_TOTALLY */ // Save current logfile to logfile.old analyze if it was set any // fixed number for the log_files. if (fixed_number_) { if (max_file_number_ < 1) //we only want one file { // Just unlink the file. ACE_OS::unlink (this->filename_); // Open a new log file with the same name. #if defined (ACE_LACKS_IOSTREAM_TOTALLY) output_file = ACE_OS::fopen (this->filename_, "wt"); if (output_file == 0) return -1; this->log_msg_->msg_ostream (output_file); #else output_file->open (ACE_TEXT_ALWAYS_CHAR (this->filename_), ios::out); #endif /* ACE_LACKS_IOSTREAM_TOTALLY */ // Release the lock previously acquired. this->log_msg_->release (); return 0; } } count_++; // Set the number of digits of the log_files labels. int digits = 1, res = count_; while((res = (res / 10))>0) digits++; if (ACE_OS::strlen (this->filename_) + digits <= MAXPATHLEN) { ACE_TCHAR backup[MAXPATHLEN+1]; // analyse if it was chosen the mode which will order the // log_files if (order_files_) { ACE_TCHAR to_backup[MAXPATHLEN+1]; // reorder the logs starting at the oldest (the biggest // number) watch if we reached max_file_number_. int max_num; if (fixed_number_ && count_ > max_file_number_) // count_ will always be bigger than max_file_number_, // so do nothing so to always reorder files from // max_file_number_. max_num = max_file_number_; else max_num = count_; for (int i = max_num ; i > 1 ;i--) { ACE_OS::sprintf (backup, ACE_LIB_TEXT ("%s.%d"), this->filename_, i); ACE_OS::sprintf (to_backup, ACE_LIB_TEXT ("%s.%d"), this->filename_, i - 1); // Remove any existing old file; ignore error as // file may not exist. ACE_OS::unlink (backup); // Rename the current log file to the name of the // backup log file. ACE_OS::rename (to_backup, backup); } ACE_OS::sprintf (backup, ACE_LIB_TEXT ("%s.1"), this->filename_); } else { if (fixed_number_ && count_>max_file_number_) count_ = 1; // start over from 1 ACE_OS::sprintf (backup, ACE_LIB_TEXT ("%s.%d"), this->filename_, count_); } // Remove any existing old file; ignore error as file may // not exist. ACE_OS::unlink (backup); // Rename the current log file to the name of the backup log // file. ACE_OS::rename (this->filename_, backup); } else ACE_ERROR ((LM_ERROR, ACE_LIB_TEXT ("Backup file name too long; ") ACE_LIB_TEXT ("backup logfile not saved.\n"))); // Open a new log file by the same name #if defined (ACE_LACKS_IOSTREAM_TOTALLY) output_file = ACE_OS::fopen (this->filename_, "wt"); if (output_file == 0) return -1; this->log_msg_->msg_ostream (output_file); #else output_file->open (ACE_TEXT_ALWAYS_CHAR (this->filename_), ios::out); #endif /* ACE_LACKS_IOSTREAM_TOTALLY */ // Release the lock previously acquired. this->log_msg_->release (); } return 0; }