void TAO_ConstantDef_i::value_i (const CORBA::Any &value) { CORBA::TypeCode_var my_tc = this->type_i (); CORBA::TypeCode_var val_tc = value.type (); CORBA::Boolean const equal_tc = my_tc.in ()->equal (val_tc.in ()); if (!equal_tc) { return; } ACE_Message_Block *mb = 0; TAO::Any_Impl *impl = value.impl (); if (impl->encoded ()) { TAO::Unknown_IDL_Type *unk = dynamic_cast<TAO::Unknown_IDL_Type *> (impl); mb = unk->_tao_get_cdr ().steal_contents (); } else { TAO_OutputCDR out; impl->marshal_value (out); TAO_InputCDR in (out); mb = in.steal_contents (); } ACE_Auto_Ptr<ACE_Message_Block> safe (mb); CORBA::TCKind kind = val_tc->kind (); switch (kind) { // The data for these types will be aligned to an 8-byte // boundary, while the rd_ptr may not. case CORBA::tk_double: case CORBA::tk_ulonglong: case CORBA::tk_longlong: case CORBA::tk_longdouble: mb->rd_ptr (ACE_ptr_align_binary (mb->rd_ptr (), ACE_CDR::MAX_ALIGNMENT)); break; default: break; } mb->crunch (); this->repo_->config ()->set_binary_value (this->section_key_, "value", mb->base (), mb->length ()); }
// // returns the alignment of ptr, wrt ACE_CDR::MAX_ALIGNMENT. // int tellalign (const char* const ptr) { int align = ACE_CDR::MAX_ALIGNMENT; while (ptr != ACE_ptr_align_binary(ptr, align)) { align = align >> 1; } return align; }
// sets up the dataModeSocket Stream, reads the test header infomation // and launches a thread to handle the requested test. static void run_server (ACE_HANDLE handle) { ACE_INET_Addr cli_addr; // create a new stream and initialized with the handle returned by // accept ACE_SOCK_Stream * dataModeStream = new ACE_SOCK_Stream; dataModeStream->set_handle (handle); // Make sure we're not in non-blocking mode. if (dataModeStream->disable (ACE_NONBLOCK) == -1){ ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("disable"))); return; } else if (dataModeStream->get_remote_addr (cli_addr) == -1){ ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("get_remote_addr"))); return; } // explicity configure Nagling. Default is // Options_Manager::test_enable_nagle=0 so default configurations is // NO NAGLING ACE_CDR::Long nagle; if (Options_Manager::test_enable_nagle) nagle=0; else nagle=1; if (Options_Manager::test_transport_protocol == IPPROTO_SCTP){ // default - sctp case if (-1 == dataModeStream->set_option(IPPROTO_SCTP, SCTP_NODELAY, &nagle, sizeof nagle)){ ACE_ERROR((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("set_option"))); return; } } else { // tcp case if (-1 == dataModeStream->set_option(IPPROTO_TCP, TCP_NODELAY, &nagle, sizeof nagle)){ ACE_ERROR ((LM_ERROR, "%p\n", "set_option")); return; } } ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) client %C connected from %d\n"), cli_addr.get_host_name (), cli_addr.get_port_number ())); // hdr bufSize is hardcoded to 8 bytes // (4 for a CDR-encoded boolean and 4 for a CDR-encoded ULong) ACE_CDR::ULong hdrBufSize = 8; // allocate a raw buffer large enough to receive the header and be // properly aligned for the CDR decoding. ACE_CDR::Char * hdrBuf= new ACE_CDR::Char[hdrBufSize+ACE_CDR::MAX_ALIGNMENT]; // align the raw buffer before reading data into it. char * hdrBuf_a = ACE_ptr_align_binary(hdrBuf, ACE_CDR::MAX_ALIGNMENT); size_t bt; // read the header if ((dataModeStream->recv_n(hdrBuf_a, hdrBufSize, 0, &bt)) == -1){ ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("recv_n"))); return; } // pass the CDR encoded data into an ACE_InputCDR class. hdrCDR does // NOT copy this data. Nor does it delete. It assumes the buffer // remains valid while it is in scope. ACE_InputCDR hdrCDR(hdrBuf_a, hdrBufSize); ACE_CDR::Boolean byteOrder; ACE_CDR::ULong numIterations; // extract the data hdrCDR >> ACE_InputCDR::to_boolean (byteOrder); hdrCDR.reset_byte_order(byteOrder); hdrCDR >> numIterations; // make sure the stream is good after the extractions if (!hdrCDR.good_bit()){ ACE_ERROR((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("hdrCDR"))); return; } ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) Test for %u iterations\n"), numIterations)); // deallocate the header buffer delete[] hdrBuf; // bundle up the arguments ArgStruct * args = new ArgStruct; args->stream = dataModeStream; args->numIters = numIterations; #if defined (ACE_HAS_THREADS) // Spawn a new thread and run the new connection in that thread of // control using the <server> function as the entry point. if (ACE_Thread_Manager::instance ()->spawn (unmarshalledOctetServer, reinterpret_cast<void *> (args), THR_DETACHED) == -1) ACE_ERROR ((LM_ERROR, ACE_TEXT ("(%P|%t) %p\n"), ACE_TEXT ("spawn"))); #else (*unmarshalledOctetServer) (reinterpret_cast<void *> (args)); #endif /* ACE_HAS_THREADS */ }
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 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)); }