void SubDriver::run() { // Set up the publications. OpenDDS::DCPS::AssociationData publications[1]; publications[0].remote_id_ = this->pub_id_; publications[0].remote_data_.transport_id = 2; // TBD later - wrong OpenDDS::DCPS::NetworkAddress network_order_address(this->pub_addr_str_); ACE_OutputCDR cdr; cdr << network_order_address; size_t len = cdr.total_length (); publications[0].remote_data_.data = OpenDDS::DCPS::TransportInterfaceBLOB (len, len, (CORBA::Octet*)(cdr.buffer ())); // Write a file so that test script knows we're ready FILE * file = ACE_OS::fopen ("subready.txt", "w"); ACE_OS::fprintf (file, "Ready\n"); ACE_OS::fclose (file); this->subscriber_.init(ALL_TRAFFIC, this->sub_id_, 1, /* size of publications array */ publications, this->num_msgs_); // Wait until we receive our expected message from the remote // publisher. For this test, we should wait until we receive the // "Hello World!" message that we expect. Then this program // can just shutdown. while (this->subscriber_.received_test_message() == 0) { ACE_OS::sleep(1); } // Tear-down the entire Transport Framework. TheTransportFactory->release(); TheServiceParticipant->shutdown(); }
bool TcpTransport::connection_info_i(TransportLocator& local_info) const { DBG_ENTRY_LVL("TcpTransport", "connection_info_i", 6); VDBG_LVL((LM_DEBUG, "(%P|%t) TcpTransport public address str %C\n", this->tcp_config_->get_public_address().c_str()), 2); // Get the public address string from the inst (usually the local address) NetworkAddress network_order_address(this->tcp_config_->get_public_address()); ACE_OutputCDR cdr; cdr << network_order_address; const CORBA::ULong len = static_cast<CORBA::ULong>(cdr.total_length()); char* buffer = const_cast<char*>(cdr.buffer()); // safe local_info.transport_type = "tcp"; local_info.data = TransportBLOB(len, len, reinterpret_cast<CORBA::Octet*>(buffer)); return true; }
void PubDriver::run() { // Set up the subscriptions. TAO::DCPS::AssociationData subscriptions[1]; subscriptions[0].remote_id_ = this->sub_id_; subscriptions[0].remote_data_.transport_id = 1; // TBD - not right TAO::DCPS::NetworkAddress network_order_address(this->sub_addr_); subscriptions[0].remote_data_.data = TAO::DCPS::TransportInterfaceBLOB (sizeof(TAO::DCPS::NetworkAddress), sizeof(TAO::DCPS::NetworkAddress), (CORBA::Octet*)(&network_order_address)); this->publisher_.init(ALL_TRAFFIC, this->pub_id_, 1, /* size of subscriptions array */ subscriptions); // Wait for a fully association establishment and then start sending samples. ACE_OS::sleep (2); this->publisher_.run(this->num_msgs_); while (this->publisher_.delivered_test_message() == 0) { ACE_OS::sleep(1); } // TBD: Do we need a shutdown message from subscriber ? // Wait for subsciber to receive messages and then close the connection. // Increase the time when more messages are sent. //ACE_OS::sleep (5); // Tear-down the entire Transport Framework. TheTransportFactory->release(); }
int OpenDDS::DCPS::SimpleTcpConnection::open(void* arg) { DBG_ENTRY_LVL("SimpleTcpConnection","open",6); // A safety check - This should not happen since the is_connector_ // defaults to true and open() is called after the ACE_Aceptor // creates this new svc handler. if (this->is_connector_ == false) { return -1; } // This connection object represents the acceptor side. this->is_connector_ = false; // The passed-in arg is really the acceptor object that created this // SimpleTcpConnection object, and is also the caller of this open() // method. We need to cast the arg to the SimpleTcpAcceptor* type. SimpleTcpAcceptor* acceptor = ACE_static_cast(SimpleTcpAcceptor*,arg); if (acceptor == 0) { // The cast failed. ACE_ERROR_RETURN((LM_ERROR, "(%P|%t) ERROR: Failed to cast void* arg to " "SimpleTcpAcceptor* type.\n"), -1); } // Now we need to ask the SimpleTcpAcceptor object to provide us with // a pointer to the SimpleTcpTransport object that "owns" the acceptor. SimpleTcpTransport_rch transport = acceptor->transport(); if (transport.is_nil()) { // The acceptor gave us a nil transport (smart) pointer. ACE_ERROR_RETURN((LM_ERROR, "(%P|%t) ERROR: Acceptor's transport is nil.\n"), -1); } SimpleTcpConfiguration* tcp_config = acceptor->get_configuration(); // Keep a "copy" of the reference to SimpleTcpConfiguration object // for ourselves. tcp_config->_add_ref (); this->tcp_config_ = tcp_config; set_sock_options(this->tcp_config_.in ()); // We expect that the active side of the connection (the remote side // in this case) will supply its listening ACE_INET_Addr as the first // message it sends to the socket. This is a one-way connection // establishment protocol message. ACE_UINT32 nlen = 0; if (this->peer().recv_n(&nlen, sizeof(ACE_UINT32)) == -1) { ACE_ERROR_RETURN((LM_ERROR, "(%P|%t) ERROR: Unable to receive the length of address string " "from the remote (active) side of the connection." " %p\n", "recv_n"), -1); } ACE_UINT32 len = ntohl(nlen); char * buf = new char [len]; if (this->peer().recv_n(buf, len) == -1) { ACE_ERROR_RETURN((LM_ERROR, "(%P|%t) ERROR: Unable to receive the address string " "from the remote (active) side of the connection." " %p\n", "recv_n"), -1); } NetworkAddress network_order_address(buf); network_order_address.to_addr(this->remote_address_); delete[] buf; //MJM: vvv CONNECTION ESTABLISHMENT CHANGES vvv //MJM: Add code to send a response to the other side that the //MJM: connection is ready to receive at this point. It may be //MJM: necessary to do this higher in the layers to make sure that we //MJM: really are ready to receive. //MJM: This is the only really tricky bit, since I have not really //MJM: investigated enough to know where the connection is considered //MJM: complete on this end. I think that it will be when the datalink //MJM: is placed in all the containers. //MJM: This is also where this end needs to call back the //MJM: TransportInterface method that will eventually signal() the //MJM: wait()ing add_associations() call. It may not be necessary on //MJM: this (passive) to actually perform the wait() and signal() //MJM: operations. There is enough information in the //MJM: add_associations() call to differentiate the cases. //MJM: ^^^ CONNECTION ESTABLISHMENT CHANGES ^^^ VDBG((LM_DEBUG, "(%P|%t) DBG: " "SimpleTcpConnection::open %X %s:%d->%s:%d reconnect_state = %d\n", this, this->remote_address_.get_host_addr (), this->remote_address_.get_port_number (), this->local_address_.get_host_addr (), this->local_address_.get_port_number (), this->reconnect_state_)); // Now it is time to announce (and give) ourselves to the // SimpleTcpTransport object. transport->passive_connection(this->remote_address_,this); this->connected_ = true; return 0; }
void PubDriver::run() { FILE* fp = ACE_OS::fopen (pub_id_fname_.c_str (), ACE_LIB_TEXT("w")); if (fp == 0) { ACE_ERROR ((LM_ERROR, ACE_LIB_TEXT("Unable to open %s for writing:(%u) %p\n"), pub_id_fname_.c_str (), ACE_LIB_TEXT("PubDriver::run"))); return; } for (int i = 0; i < num_datawriters_; i ++) { ::Mine::FooDataWriterImpl* datawriter_servant = ::TAO::DCPS::reference_to_servant< ::Mine::FooDataWriterImpl, ::DDS::DataWriter_ptr> (datawriters_[i].in ()); TAO::DCPS::PublicationId pub_id = datawriter_servant->get_publication_id (); // Write the publication id to a file. ACE_DEBUG ((LM_DEBUG, ACE_TEXT("(%P|%t) PubDriver::run, ") ACE_TEXT(" Write to %s: pub_id=%d. \n"), pub_id_fname_.c_str (), pub_id)); ACE_OS::fprintf (fp, "%d\n", pub_id); } fclose (fp); // Set up the subscriptions. ::TAO::DCPS::ReaderAssociationSeq associations; associations.length (1); associations[0].readerTransInfo.transport_id = 1; // TBD - not right TAO::DCPS::NetworkAddress network_order_address(this->sub_addr_); associations[0].readerTransInfo.data = TAO::DCPS::TransportInterfaceBLOB (sizeof(TAO::DCPS::NetworkAddress), sizeof(TAO::DCPS::NetworkAddress), (CORBA::Octet*)(&network_order_address)); associations[0].readerId = this->sub_id_; associations[0].subQos = TheServiceParticipant->initial_SubscriberQos (); associations[0].readerQos = TheServiceParticipant->initial_DataReaderQos (); { for (int i = 0; i < num_datawriters_; i ++) { ::TAO::DCPS::DataWriterRemote_var dw_remote = ::TAO::DCPS::DataWriterRemote::_narrow (datawriters_[i].in ()); ::Mine::FooDataWriterImpl* datawriter_servant = ::TAO::DCPS::reference_to_servant< ::Mine::FooDataWriterImpl, ::DDS::DataWriter_ptr> (datawriters_[i].in ()); TAO::DCPS::PublicationId pub_id = datawriter_servant->get_publication_id (); dw_remote->add_associations (pub_id, associations); } } // Let the subscriber catch up before we broadcast. ACE_OS::sleep (2); // Each Writer/DataWriter launch threads to write samples // to the same instance or multiple instances. // When writing to multiple instances, the instance key // identifies instances is the thread id. { for (int i = 0; i < num_datawriters_; i ++) { writers_[i] = new Writer(this, datawriters_[i].in (), num_threads_to_write_, num_writes_per_thread_, multiple_instances_, i, has_key_, write_delay_msec_, check_data_dropped_); writers_[i]->start (); } } }
void SubDriver::run() { DBG_ENTRY_LVL("SubDriver", "run", 6); VDBG((LM_DEBUG, "(%P|%t) DBG: " "Initialize our SimpleSubscriber object.\n")); this->reader_.enable_transport(false /*reliable*/, false /*durable*/); // Write a file so that test script knows we're ready FILE * file = ACE_OS::fopen ("subready.txt", ACE_TEXT("w")); ACE_OS::fprintf (file, "Ready\n"); ACE_OS::fclose (file); VDBG((LM_DEBUG, "(%P|%t) DBG: Create the 'publications'.\n")); // Set up the publication. OpenDDS::DCPS::AssociationData publication; publication.remote_id_ = this->pub_id_; publication.remote_reliable_ = true; publication.remote_data_.length(1); if (shmem_) { publication.remote_data_[0].transport_type = "shmem"; std::ofstream ofs("sub-pid.txt"); ofs << ACE_OS::getpid() << std::endl; ofs.close(); for (ACE_stat filestat; -1 == ACE_OS::stat("pub-pid.txt", &filestat); ACE_OS::sleep(1)) {/*empty loop*/} std::ifstream ifs("pub-pid.txt"); std::string pid; getline(ifs, pid); std::string str = OpenDDS::DCPS::get_fully_qualified_hostname() + '\0' + "OpenDDS-" + pid + "-shmem1"; publication.remote_data_[0].data.length(static_cast<CORBA::ULong>(str.size())); std::memcpy(publication.remote_data_[0].data.get_buffer(), str.c_str(), str.size()); } else { // tcp publication.remote_data_[0].transport_type = "tcp"; OpenDDS::DCPS::NetworkAddress network_order_address( ACE_TEXT_ALWAYS_CHAR(this->pub_addr_str_.c_str())); ACE_OutputCDR cdr; cdr << network_order_address; CORBA::ULong len = static_cast<CORBA::ULong>(cdr.total_length()); publication.remote_data_[0].data = OpenDDS::DCPS::TransportBLOB(len, len, (CORBA::Octet*)(cdr.buffer())); } this->reader_.init(publication, this->num_msgs_); VDBG((LM_DEBUG, "(%P|%t) DBG: " "Ask the SimpleSubscriber object if it has received what, " "it expected. If not, sleep for 1 second, and ask again.\n")); // Wait until we receive our expected message from the remote // publisher. For this test, we should wait until we receive the // "Hello World!" message that we expect. Then this program // can just shutdown. while (this->reader_.received_test_message() == 0) { ACE_OS::sleep(1); } this->reader_.print_time(); if (shmem_) { ACE_OS::unlink("sub-pid.txt"); } VDBG((LM_DEBUG, "(%P|%t) DBG: " "The SimpleSubscriber object has received what it expected. " "Release TheTransportFactory - causing all TransportImpl " "objects to be shutdown().\n")); this->reader_.disassociate(this->pub_id_); TheServiceParticipant->shutdown(); VDBG((LM_DEBUG, "(%P|%t) DBG: " "TheTransportFactory has finished releasing.\n")); }
void PubDriver::run() { DBG_ENTRY_LVL("PubDriver","run",6); VDBG((LM_DEBUG, "(%P|%t) DBG: " "Initialize our SimplePublisher object.\n")); this->writer_.enable_transport(false /*reliable*/, false /*durable*/); VDBG((LM_DEBUG, "(%P|%t) DBG: Create the 'subscriptions'.\n")); // Set up the subscription. OpenDDS::DCPS::AssociationData subscription; subscription.remote_id_ = this->sub_id_; subscription.remote_reliable_ = true; subscription.remote_data_.length(1); if (shmem_) { subscription.remote_data_[0].transport_type = "shmem"; std::ofstream ofs("pub-pid.txt"); ofs << ACE_OS::getpid() << std::endl; ofs.close(); for (ACE_stat filestat; -1 == ACE_OS::stat("sub-pid.txt", &filestat); ACE_OS::sleep(1)) {/*empty loop*/} std::ifstream ifs("sub-pid.txt"); std::string pid; getline(ifs, pid); std::string str = OpenDDS::DCPS::get_fully_qualified_hostname() + '\0' + "OpenDDS-" + pid + "-shmem1"; subscription.remote_data_[0].data.length(static_cast<CORBA::ULong>(str.size())); std::memcpy(subscription.remote_data_[0].data.get_buffer(), str.c_str(), str.size()); } else { // tcp subscription.remote_data_[0].transport_type = "tcp"; OpenDDS::DCPS::NetworkAddress network_order_address( ACE_TEXT_ALWAYS_CHAR(this->sub_addr_str_.c_str())); ACE_OutputCDR cdr; cdr << network_order_address; CORBA::ULong len = static_cast<CORBA::ULong>(cdr.total_length()); subscription.remote_data_[0].data = OpenDDS::DCPS::TransportBLOB(len, len, (CORBA::Octet*)(cdr.buffer())); } this->writer_.init(subscription); // Wait for a fully association establishment and then start sending samples. ACE_OS::sleep(2); VDBG((LM_DEBUG, "(%P|%t) DBG: " "Run our SimplePublisher object.\n")); this->writer_.run(this->num_msgs_, this->msg_size_); VDBG((LM_DEBUG, "(%P|%t) DBG: " "Ask the SimplePublisher object if it is done running. " "If not, sleep for 1 second, and ask again.\n")); while (this->writer_.delivered_test_message() == 0) { ACE_OS::sleep(1); } if (shmem_) { for (ACE_stat filestat; 0 == ACE_OS::stat("sub-pid.txt", &filestat); ACE_OS::sleep(1)) {/*empty loop*/} } VDBG((LM_DEBUG, "(%P|%t) DBG: " "The SimplePublisher object is done running. " "Release TheTransportFactory - causing all TransportImpl " "objects to be shutdown().\n")); this->writer_.disassociate(this->sub_id_); TheServiceParticipant->shutdown(); VDBG((LM_DEBUG, "(%P|%t) DBG: " "TheTransportFactory has finished releasing.\n")); }
void SubDriver::run() { ACE_DEBUG ((LM_DEBUG, ACE_TEXT("(%P|%t) SubDriver::run, ") ACE_TEXT(" Wait for %s. \n"), pub_id_fname_.c_str ())); PublicationIds ids; // Wait for the publication id file created by the publisher. while (1) { FILE* fp = ACE_OS::fopen (pub_id_fname_.c_str (), ACE_TEXT("r")); if (fp == 0) { ACE_OS::sleep (1); } else { // This could be made cleaner by losing the old C-style I/O. ::OpenDDS::DCPS::PublicationId pub_id = OpenDDS::DCPS::GUID_UNKNOWN; char charBuffer[64]; while (fscanf (fp, "%s\n", &charBuffer[0]) != EOF) { std::stringstream buffer( charBuffer); buffer >> pub_id; ids.push_back (pub_id); std::stringstream idBuffer; idBuffer << pub_id; ACE_DEBUG ((LM_DEBUG, ACE_TEXT("(%P|%t) SubDriver::run, ") ACE_TEXT(" Got from %s: pub_id=%C. \n"), pub_id_fname_.c_str (), buffer.str().c_str())); } ACE_OS::fclose (fp); break; } } CORBA::Object_var object = orb_->string_to_object (pub_driver_ior_.c_str ()); pub_driver_ = ::Test::TestPubDriver::_narrow (object.in ()); TEST_CHECK (!CORBA::is_nil (pub_driver_.in ())); size_t num_publications = ids.size (); // Set up the publications. OpenDDS::DCPS::AssociationData* publications = new OpenDDS::DCPS::AssociationData[num_publications]; for (size_t i = 0; i < num_publications; i ++) { publications[i].remote_id_ = ids[i]; publications[i].remote_data_.transport_id = ALL_TRAFFIC; // TBD later - wrong publications[i].remote_data_.publication_transport_priority = 0; OpenDDS::DCPS::NetworkAddress network_order_address(this->pub_addr_str_); ACE_OutputCDR cdr; cdr << network_order_address; size_t len = cdr.total_length (); publications[i].remote_data_.data = OpenDDS::DCPS::TransportInterfaceBLOB (len, len, (CORBA::Octet*)(cdr.buffer ())); } this->subscriber_.init(ALL_TRAFFIC, this->sub_id_, num_publications, publications, receive_delay_msec_); delete [] publications; while (this->subscriber_.received_test_message() != num_writes_) { ACE_OS::sleep(1); } pub_driver_->shutdown (); // Sleep before release transport so the connection will not go away. // This would avoid the problem of publisher sendv failure due to lost // connection during the shutdown period. ACE_OS::sleep (5); OpenDDS::DCPS::WriterIdSeq writers; writers.length(num_publications); for (size_t i = 0; i < num_publications; ++i) { writers[i] = ids[i]; } this->subscriber_.remove_associations(num_publications, writers.get_buffer(), this->sub_id_); // Tear-down the entire Transport Framework. TheTransportFactory->release(); TheServiceParticipant->shutdown(); }